mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-16 10:45:12 +00:00
Changes (#195)
* Changes added * Reading of events for applications changed. * Proto changed * Tests added * Added more tests. * Struct for Data expanded with additional fields. * refactoring * Changes from review. * Merge in to Master * Changes from review. * fix: generate proto Co-authored-by: Fabiennne <[email protected]>
This commit is contained in:
co-authored by
Fabiennne
parent
8dd6082b17
commit
1dd82ab1b7
@@ -2,6 +2,7 @@ package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
"github.com/golang/protobuf/ptypes/empty"
|
||||
)
|
||||
@@ -85,5 +86,9 @@ func (s *Server) RegenerateOIDCClientSecret(ctx context.Context, in *Application
|
||||
}
|
||||
|
||||
func (s *Server) ApplicationChanges(ctx context.Context, changesRequest *ChangeRequest) (*Changes, error) {
|
||||
return nil, errors.ThrowUnimplemented(nil, "GRPC-due45", "Not implemented")
|
||||
response, err := s.project.ApplicationChanges(ctx, changesRequest.Id, changesRequest.SecId, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return appChangesToResponse(response, changesRequest.GetSequenceOffset(), changesRequest.GetLimit()), nil
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/caos/zitadel/internal/eventstore/models"
|
||||
"github.com/caos/zitadel/internal/model"
|
||||
proj_model "github.com/caos/zitadel/internal/project/model"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
|
||||
func appFromModel(app *proj_model.Application) *Application {
|
||||
@@ -311,3 +315,31 @@ func oidcAuthMethodTypeFromModel(authType proj_model.OIDCAuthMethodType) OIDCAut
|
||||
return OIDCAuthMethodType_OIDCAUTHMETHODTYPE_BASIC
|
||||
}
|
||||
}
|
||||
|
||||
func appChangesToResponse(response *proj_model.ApplicationChanges, offset uint64, limit uint64) (_ *Changes) {
|
||||
return &Changes{
|
||||
Limit: limit,
|
||||
Offset: offset,
|
||||
Changes: appChangesToMgtAPI(response),
|
||||
}
|
||||
}
|
||||
|
||||
func appChangesToMgtAPI(changes *proj_model.ApplicationChanges) (_ []*Change) {
|
||||
result := make([]*Change, len(changes.Changes))
|
||||
|
||||
for i, change := range changes.Changes {
|
||||
b, err := json.Marshal(change.Data)
|
||||
data := &structpb.Struct{}
|
||||
err = protojson.Unmarshal(b, data)
|
||||
if err != nil {
|
||||
}
|
||||
result[i] = &Change{
|
||||
ChangeDate: change.ChangeDate,
|
||||
EventType: change.EventType,
|
||||
Sequence: change.Sequence,
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
+2832
-2821
File diff suppressed because it is too large
Load Diff
@@ -364,7 +364,7 @@ func request_ManagementService_UserChanges_0(ctx context.Context, marshaler runt
|
||||
}
|
||||
|
||||
var (
|
||||
filter_ManagementService_ApplicationChanges_0 = &utilities.DoubleArray{Encoding: map[string]int{"id": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
|
||||
filter_ManagementService_ApplicationChanges_0 = &utilities.DoubleArray{Encoding: map[string]int{"id": 0, "sec_id": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}}
|
||||
)
|
||||
|
||||
func request_ManagementService_ApplicationChanges_0(ctx context.Context, marshaler runtime.Marshaler, client ManagementServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
@@ -389,6 +389,17 @@ func request_ManagementService_ApplicationChanges_0(ctx context.Context, marshal
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
|
||||
}
|
||||
|
||||
val, ok = pathParams["sec_id"]
|
||||
if !ok {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "sec_id")
|
||||
}
|
||||
|
||||
protoReq.SecId, err = runtime.String(val)
|
||||
|
||||
if err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "sec_id", err)
|
||||
}
|
||||
|
||||
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_ManagementService_ApplicationChanges_0); err != nil {
|
||||
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
|
||||
}
|
||||
@@ -5832,7 +5843,7 @@ var (
|
||||
|
||||
pattern_ManagementService_UserChanges_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1, 2, 2}, []string{"users", "id", "changes"}, ""))
|
||||
|
||||
pattern_ManagementService_ApplicationChanges_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1, 2, 2}, []string{"applications", "id", "changes"}, ""))
|
||||
pattern_ManagementService_ApplicationChanges_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4}, []string{"projects", "id", "applications", "sec_id", "changes"}, ""))
|
||||
|
||||
pattern_ManagementService_OrgChanges_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1, 2, 2}, []string{"orgs", "id", "changes"}, ""))
|
||||
|
||||
|
||||
@@ -19,44 +19,6 @@
|
||||
"application/grpc"
|
||||
],
|
||||
"paths": {
|
||||
"/applications/{id}/changes": {
|
||||
"get": {
|
||||
"operationId": "ApplicationChanges",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/v1Changes"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"format": "uint64"
|
||||
},
|
||||
{
|
||||
"name": "sequence_offset",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"format": "uint64"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"ManagementService"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/authgrants/_search": {
|
||||
"post": {
|
||||
"summary": "Grant",
|
||||
@@ -436,6 +398,12 @@
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "sec_id",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
@@ -1159,6 +1127,50 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"/projects/{id}/applications/{sec_id}/changes": {
|
||||
"get": {
|
||||
"operationId": "ApplicationChanges",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/v1Changes"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "sec_id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"format": "uint64"
|
||||
},
|
||||
{
|
||||
"name": "sequence_offset",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"format": "uint64"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"ManagementService"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/projects/{id}/changes": {
|
||||
"get": {
|
||||
"operationId": "ProjectChanges",
|
||||
@@ -1177,6 +1189,12 @@
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "sec_id",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
@@ -2834,6 +2852,12 @@
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "sec_id",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
|
||||
@@ -2,8 +2,6 @@ package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
)
|
||||
|
||||
func (s *Server) GetOrgByID(ctx context.Context, orgID *OrgID) (*Org, error) {
|
||||
@@ -39,5 +37,9 @@ func (s *Server) ReactivateOrg(ctx context.Context, in *OrgID) (*Org, error) {
|
||||
}
|
||||
|
||||
func (s *Server) OrgChanges(ctx context.Context, changesRequest *ChangeRequest) (*Changes, error) {
|
||||
return nil, errors.ThrowUnimplemented(nil, "GRPC-DNiIq", "unimplemented")
|
||||
response, err := s.org.OrgChanges(ctx, changesRequest.Id, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return orgChangesToResponse(response, changesRequest.GetSequenceOffset(), changesRequest.GetLimit()), nil
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/caos/logging"
|
||||
org_model "github.com/caos/zitadel/internal/org/model"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
|
||||
func orgsFromModel(orgs []*org_model.Org) []*Org {
|
||||
@@ -58,3 +62,31 @@ func orgStateFromModel(state org_model.OrgState) OrgState {
|
||||
return OrgState_ORGSTATE_UNSPECIFIED
|
||||
}
|
||||
}
|
||||
|
||||
func orgChangesToResponse(response *org_model.OrgChanges, offset uint64, limit uint64) (_ *Changes) {
|
||||
return &Changes{
|
||||
Limit: limit,
|
||||
Offset: offset,
|
||||
Changes: orgChangesToMgtAPI(response),
|
||||
}
|
||||
}
|
||||
|
||||
func orgChangesToMgtAPI(changes *org_model.OrgChanges) (_ []*Change) {
|
||||
result := make([]*Change, len(changes.Changes))
|
||||
|
||||
for i, change := range changes.Changes {
|
||||
b, err := json.Marshal(change.Data)
|
||||
data := &structpb.Struct{}
|
||||
err = protojson.Unmarshal(b, data)
|
||||
if err != nil {
|
||||
}
|
||||
result[i] = &Change{
|
||||
ChangeDate: change.ChangeDate,
|
||||
EventType: change.EventType,
|
||||
Sequence: change.Sequence,
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/api"
|
||||
"github.com/caos/zitadel/internal/api/auth"
|
||||
grpc_util "github.com/caos/zitadel/internal/api/grpc"
|
||||
@@ -124,7 +125,11 @@ func (s *Server) SearchProjectRoles(ctx context.Context, in *ProjectRoleSearchRe
|
||||
}
|
||||
|
||||
func (s *Server) ProjectChanges(ctx context.Context, changesRequest *ChangeRequest) (*Changes, error) {
|
||||
return nil, errors.ThrowUnimplemented(nil, "GRPC-mci3f", "Not implemented")
|
||||
response, err := s.project.ProjectChanges(ctx, changesRequest.Id, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return projectChangesToResponse(response, changesRequest.GetSequenceOffset(), changesRequest.GetLimit()), nil
|
||||
}
|
||||
|
||||
func (s *Server) IsZitadel(ctx context.Context, projectID string) bool {
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/caos/zitadel/internal/eventstore/models"
|
||||
proj_model "github.com/caos/zitadel/internal/project/model"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
|
||||
func projectFromModel(project *proj_model.Project) *Project {
|
||||
@@ -248,3 +252,31 @@ func projectRoleSearchKeyToModel(key ProjectRoleSearchKey) proj_model.ProjectRol
|
||||
return proj_model.PROJECTROLESEARCHKEY_UNSPECIFIED
|
||||
}
|
||||
}
|
||||
|
||||
func projectChangesToResponse(response *proj_model.ProjectChanges, offset uint64, limit uint64) (_ *Changes) {
|
||||
return &Changes{
|
||||
Limit: limit,
|
||||
Offset: offset,
|
||||
Changes: projectChangesToMgtAPI(response),
|
||||
}
|
||||
}
|
||||
|
||||
func projectChangesToMgtAPI(changes *proj_model.ProjectChanges) (_ []*Change) {
|
||||
result := make([]*Change, len(changes.Changes))
|
||||
|
||||
for i, change := range changes.Changes {
|
||||
b, err := json.Marshal(change.Data)
|
||||
data := &structpb.Struct{}
|
||||
err = protojson.Unmarshal(b, data)
|
||||
if err != nil {
|
||||
}
|
||||
result[i] = &Change{
|
||||
ChangeDate: change.ChangeDate,
|
||||
EventType: change.EventType,
|
||||
Sequence: change.Sequence,
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/caos/zitadel/internal/api"
|
||||
grpc_util "github.com/caos/zitadel/internal/api/grpc"
|
||||
"github.com/caos/zitadel/internal/errors"
|
||||
@@ -36,7 +37,11 @@ func (s *Server) SearchUsers(ctx context.Context, in *UserSearchRequest) (*UserS
|
||||
}
|
||||
|
||||
func (s *Server) UserChanges(ctx context.Context, changesRequest *ChangeRequest) (*Changes, error) {
|
||||
return nil, errors.ThrowUnimplemented(nil, "GRPC-pl6Zu", "Not implemented")
|
||||
response, err := s.user.UserChanges(ctx, changesRequest.Id, 0, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return userChangesToResponse(response, changesRequest.GetSequenceOffset(), changesRequest.GetLimit()), nil
|
||||
}
|
||||
|
||||
func (s *Server) IsUserUnique(ctx context.Context, request *UniqueUserRequest) (*UniqueUserResponse, error) {
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/caos/logging"
|
||||
"github.com/caos/zitadel/internal/eventstore/models"
|
||||
usr_model "github.com/caos/zitadel/internal/user/model"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"golang.org/x/text/language"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
|
||||
func userFromModel(user *usr_model.User) *User {
|
||||
@@ -397,3 +401,31 @@ func mfaStateFromModel(state usr_model.MfaState) MFAState {
|
||||
return MFAState_MFASTATE_UNSPECIFIED
|
||||
}
|
||||
}
|
||||
|
||||
func userChangesToResponse(response *usr_model.UserChanges, offset uint64, limit uint64) (_ *Changes) {
|
||||
return &Changes{
|
||||
Limit: limit,
|
||||
Offset: offset,
|
||||
Changes: userChangesToMgtAPI(response),
|
||||
}
|
||||
}
|
||||
|
||||
func userChangesToMgtAPI(changes *usr_model.UserChanges) (_ []*Change) {
|
||||
result := make([]*Change, len(changes.Changes))
|
||||
|
||||
for i, change := range changes.Changes {
|
||||
b, err := json.Marshal(change.Data)
|
||||
data := &structpb.Struct{}
|
||||
err = protojson.Unmarshal(b, data)
|
||||
if err != nil {
|
||||
}
|
||||
result[i] = &Change{
|
||||
ChangeDate: change.ChangeDate,
|
||||
EventType: change.EventType,
|
||||
Sequence: change.Sequence,
|
||||
Data: data,
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ service ManagementService {
|
||||
|
||||
rpc ApplicationChanges(ChangeRequest) returns (Changes) {
|
||||
option (google.api.http) = {
|
||||
get: "/applications/{id}/changes"
|
||||
get: "/projects/{id}/applications/{sec_id}/changes"
|
||||
};
|
||||
|
||||
option (caos.zitadel.utils.v1.auth_option) = {
|
||||
@@ -1235,8 +1235,9 @@ service ManagementService {
|
||||
|
||||
message ChangeRequest {
|
||||
string id = 1;
|
||||
uint64 limit= 2;
|
||||
uint64 sequence_offset = 3;
|
||||
string sec_id = 2;
|
||||
uint64 limit= 3;
|
||||
uint64 sequence_offset = 4;
|
||||
}
|
||||
|
||||
message Changes {
|
||||
|
||||
Reference in New Issue
Block a user