From 0aef2df882fb09193bb1723b396fa8d9b8889400 Mon Sep 17 00:00:00 2001 From: Abin Simon Date: Wed, 12 Jan 2022 15:12:37 +0530 Subject: [PATCH] Few tweaks on resource response on success --- components/usermgmt/README.md | 4 ++-- components/usermgmt/pkg/service/group.go | 7 +++++-- components/usermgmt/pkg/service/role.go | 2 +- components/usermgmt/pkg/service/user.go | 7 +++---- components/usermgmt/readme | 11 ----------- 5 files changed, 11 insertions(+), 20 deletions(-) delete mode 100644 components/usermgmt/readme diff --git a/components/usermgmt/README.md b/components/usermgmt/README.md index 73b5c39..a9ac69e 100644 --- a/components/usermgmt/README.md +++ b/components/usermgmt/README.md @@ -8,8 +8,8 @@ All user/auth related requests go through here. ### Run kratos migrations -``` shell -export DSN='postgres://admindbuser@localhost:5432/admindb?sslmode=disable' +``` shele +export DSN='postgres://postgres@localhost:5432/admindb?sslmode=disable' kratos -c kratos.yaml migrate sql -e --yes ``` diff --git a/components/usermgmt/pkg/service/group.go b/components/usermgmt/pkg/service/group.go index 845a4cb..8a3830c 100644 --- a/components/usermgmt/pkg/service/group.go +++ b/components/usermgmt/pkg/service/group.go @@ -76,7 +76,7 @@ func (s *groupService) updateGroupRoleRelation(ctx context.Context, group *userv pgnr := models.ProjectGroupNamespaceRole{ Name: group.GetMetadata().GetName(), Description: group.GetMetadata().GetDescription(), - CreatedAt: time.Now(), + CreatedAt: time.Now(), // TODO: could drop this as it is default ModifiedAt: time.Now(), Trash: false, RoleId: roleId, @@ -169,6 +169,9 @@ func (s *groupService) updateGroupAccountRelation(ctx context.Context, group *us } grpaccs = append(grpaccs, grp) } + if len(grpaccs) == 0 { + return group, nil + } _, err := s.dao.Create(ctx, &grpaccs) if err != nil { group.Status = &v3.Status{ @@ -218,7 +221,7 @@ func (s *groupService) Create(ctx context.Context, group *userv3.Group) (*userv3 Users: group.Spec.Users, // TODO: is this the right thing to do? Projectnamespaceroles: group.Spec.Projectnamespaceroles, // TODO: is this the right thing to do? } - if group.Status != nil { + if group.Status == nil { group.Status = &v3.Status{ ConditionType: "Create", ConditionStatus: v3.ConditionStatus_StatusOK, diff --git a/components/usermgmt/pkg/service/role.go b/components/usermgmt/pkg/service/role.go index 3b0a72f..fb31cf7 100644 --- a/components/usermgmt/pkg/service/role.go +++ b/components/usermgmt/pkg/service/role.go @@ -85,7 +85,7 @@ func (s *roleService) Create(ctx context.Context, role *userv3.Role) (*userv3.Ro IsGlobal: createdRole.IsGlobal, Scope: createdRole.Scope, } - if role.Status != nil { + if role.Status == nil { role.Status = &v3.Status{ ConditionType: "Create", ConditionStatus: v3.ConditionStatus_StatusOK, diff --git a/components/usermgmt/pkg/service/user.go b/components/usermgmt/pkg/service/user.go index fb9e0bc..51c8326 100644 --- a/components/usermgmt/pkg/service/user.go +++ b/components/usermgmt/pkg/service/user.go @@ -10,9 +10,9 @@ import ( bun "github.com/uptrace/bun" "google.golang.org/protobuf/types/known/timestamppb" + "github.com/RafaySystems/rcloud-base/components/common/pkg/persistence/provider/pg" v3 "github.com/RafaySystems/rcloud-base/components/common/proto/types/commonpb/v3" "github.com/RafaySystems/rcloud-base/components/usermgmt/pkg/internal/models" - "github.com/RafaySystems/rcloud-base/components/common/pkg/persistence/provider/pg" userrpcv3 "github.com/RafaySystems/rcloud-base/components/usermgmt/proto/rpc/v3" userv3 "github.com/RafaySystems/rcloud-base/components/usermgmt/proto/types/userpb/v3" ) @@ -50,7 +50,7 @@ func NewUserService(kc *kclient.APIClient, db *bun.DB) UserService { // Convert from kratos.Identity to GVK format func identityToUser(id *kclient.Identity) *userv3.User { - traits := id.Traits.(map[string]interface{}) + traits := id.GetTraits().(map[string]interface{}) return &userv3.User{ ApiVersion: "usermgmt.k8smgmt.io/v3", Kind: "User", @@ -159,7 +159,6 @@ func (s *userService) updateUserRoleRelation(ctx context.Context, user *userv3.U func (s *userService) updateGroupAccountRelation(ctx context.Context, user *userv3.User) (*userv3.User, error) { // TODO: diff and delete the old relations userId, _ := uuid.Parse(user.GetMetadata().GetId()) - fmt.Println("userId:", userId); // TODO: add transactions var grpaccs []models.GroupAccount @@ -169,7 +168,7 @@ func (s *userService) updateGroupAccountRelation(ctx context.Context, user *user return nil, err } grp := models.GroupAccount{ - Name: user.GetMetadata().GetName(), // TODO: what is name for relations? + Name: user.GetMetadata().GetName(), // TODO: what is name for relations? Description: user.GetMetadata().GetDescription(), // TODO: now sure what this is either CreatedAt: time.Now(), ModifiedAt: time.Now(), diff --git a/components/usermgmt/readme b/components/usermgmt/readme deleted file mode 100644 index 688f79a..0000000 --- a/components/usermgmt/readme +++ /dev/null @@ -1,11 +0,0 @@ -User management for rcloud - -Dependencies: -- ory/kratos - -Components: -- Glue between frontend and kratos -- Auth validation for use in other modules - -TBD: -- Will casbin be integrated in same module or separate api call? (Probably separate api call) \ No newline at end of file