aboutsummaryrefslogtreecommitdiff
path: root/userapi
diff options
context:
space:
mode:
Diffstat (limited to 'userapi')
-rw-r--r--userapi/api/api.go8
-rw-r--r--userapi/api/api_trace.go7
-rw-r--r--userapi/internal/api.go34
-rw-r--r--userapi/inthttp/client.go3
-rw-r--r--userapi/inthttp/server.go29
5 files changed, 70 insertions, 11 deletions
diff --git a/userapi/api/api.go b/userapi/api/api.go
index 75d06dd6..04609659 100644
--- a/userapi/api/api.go
+++ b/userapi/api/api.go
@@ -33,7 +33,7 @@ type UserInternalAPI interface {
PerformDeviceUpdate(ctx context.Context, req *PerformDeviceUpdateRequest, res *PerformDeviceUpdateResponse) error
PerformAccountDeactivation(ctx context.Context, req *PerformAccountDeactivationRequest, res *PerformAccountDeactivationResponse) error
PerformOpenIDTokenCreation(ctx context.Context, req *PerformOpenIDTokenCreationRequest, res *PerformOpenIDTokenCreationResponse) error
- PerformKeyBackup(ctx context.Context, req *PerformKeyBackupRequest, res *PerformKeyBackupResponse)
+ PerformKeyBackup(ctx context.Context, req *PerformKeyBackupRequest, res *PerformKeyBackupResponse) error
QueryKeyBackup(ctx context.Context, req *QueryKeyBackupRequest, res *QueryKeyBackupResponse)
QueryProfile(ctx context.Context, req *QueryProfileRequest, res *QueryProfileResponse) error
QueryAccessToken(ctx context.Context, req *QueryAccessTokenRequest, res *QueryAccessTokenResponse) error
@@ -181,7 +181,7 @@ type QueryAccessTokenRequest struct {
// QueryAccessTokenResponse is the response for QueryAccessToken
type QueryAccessTokenResponse struct {
Device *Device
- Err error // e.g ErrorForbidden
+ Err string // e.g ErrorForbidden
}
// QueryAccountDataRequest is the request for QueryAccountData
@@ -290,6 +290,10 @@ type PerformDeviceCreationRequest struct {
IPAddr string
// Useragent for this device
UserAgent string
+ // NoDeviceListUpdate determines whether we should avoid sending a device list
+ // update for this account. Generally the only reason to do this is if the account
+ // is an appservice account.
+ NoDeviceListUpdate bool
}
// PerformDeviceCreationResponse is the response for PerformDeviceCreation
diff --git a/userapi/api/api_trace.go b/userapi/api/api_trace.go
index 84dcb309..aa069f40 100644
--- a/userapi/api/api_trace.go
+++ b/userapi/api/api_trace.go
@@ -74,11 +74,14 @@ func (t *UserInternalAPITrace) PerformOpenIDTokenCreation(ctx context.Context, r
util.GetLogger(ctx).Infof("PerformOpenIDTokenCreation req=%+v res=%+v", js(req), js(res))
return err
}
-func (t *UserInternalAPITrace) PerformKeyBackup(ctx context.Context, req *PerformKeyBackupRequest, res *PerformKeyBackupResponse) {
- t.Impl.PerformKeyBackup(ctx, req, res)
+func (t *UserInternalAPITrace) PerformKeyBackup(ctx context.Context, req *PerformKeyBackupRequest, res *PerformKeyBackupResponse) error {
+ err := t.Impl.PerformKeyBackup(ctx, req, res)
+ util.GetLogger(ctx).Infof("PerformKeyBackup req=%+v res=%+v", js(req), js(res))
+ return err
}
func (t *UserInternalAPITrace) QueryKeyBackup(ctx context.Context, req *QueryKeyBackupRequest, res *QueryKeyBackupResponse) {
t.Impl.QueryKeyBackup(ctx, req, res)
+ util.GetLogger(ctx).Infof("QueryKeyBackup req=%+v res=%+v", js(req), js(res))
}
func (t *UserInternalAPITrace) QueryProfile(ctx context.Context, req *QueryProfileRequest, res *QueryProfileResponse) error {
err := t.Impl.QueryProfile(ctx, req, res)
diff --git a/userapi/internal/api.go b/userapi/internal/api.go
index 4ff8f51d..5d91383d 100644
--- a/userapi/internal/api.go
+++ b/userapi/internal/api.go
@@ -119,6 +119,9 @@ func (a *UserInternalAPI) PerformDeviceCreation(ctx context.Context, req *api.Pe
}
res.DeviceCreated = true
res.Device = dev
+ if req.NoDeviceListUpdate {
+ return nil
+ }
// create empty device keys and upload them to trigger device list changes
return a.deviceListUpdate(dev.UserID, []string{dev.ID})
}
@@ -358,8 +361,11 @@ func (a *UserInternalAPI) QueryAccountData(ctx context.Context, req *api.QueryAc
func (a *UserInternalAPI) QueryAccessToken(ctx context.Context, req *api.QueryAccessTokenRequest, res *api.QueryAccessTokenResponse) error {
if req.AppServiceUserID != "" {
appServiceDevice, err := a.queryAppServiceToken(ctx, req.AccessToken, req.AppServiceUserID)
+ if err != nil {
+ res.Err = err.Error()
+ }
res.Device = appServiceDevice
- res.Err = err
+
return nil
}
device, err := a.DeviceDB.GetDeviceByAccessToken(ctx, req.AccessToken)
@@ -455,13 +461,16 @@ func (a *UserInternalAPI) QueryOpenIDToken(ctx context.Context, req *api.QueryOp
return nil
}
-func (a *UserInternalAPI) PerformKeyBackup(ctx context.Context, req *api.PerformKeyBackupRequest, res *api.PerformKeyBackupResponse) {
+func (a *UserInternalAPI) PerformKeyBackup(ctx context.Context, req *api.PerformKeyBackupRequest, res *api.PerformKeyBackupResponse) error {
// Delete metadata
if req.DeleteBackup {
if req.Version == "" {
res.BadInput = true
res.Error = "must specify a version to delete"
- return
+ if res.Error != "" {
+ return fmt.Errorf(res.Error)
+ }
+ return nil
}
exists, err := a.AccountDB.DeleteKeyBackup(ctx, req.UserID, req.Version)
if err != nil {
@@ -469,7 +478,10 @@ func (a *UserInternalAPI) PerformKeyBackup(ctx context.Context, req *api.Perform
}
res.Exists = exists
res.Version = req.Version
- return
+ if res.Error != "" {
+ return fmt.Errorf(res.Error)
+ }
+ return nil
}
// Create metadata
if req.Version == "" {
@@ -479,7 +491,10 @@ func (a *UserInternalAPI) PerformKeyBackup(ctx context.Context, req *api.Perform
}
res.Exists = err == nil
res.Version = version
- return
+ if res.Error != "" {
+ return fmt.Errorf(res.Error)
+ }
+ return nil
}
// Update metadata
if len(req.Keys.Rooms) == 0 {
@@ -489,10 +504,17 @@ func (a *UserInternalAPI) PerformKeyBackup(ctx context.Context, req *api.Perform
}
res.Exists = err == nil
res.Version = req.Version
- return
+ if res.Error != "" {
+ return fmt.Errorf(res.Error)
+ }
+ return nil
}
// Upload Keys for a specific version metadata
a.uploadBackupKeys(ctx, req, res)
+ if res.Error != "" {
+ return fmt.Errorf(res.Error)
+ }
+ return nil
}
func (a *UserInternalAPI) uploadBackupKeys(ctx context.Context, req *api.PerformKeyBackupRequest, res *api.PerformKeyBackupResponse) {
diff --git a/userapi/inthttp/client.go b/userapi/inthttp/client.go
index a89d1a26..1599d463 100644
--- a/userapi/inthttp/client.go
+++ b/userapi/inthttp/client.go
@@ -228,7 +228,7 @@ func (h *httpUserInternalAPI) QueryOpenIDToken(ctx context.Context, req *api.Que
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
}
-func (h *httpUserInternalAPI) PerformKeyBackup(ctx context.Context, req *api.PerformKeyBackupRequest, res *api.PerformKeyBackupResponse) {
+func (h *httpUserInternalAPI) PerformKeyBackup(ctx context.Context, req *api.PerformKeyBackupRequest, res *api.PerformKeyBackupResponse) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformKeyBackup")
defer span.Finish()
@@ -237,6 +237,7 @@ func (h *httpUserInternalAPI) PerformKeyBackup(ctx context.Context, req *api.Per
if err != nil {
res.Error = err.Error()
}
+ return nil
}
func (h *httpUserInternalAPI) QueryKeyBackup(ctx context.Context, req *api.QueryKeyBackupRequest, res *api.QueryKeyBackupResponse) {
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryKeyBackup")
diff --git a/userapi/inthttp/server.go b/userapi/inthttp/server.go
index 1c1cfdcd..ac05bcd0 100644
--- a/userapi/inthttp/server.go
+++ b/userapi/inthttp/server.go
@@ -16,6 +16,7 @@ package inthttp
import (
"encoding/json"
+ "fmt"
"net/http"
"github.com/gorilla/mux"
@@ -234,4 +235,32 @@ func AddRoutes(internalAPIMux *mux.Router, s api.UserInternalAPI) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
+ internalAPIMux.Handle(QueryKeyBackupPath,
+ httputil.MakeInternalAPI("queryKeyBackup", func(req *http.Request) util.JSONResponse {
+ request := api.QueryKeyBackupRequest{}
+ response := api.QueryKeyBackupResponse{}
+ if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
+ return util.MessageResponse(http.StatusBadRequest, err.Error())
+ }
+ s.QueryKeyBackup(req.Context(), &request, &response)
+ if response.Error != "" {
+ return util.ErrorResponse(fmt.Errorf("QueryKeyBackup: %s", response.Error))
+ }
+ return util.JSONResponse{Code: http.StatusOK, JSON: &response}
+ }),
+ )
+ internalAPIMux.Handle(PerformKeyBackupPath,
+ httputil.MakeInternalAPI("performKeyBackup", func(req *http.Request) util.JSONResponse {
+ request := api.PerformKeyBackupRequest{}
+ response := api.PerformKeyBackupResponse{}
+ if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
+ return util.MessageResponse(http.StatusBadRequest, err.Error())
+ }
+ err := s.PerformKeyBackup(req.Context(), &request, &response)
+ if err != nil {
+ return util.JSONResponse{Code: http.StatusBadRequest, JSON: &response}
+ }
+ return util.JSONResponse{Code: http.StatusOK, JSON: &response}
+ }),
+ )
}