Add methods to query the policy version

This commit is contained in:
Till Faelligen 2022-02-14 14:03:30 +01:00
parent 9583784e8a
commit 3c5c3ea7fb
5 changed files with 116 additions and 8 deletions

View file

@ -44,6 +44,8 @@ type UserInternalAPI interface {
QueryDeviceInfos(ctx context.Context, req *QueryDeviceInfosRequest, res *QueryDeviceInfosResponse) error QueryDeviceInfos(ctx context.Context, req *QueryDeviceInfosRequest, res *QueryDeviceInfosResponse) error
QuerySearchProfiles(ctx context.Context, req *QuerySearchProfilesRequest, res *QuerySearchProfilesResponse) error QuerySearchProfiles(ctx context.Context, req *QuerySearchProfilesRequest, res *QuerySearchProfilesResponse) error
QueryOpenIDToken(ctx context.Context, req *QueryOpenIDTokenRequest, res *QueryOpenIDTokenResponse) error QueryOpenIDToken(ctx context.Context, req *QueryOpenIDTokenRequest, res *QueryOpenIDTokenResponse) error
QueryPolicyVersion(ctx context.Context, req *QueryPolicyVersionRequest, res *QueryPolicyVersionResponse) error
GetOutdatedPolicy(ctx context.Context, req *QueryOutdatedPolicyUsersRequest, res *QueryOutdatedPolicyUsersResponse) error
} }
type PerformKeyBackupRequest struct { type PerformKeyBackupRequest struct {
@ -335,6 +337,26 @@ type QueryOpenIDTokenResponse struct {
ExpiresAtMS int64 ExpiresAtMS int64
} }
// QueryPolicyVersionRequest is the response for QueryPolicyVersionRequest
type QueryPolicyVersionRequest struct {
LocalPart string
}
// QueryPolicyVersionResponsestruct is the response for QueryPolicyVersionResponsestruct
type QueryPolicyVersionResponse struct {
PolicyVersion string
}
// QueryOutdatedPolicyUsersRequest is the response for QueryOutdatedPolicyUsersRequest
type QueryOutdatedPolicyUsersRequest struct {
PolicyVersion string
}
// QueryOutdatedPolicyUsersResponse is the response for QueryOutdatedPolicyUsersRequest
type QueryOutdatedPolicyUsersResponse struct {
OutdatedUsers []string
}
// Device represents a client's device (mobile, web, etc) // Device represents a client's device (mobile, web, etc)
type Device struct { type Device struct {
ID string ID string

View file

@ -119,6 +119,18 @@ func (t *UserInternalAPITrace) QueryOpenIDToken(ctx context.Context, req *QueryO
return err return err
} }
func (t *UserInternalAPITrace) QueryPolicyVersion(ctx context.Context, req *QueryPolicyVersionRequest, res *QueryPolicyVersionResponse) error {
err := t.Impl.QueryPolicyVersion(ctx, req, res)
util.GetLogger(ctx).Infof("QueryPolicyVersion req=%+v res=%+v", js(req), js(res))
return err
}
func (t *UserInternalAPITrace) GetOutdatedPolicy(ctx context.Context, req *QueryOutdatedPolicyUsersRequest, res *QueryOutdatedPolicyUsersResponse) error {
err := t.Impl.GetOutdatedPolicy(ctx, req, res)
util.GetLogger(ctx).Infof("QueryPolicyVersion req=%+v res=%+v", js(req), js(res))
return err
}
func js(thing interface{}) string { func js(thing interface{}) string {
b, err := json.Marshal(thing) b, err := json.Marshal(thing)
if err != nil { if err != nil {

View file

@ -587,3 +587,31 @@ func (a *UserInternalAPI) QueryKeyBackup(ctx context.Context, req *api.QueryKeyB
} }
res.Keys = result res.Keys = result
} }
func (a *UserInternalAPI) QueryPolicyVersion(
ctx context.Context,
req *api.QueryPolicyVersionRequest,
res *api.QueryPolicyVersionResponse,
) error {
var err error
res.PolicyVersion, err = a.AccountDB.GetPrivacyPolicy(ctx, req.LocalPart)
if err != nil {
return err
}
return nil
}
func (a *UserInternalAPI) GetOutdatedPolicy(
ctx context.Context,
req *api.QueryOutdatedPolicyUsersRequest,
res *api.QueryOutdatedPolicyUsersResponse,
) error {
var err error
res.OutdatedUsers, err = a.AccountDB.GetOutdatedPolicy(ctx, req.PolicyVersion)
if err != nil {
return err
}
return nil
}

View file

@ -38,14 +38,16 @@ const (
PerformOpenIDTokenCreationPath = "/userapi/performOpenIDTokenCreation" PerformOpenIDTokenCreationPath = "/userapi/performOpenIDTokenCreation"
PerformKeyBackupPath = "/userapi/performKeyBackup" PerformKeyBackupPath = "/userapi/performKeyBackup"
QueryKeyBackupPath = "/userapi/queryKeyBackup" QueryKeyBackupPath = "/userapi/queryKeyBackup"
QueryProfilePath = "/userapi/queryProfile" QueryProfilePath = "/userapi/queryProfile"
QueryAccessTokenPath = "/userapi/queryAccessToken" QueryAccessTokenPath = "/userapi/queryAccessToken"
QueryDevicesPath = "/userapi/queryDevices" QueryDevicesPath = "/userapi/queryDevices"
QueryAccountDataPath = "/userapi/queryAccountData" QueryAccountDataPath = "/userapi/queryAccountData"
QueryDeviceInfosPath = "/userapi/queryDeviceInfos" QueryDeviceInfosPath = "/userapi/queryDeviceInfos"
QuerySearchProfilesPath = "/userapi/querySearchProfiles" QuerySearchProfilesPath = "/userapi/querySearchProfiles"
QueryOpenIDTokenPath = "/userapi/queryOpenIDToken" QueryOpenIDTokenPath = "/userapi/queryOpenIDToken"
QueryPolicyVersion = "/userapi/queryPolicyVersion"
QueryOutdatedPolicyUsers = "/userapi/queryOutdatedPolicy"
) )
// NewUserAPIClient creates a UserInternalAPI implemented by talking to a HTTP POST API. // NewUserAPIClient creates a UserInternalAPI implemented by talking to a HTTP POST API.
@ -249,3 +251,19 @@ func (h *httpUserInternalAPI) QueryKeyBackup(ctx context.Context, req *api.Query
res.Error = err.Error() res.Error = err.Error()
} }
} }
func (h *httpUserInternalAPI) QueryPolicyVersion(ctx context.Context, req *api.QueryPolicyVersionRequest, res *api.QueryPolicyVersionResponse) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryKeyBackup")
defer span.Finish()
apiURL := h.apiURL + QueryPolicyVersion
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
}
func (h *httpUserInternalAPI) GetOutdatedPolicy(ctx context.Context, req *api.QueryOutdatedPolicyUsersRequest, res *api.QueryOutdatedPolicyUsersResponse) error {
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryKeyBackup")
defer span.Finish()
apiURL := h.apiURL + QueryOutdatedPolicyUsers
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
}

View file

@ -265,4 +265,32 @@ func AddRoutes(internalAPIMux *mux.Router, s api.UserInternalAPI) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response} return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}), }),
) )
internalAPIMux.Handle(QueryPolicyVersion,
httputil.MakeInternalAPI("queryPolicyVersion", func(req *http.Request) util.JSONResponse {
request := api.QueryPolicyVersionRequest{}
response := api.QueryPolicyVersionResponse{}
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.MessageResponse(http.StatusBadRequest, err.Error())
}
err := s.QueryPolicyVersion(req.Context(), &request, &response)
if err != nil {
return util.JSONResponse{Code: http.StatusBadRequest, JSON: &response}
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
internalAPIMux.Handle(QueryOutdatedPolicyUsers,
httputil.MakeInternalAPI("queryOutdatedPolicyUsers", func(req *http.Request) util.JSONResponse {
request := api.QueryOutdatedPolicyUsersRequest{}
response := api.QueryOutdatedPolicyUsersResponse{}
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.MessageResponse(http.StatusBadRequest, err.Error())
}
err := s.GetOutdatedPolicy(req.Context(), &request, &response)
if err != nil {
return util.JSONResponse{Code: http.StatusBadRequest, JSON: &response}
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
} }