diff --git a/channels/mocks/repository.go b/channels/mocks/repository.go index 930f8b52c1..69b7cd32bd 100644 --- a/channels/mocks/repository.go +++ b/channels/mocks/repository.go @@ -38,23 +38,23 @@ func (_m *Repository) AddConnections(ctx context.Context, conns []channels.Conne } // AddRoles provides a mock function with given fields: ctx, rps -func (_m *Repository) AddRoles(ctx context.Context, rps []roles.RoleProvision) ([]roles.Role, error) { +func (_m *Repository) AddRoles(ctx context.Context, rps []roles.RoleProvision) ([]roles.RoleProvision, error) { ret := _m.Called(ctx, rps) if len(ret) == 0 { panic("no return value specified for AddRoles") } - var r0 []roles.Role + var r0 []roles.RoleProvision var r1 error - if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) ([]roles.Role, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) ([]roles.RoleProvision, error)); ok { return rf(ctx, rps) } - if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) []roles.Role); ok { + if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) []roles.RoleProvision); ok { r0 = rf(ctx, rps) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]roles.Role) + r0 = ret.Get(0).([]roles.RoleProvision) } } diff --git a/channels/mocks/service.go b/channels/mocks/service.go index 0f625b81d7..10a8a8b4b1 100644 --- a/channels/mocks/service.go +++ b/channels/mocks/service.go @@ -23,22 +23,22 @@ type Service struct { } // AddRole provides a mock function with given fields: ctx, session, entityID, roleName, optionalActions, optionalMembers -func (_m *Service) AddRole(ctx context.Context, session authn.Session, entityID string, roleName string, optionalActions []string, optionalMembers []string) (roles.Role, error) { +func (_m *Service) AddRole(ctx context.Context, session authn.Session, entityID string, roleName string, optionalActions []string, optionalMembers []string) (roles.RoleProvision, error) { ret := _m.Called(ctx, session, entityID, roleName, optionalActions, optionalMembers) if len(ret) == 0 { panic("no return value specified for AddRole") } - var r0 roles.Role + var r0 roles.RoleProvision var r1 error - if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) (roles.Role, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) (roles.RoleProvision, error)); ok { return rf(ctx, session, entityID, roleName, optionalActions, optionalMembers) } - if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) roles.Role); ok { + if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) roles.RoleProvision); ok { r0 = rf(ctx, session, entityID, roleName, optionalActions, optionalMembers) } else { - r0 = ret.Get(0).(roles.Role) + r0 = ret.Get(0).(roles.RoleProvision) } if rf, ok := ret.Get(1).(func(context.Context, authn.Session, string, string, []string, []string) error); ok { diff --git a/clients/mocks/repository.go b/clients/mocks/repository.go index 501a9e9807..873aadb1fc 100644 --- a/clients/mocks/repository.go +++ b/clients/mocks/repository.go @@ -38,23 +38,23 @@ func (_m *Repository) AddConnections(ctx context.Context, conns []clients.Connec } // AddRoles provides a mock function with given fields: ctx, rps -func (_m *Repository) AddRoles(ctx context.Context, rps []roles.RoleProvision) ([]roles.Role, error) { +func (_m *Repository) AddRoles(ctx context.Context, rps []roles.RoleProvision) ([]roles.RoleProvision, error) { ret := _m.Called(ctx, rps) if len(ret) == 0 { panic("no return value specified for AddRoles") } - var r0 []roles.Role + var r0 []roles.RoleProvision var r1 error - if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) ([]roles.Role, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) ([]roles.RoleProvision, error)); ok { return rf(ctx, rps) } - if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) []roles.Role); ok { + if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) []roles.RoleProvision); ok { r0 = rf(ctx, rps) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]roles.Role) + r0 = ret.Get(0).([]roles.RoleProvision) } } diff --git a/clients/mocks/service.go b/clients/mocks/service.go index f93aac6425..07944793c9 100644 --- a/clients/mocks/service.go +++ b/clients/mocks/service.go @@ -21,22 +21,22 @@ type Service struct { } // AddRole provides a mock function with given fields: ctx, session, entityID, roleName, optionalActions, optionalMembers -func (_m *Service) AddRole(ctx context.Context, session authn.Session, entityID string, roleName string, optionalActions []string, optionalMembers []string) (roles.Role, error) { +func (_m *Service) AddRole(ctx context.Context, session authn.Session, entityID string, roleName string, optionalActions []string, optionalMembers []string) (roles.RoleProvision, error) { ret := _m.Called(ctx, session, entityID, roleName, optionalActions, optionalMembers) if len(ret) == 0 { panic("no return value specified for AddRole") } - var r0 roles.Role + var r0 roles.RoleProvision var r1 error - if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) (roles.Role, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) (roles.RoleProvision, error)); ok { return rf(ctx, session, entityID, roleName, optionalActions, optionalMembers) } - if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) roles.Role); ok { + if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) roles.RoleProvision); ok { r0 = rf(ctx, session, entityID, roleName, optionalActions, optionalMembers) } else { - r0 = ret.Get(0).(roles.Role) + r0 = ret.Get(0).(roles.RoleProvision) } if rf, ok := ret.Get(1).(func(context.Context, authn.Session, string, string, []string, []string) error); ok { diff --git a/domains/mocks/repository.go b/domains/mocks/repository.go index 8fadf76968..54674fe453 100644 --- a/domains/mocks/repository.go +++ b/domains/mocks/repository.go @@ -19,23 +19,23 @@ type Repository struct { } // AddRoles provides a mock function with given fields: ctx, rps -func (_m *Repository) AddRoles(ctx context.Context, rps []roles.RoleProvision) ([]roles.Role, error) { +func (_m *Repository) AddRoles(ctx context.Context, rps []roles.RoleProvision) ([]roles.RoleProvision, error) { ret := _m.Called(ctx, rps) if len(ret) == 0 { panic("no return value specified for AddRoles") } - var r0 []roles.Role + var r0 []roles.RoleProvision var r1 error - if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) ([]roles.Role, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) ([]roles.RoleProvision, error)); ok { return rf(ctx, rps) } - if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) []roles.Role); ok { + if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) []roles.RoleProvision); ok { r0 = rf(ctx, rps) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]roles.Role) + r0 = ret.Get(0).([]roles.RoleProvision) } } diff --git a/domains/mocks/service.go b/domains/mocks/service.go index 23f9f2d3e0..6c258eba23 100644 --- a/domains/mocks/service.go +++ b/domains/mocks/service.go @@ -22,22 +22,22 @@ type Service struct { } // AddRole provides a mock function with given fields: ctx, session, entityID, roleName, optionalActions, optionalMembers -func (_m *Service) AddRole(ctx context.Context, session authn.Session, entityID string, roleName string, optionalActions []string, optionalMembers []string) (roles.Role, error) { +func (_m *Service) AddRole(ctx context.Context, session authn.Session, entityID string, roleName string, optionalActions []string, optionalMembers []string) (roles.RoleProvision, error) { ret := _m.Called(ctx, session, entityID, roleName, optionalActions, optionalMembers) if len(ret) == 0 { panic("no return value specified for AddRole") } - var r0 roles.Role + var r0 roles.RoleProvision var r1 error - if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) (roles.Role, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) (roles.RoleProvision, error)); ok { return rf(ctx, session, entityID, roleName, optionalActions, optionalMembers) } - if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) roles.Role); ok { + if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) roles.RoleProvision); ok { r0 = rf(ctx, session, entityID, roleName, optionalActions, optionalMembers) } else { - r0 = ret.Get(0).(roles.Role) + r0 = ret.Get(0).(roles.RoleProvision) } if rf, ok := ret.Get(1).(func(context.Context, authn.Session, string, string, []string, []string) error); ok { diff --git a/groups/mocks/repository.go b/groups/mocks/repository.go index c8d9cd6c31..e98a449db7 100644 --- a/groups/mocks/repository.go +++ b/groups/mocks/repository.go @@ -19,23 +19,23 @@ type Repository struct { } // AddRoles provides a mock function with given fields: ctx, rps -func (_m *Repository) AddRoles(ctx context.Context, rps []roles.RoleProvision) ([]roles.Role, error) { +func (_m *Repository) AddRoles(ctx context.Context, rps []roles.RoleProvision) ([]roles.RoleProvision, error) { ret := _m.Called(ctx, rps) if len(ret) == 0 { panic("no return value specified for AddRoles") } - var r0 []roles.Role + var r0 []roles.RoleProvision var r1 error - if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) ([]roles.Role, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) ([]roles.RoleProvision, error)); ok { return rf(ctx, rps) } - if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) []roles.Role); ok { + if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) []roles.RoleProvision); ok { r0 = rf(ctx, rps) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]roles.Role) + r0 = ret.Get(0).([]roles.RoleProvision) } } diff --git a/groups/mocks/service.go b/groups/mocks/service.go index 6e02c7316b..4dda23ee9c 100644 --- a/groups/mocks/service.go +++ b/groups/mocks/service.go @@ -58,22 +58,22 @@ func (_m *Service) AddParentGroup(ctx context.Context, session authn.Session, id } // AddRole provides a mock function with given fields: ctx, session, entityID, roleName, optionalActions, optionalMembers -func (_m *Service) AddRole(ctx context.Context, session authn.Session, entityID string, roleName string, optionalActions []string, optionalMembers []string) (roles.Role, error) { +func (_m *Service) AddRole(ctx context.Context, session authn.Session, entityID string, roleName string, optionalActions []string, optionalMembers []string) (roles.RoleProvision, error) { ret := _m.Called(ctx, session, entityID, roleName, optionalActions, optionalMembers) if len(ret) == 0 { panic("no return value specified for AddRole") } - var r0 roles.Role + var r0 roles.RoleProvision var r1 error - if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) (roles.Role, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) (roles.RoleProvision, error)); ok { return rf(ctx, session, entityID, roleName, optionalActions, optionalMembers) } - if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) roles.Role); ok { + if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) roles.RoleProvision); ok { r0 = rf(ctx, session, entityID, roleName, optionalActions, optionalMembers) } else { - r0 = ret.Get(0).(roles.Role) + r0 = ret.Get(0).(roles.RoleProvision) } if rf, ok := ret.Get(1).(func(context.Context, authn.Session, string, string, []string, []string) error); ok { diff --git a/pkg/roles/mocks/rolemanager.go b/pkg/roles/mocks/rolemanager.go index ff16fe9f93..36c881ccd4 100644 --- a/pkg/roles/mocks/rolemanager.go +++ b/pkg/roles/mocks/rolemanager.go @@ -20,22 +20,22 @@ type RoleManager struct { } // AddRole provides a mock function with given fields: ctx, session, entityID, roleName, optionalActions, optionalMembers -func (_m *RoleManager) AddRole(ctx context.Context, session authn.Session, entityID string, roleName string, optionalActions []string, optionalMembers []string) (roles.Role, error) { +func (_m *RoleManager) AddRole(ctx context.Context, session authn.Session, entityID string, roleName string, optionalActions []string, optionalMembers []string) (roles.RoleProvision, error) { ret := _m.Called(ctx, session, entityID, roleName, optionalActions, optionalMembers) if len(ret) == 0 { panic("no return value specified for AddRole") } - var r0 roles.Role + var r0 roles.RoleProvision var r1 error - if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) (roles.Role, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) (roles.RoleProvision, error)); ok { return rf(ctx, session, entityID, roleName, optionalActions, optionalMembers) } - if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) roles.Role); ok { + if rf, ok := ret.Get(0).(func(context.Context, authn.Session, string, string, []string, []string) roles.RoleProvision); ok { r0 = rf(ctx, session, entityID, roleName, optionalActions, optionalMembers) } else { - r0 = ret.Get(0).(roles.Role) + r0 = ret.Get(0).(roles.RoleProvision) } if rf, ok := ret.Get(1).(func(context.Context, authn.Session, string, string, []string, []string) error); ok { diff --git a/pkg/roles/mocks/rolesRepo.go b/pkg/roles/mocks/rolesRepo.go index 9679e50d36..b8f7bd1d48 100644 --- a/pkg/roles/mocks/rolesRepo.go +++ b/pkg/roles/mocks/rolesRepo.go @@ -17,23 +17,23 @@ type Repository struct { } // AddRoles provides a mock function with given fields: ctx, rps -func (_m *Repository) AddRoles(ctx context.Context, rps []roles.RoleProvision) ([]roles.Role, error) { +func (_m *Repository) AddRoles(ctx context.Context, rps []roles.RoleProvision) ([]roles.RoleProvision, error) { ret := _m.Called(ctx, rps) if len(ret) == 0 { panic("no return value specified for AddRoles") } - var r0 []roles.Role + var r0 []roles.RoleProvision var r1 error - if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) ([]roles.Role, error)); ok { + if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) ([]roles.RoleProvision, error)); ok { return rf(ctx, rps) } - if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) []roles.Role); ok { + if rf, ok := ret.Get(0).(func(context.Context, []roles.RoleProvision) []roles.RoleProvision); ok { r0 = rf(ctx, rps) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]roles.Role) + r0 = ret.Get(0).([]roles.RoleProvision) } } diff --git a/pkg/roles/provisionmanage.go b/pkg/roles/provisionmanage.go index 9c00c66490..602a9b8a58 100644 --- a/pkg/roles/provisionmanage.go +++ b/pkg/roles/provisionmanage.go @@ -210,23 +210,24 @@ func (r ProvisionManageService) AddNewEntitiesRoles(ctx context.Context, domainI }() } - if _, err := r.repo.AddRoles(ctx, newRolesProvision); err != nil { + nprs, err := r.repo.AddRoles(ctx, newRolesProvision) + if err != nil { return []RoleProvision{}, errors.Wrap(svcerr.ErrCreateEntity, err) } - return newRolesProvision, nil + return nprs, nil } -func (r ProvisionManageService) AddRole(ctx context.Context, session authn.Session, entityID string, roleName string, optionalActions []string, optionalMembers []string) (retRole Role, retErr error) { +func (r ProvisionManageService) AddRole(ctx context.Context, session authn.Session, entityID string, roleName string, optionalActions []string, optionalMembers []string) (retRoleProvision RoleProvision, retErr error) { sid, err := r.sidProvider.ID() if err != nil { - return Role{}, errors.Wrap(svcerr.ErrCreateEntity, err) + return RoleProvision{}, errors.Wrap(svcerr.ErrCreateEntity, err) } id := r.entityType + "_" + sid if err := r.validateActions(toRolesActions(optionalActions)); err != nil { - return Role{}, errors.Wrap(svcerr.ErrMalformedEntity, err) + return RoleProvision{}, errors.Wrap(svcerr.ErrMalformedEntity, err) } newRoleProvisions := []RoleProvision{ @@ -267,7 +268,7 @@ func (r ProvisionManageService) AddRole(ctx context.Context, session authn.Sessi if len(prs) > 0 { if err := r.policy.AddPolicies(ctx, prs); err != nil { - return Role{}, errors.Wrap(svcerr.ErrCreateEntity, err) + return RoleProvision{}, errors.Wrap(svcerr.ErrCreateEntity, err) } defer func() { @@ -279,16 +280,16 @@ func (r ProvisionManageService) AddRole(ctx context.Context, session authn.Sessi }() } - newRoles, err := r.repo.AddRoles(ctx, newRoleProvisions) + nrps, err := r.repo.AddRoles(ctx, newRoleProvisions) if err != nil { - return Role{}, errors.Wrap(svcerr.ErrCreateEntity, err) + return RoleProvision{}, errors.Wrap(svcerr.ErrCreateEntity, err) } - if len(newRoles) == 0 { - return Role{}, svcerr.ErrCreateEntity + if len(nrps) == 0 { + return RoleProvision{}, svcerr.ErrCreateEntity } - return newRoles[0], nil + return nrps[0], nil } func (r ProvisionManageService) RemoveRole(ctx context.Context, session authn.Session, entityID, roleID string) error { diff --git a/pkg/roles/repo/postgres/roles.go b/pkg/roles/repo/postgres/roles.go index 77e7229fe2..64b8b5e2f0 100644 --- a/pkg/roles/repo/postgres/roles.go +++ b/pkg/roles/repo/postgres/roles.go @@ -160,10 +160,10 @@ func toRole(r dbRole) roles.Role { } } -func (repo *Repository) AddRoles(ctx context.Context, rps []roles.RoleProvision) ([]roles.Role, error) { +func (repo *Repository) AddRoles(ctx context.Context, rps []roles.RoleProvision) ([]roles.RoleProvision, error) { tx, err := repo.db.BeginTxx(ctx, nil) if err != nil { - return []roles.Role{}, errors.Wrap(repoerr.ErrCreateEntity, err) + return []roles.RoleProvision{}, errors.Wrap(repoerr.ErrCreateEntity, err) } defer func() { if err != nil { @@ -173,18 +173,14 @@ func (repo *Repository) AddRoles(ctx context.Context, rps []roles.RoleProvision) } }() - var retRoles []roles.Role - for _, rp := range rps { q := fmt.Sprintf(`INSERT INTO %s_roles (id, name, entity_id, created_by, created_at, updated_by, updated_at) VALUES (:id, :name, :entity_id, :created_by, :created_at, :updated_by, :updated_at);`, repo.tableNamePrefix) if _, err := tx.NamedExec(q, toDBRoles(rp.Role)); err != nil { - return []roles.Role{}, postgres.HandleError(repoerr.ErrCreateEntity, err) + return []roles.RoleProvision{}, postgres.HandleError(repoerr.ErrCreateEntity, err) } - retRoles = append(retRoles, rp.Role) - if len(rp.OptionalActions) > 0 { capq := fmt.Sprintf(`INSERT INTO %s_role_actions (role_id, action) VALUES (:role_id, :action) @@ -198,7 +194,7 @@ func (repo *Repository) AddRoles(ctx context.Context, rps []roles.RoleProvision) }) } if _, err := tx.NamedExec(capq, rCaps); err != nil { - return []roles.Role{}, postgres.HandleError(repoerr.ErrCreateEntity, err) + return []roles.RoleProvision{}, postgres.HandleError(repoerr.ErrCreateEntity, err) } } @@ -215,16 +211,16 @@ func (repo *Repository) AddRoles(ctx context.Context, rps []roles.RoleProvision) }) } if _, err := tx.NamedExec(mq, rMems); err != nil { - return []roles.Role{}, postgres.HandleError(repoerr.ErrCreateEntity, err) + return []roles.RoleProvision{}, postgres.HandleError(repoerr.ErrCreateEntity, err) } } } if err := tx.Commit(); err != nil { - return []roles.Role{}, postgres.HandleError(repoerr.ErrCreateEntity, err) + return []roles.RoleProvision{}, postgres.HandleError(repoerr.ErrCreateEntity, err) } - return retRoles, nil + return rps, nil } func (repo *Repository) RemoveRoles(ctx context.Context, roleIDs []string) error { diff --git a/pkg/roles/rolemanager/api/endpoints.go b/pkg/roles/rolemanager/api/endpoints.go index 566d728f33..982b83affc 100644 --- a/pkg/roles/rolemanager/api/endpoints.go +++ b/pkg/roles/rolemanager/api/endpoints.go @@ -27,11 +27,11 @@ func CreateRoleEndpoint(svc roles.RoleManager) endpoint.Endpoint { return nil, svcerr.ErrAuthentication } - ro, err := svc.AddRole(ctx, session, req.entityID, req.RoleName, req.OptionalActions, req.OptionalMembers) + rp, err := svc.AddRole(ctx, session, req.entityID, req.RoleName, req.OptionalActions, req.OptionalMembers) if err != nil { return nil, err } - return createRoleRes{Role: ro}, nil + return createRoleRes{RoleProvision: rp}, nil } } diff --git a/pkg/roles/rolemanager/api/responses.go b/pkg/roles/rolemanager/api/responses.go index eb5e00746d..1c14b4bbda 100644 --- a/pkg/roles/rolemanager/api/responses.go +++ b/pkg/roles/rolemanager/api/responses.go @@ -28,7 +28,7 @@ var ( ) type createRoleRes struct { - roles.Role + roles.RoleProvision } func (res createRoleRes) Code() int { diff --git a/pkg/roles/rolemanager/events/events.go b/pkg/roles/rolemanager/events/events.go index 93da93573e..44de0de898 100644 --- a/pkg/roles/rolemanager/events/events.go +++ b/pkg/roles/rolemanager/events/events.go @@ -50,19 +50,21 @@ var ( type addRoleEvent struct { operationPrefix string - roles.Role + roles.RoleProvision } func (are addRoleEvent) Encode() (map[string]interface{}, error) { val := map[string]interface{}{ - "operation": are.operationPrefix + addRole, - "id": are.ID, - "name": are.Name, - "entity_id": are.EntityID, - "created_by": are.CreatedBy, - "created_at": are.CreatedAt, - "updated_by": are.UpdatedBy, - "updated_at": are.UpdatedAt, + "operation": are.operationPrefix + addRole, + "id": are.ID, + "name": are.Name, + "entity_id": are.EntityID, + "created_by": are.CreatedBy, + "created_at": are.CreatedAt, + "updated_by": are.UpdatedBy, + "updated_at": are.UpdatedAt, + "optional_actions": are.OptionalActions, + "optional_members": are.OptionalMembers, } return val, nil } diff --git a/pkg/roles/rolemanager/events/streams.go b/pkg/roles/rolemanager/events/streams.go index a72a193ead..613799b76c 100644 --- a/pkg/roles/rolemanager/events/streams.go +++ b/pkg/roles/rolemanager/events/streams.go @@ -30,20 +30,20 @@ func NewRoleManagerEventStore(svcName, operationPrefix string, svc roles.RoleMan } } -func (rmes *RoleManagerEventStore) AddRole(ctx context.Context, session authn.Session, entityID, roleName string, optionalActions []string, optionalMembers []string) (roles.Role, error) { - ro, err := rmes.svc.AddRole(ctx, session, entityID, roleName, optionalActions, optionalMembers) +func (rmes *RoleManagerEventStore) AddRole(ctx context.Context, session authn.Session, entityID, roleName string, optionalActions []string, optionalMembers []string) (roles.RoleProvision, error) { + nrp, err := rmes.svc.AddRole(ctx, session, entityID, roleName, optionalActions, optionalMembers) if err != nil { - return ro, err + return nrp, err } e := addRoleEvent{ operationPrefix: rmes.operationPrefix, - Role: ro, + RoleProvision: nrp, } if err := rmes.Publish(ctx, e); err != nil { - return ro, err + return nrp, err } - return ro, nil + return nrp, nil } func (rmes *RoleManagerEventStore) RemoveRole(ctx context.Context, session authn.Session, entityID, roleID string) error { diff --git a/pkg/roles/rolemanager/middleware/authoirzation.go b/pkg/roles/rolemanager/middleware/authoirzation.go index c54235fedc..4f4f6fd7c3 100644 --- a/pkg/roles/rolemanager/middleware/authoirzation.go +++ b/pkg/roles/rolemanager/middleware/authoirzation.go @@ -52,7 +52,7 @@ func (ram RoleManagerAuthorizationMiddleware) validate() error { return nil } -func (ram RoleManagerAuthorizationMiddleware) AddRole(ctx context.Context, session authn.Session, entityID, roleName string, optionalActions []string, optionalMembers []string) (roles.Role, error) { +func (ram RoleManagerAuthorizationMiddleware) AddRole(ctx context.Context, session authn.Session, entityID, roleName string, optionalActions []string, optionalMembers []string) (roles.RoleProvision, error) { if err := ram.authorize(ctx, roles.OpAddRole, smqauthz.PolicyReq{ Domain: session.DomainID, Subject: session.DomainUserID, @@ -61,7 +61,7 @@ func (ram RoleManagerAuthorizationMiddleware) AddRole(ctx context.Context, sessi Object: entityID, ObjectType: ram.entityType, }); err != nil { - return roles.Role{}, err + return roles.RoleProvision{}, err } return ram.svc.AddRole(ctx, session, entityID, roleName, optionalActions, optionalMembers) } diff --git a/pkg/roles/rolemanager/middleware/logging.go b/pkg/roles/rolemanager/middleware/logging.go index 951e430dad..4e4af3aa58 100644 --- a/pkg/roles/rolemanager/middleware/logging.go +++ b/pkg/roles/rolemanager/middleware/logging.go @@ -31,7 +31,7 @@ func NewRoleManagerLoggingMiddleware(svcName string, svc roles.RoleManager, logg } } -func (lm *RoleManagerLoggingMiddleware) AddRole(ctx context.Context, session authn.Session, entityID, roleName string, optionalActions []string, optionalMembers []string) (ro roles.Role, err error) { +func (lm *RoleManagerLoggingMiddleware) AddRole(ctx context.Context, session authn.Session, entityID, roleName string, optionalActions []string, optionalMembers []string) (ro roles.RoleProvision, err error) { prefix := fmt.Sprintf("Add %s roles", lm.svcName) defer func(begin time.Time) { args := []any{ diff --git a/pkg/roles/rolemanager/middleware/meterics.go b/pkg/roles/rolemanager/middleware/meterics.go index fd8e1f31f1..6a1fa43ace 100644 --- a/pkg/roles/rolemanager/middleware/meterics.go +++ b/pkg/roles/rolemanager/middleware/meterics.go @@ -31,7 +31,7 @@ func NewRoleManagerMetricsMiddleware(svcName string, svc roles.RoleManager, coun } } -func (rmm *RoleManagerMetricsMiddleware) AddRole(ctx context.Context, session authn.Session, entityID, roleName string, optionalActions []string, optionalMembers []string) (roles.Role, error) { +func (rmm *RoleManagerMetricsMiddleware) AddRole(ctx context.Context, session authn.Session, entityID, roleName string, optionalActions []string, optionalMembers []string) (roles.RoleProvision, error) { return rmm.svc.AddRole(ctx, session, entityID, roleName, optionalActions, optionalMembers) } diff --git a/pkg/roles/rolemanager/tracing/tracing.go b/pkg/roles/rolemanager/tracing/tracing.go index 15b3ce5b10..009ff46486 100644 --- a/pkg/roles/rolemanager/tracing/tracing.go +++ b/pkg/roles/rolemanager/tracing/tracing.go @@ -23,7 +23,7 @@ func NewRoleManagerTracing(svcName string, svc roles.RoleManager, tracer trace.T return RoleManagerTracing{svcName, svc, tracer} } -func (rtm *RoleManagerTracing) AddRole(ctx context.Context, session authn.Session, entityID, roleName string, optionalActions []string, optionalMembers []string) (roles.Role, error) { +func (rtm *RoleManagerTracing) AddRole(ctx context.Context, session authn.Session, entityID, roleName string, optionalActions []string, optionalMembers []string) (roles.RoleProvision, error) { return rtm.roles.AddRole(ctx, session, entityID, roleName, optionalActions, optionalMembers) } diff --git a/pkg/roles/roles.go b/pkg/roles/roles.go index 347b871e0c..a247ec6a68 100644 --- a/pkg/roles/roles.go +++ b/pkg/roles/roles.go @@ -90,7 +90,7 @@ type Provisioner interface { //go:generate mockery --name RoleManager --output=./mocks --filename rolemanager.go --quiet --note "Copyright (c) Abstract Machines" type RoleManager interface { // Add New role to entity - AddRole(ctx context.Context, session authn.Session, entityID, roleName string, optionalActions []string, optionalMembers []string) (Role, error) + AddRole(ctx context.Context, session authn.Session, entityID, roleName string, optionalActions []string, optionalMembers []string) (RoleProvision, error) // Remove removes the roles of entity. RemoveRole(ctx context.Context, session authn.Session, entityID, roleID string) error @@ -129,7 +129,7 @@ type RoleManager interface { //go:generate mockery --name Repository --output=./mocks --filename rolesRepo.go --quiet --note "Copyright (c) Abstract Machines" type Repository interface { - AddRoles(ctx context.Context, rps []RoleProvision) ([]Role, error) + AddRoles(ctx context.Context, rps []RoleProvision) ([]RoleProvision, error) RemoveRoles(ctx context.Context, roleIDs []string) error UpdateRole(ctx context.Context, ro Role) (Role, error) RetrieveRole(ctx context.Context, roleID string) (Role, error)