mirror of
https://github.com/paralus/paralus.git
synced 2026-05-08 17:36:56 +00:00
Convert from dao interface to funcs
This was done inorder to support transactions which will be done in the next PR. This is the first step towards that.
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/RafaySystems/rcloud-base/internal/dao"
|
||||
"github.com/RafaySystems/rcloud-base/internal/models"
|
||||
"github.com/RafaySystems/rcloud-base/internal/persistence/provider/pg"
|
||||
"github.com/RafaySystems/rcloud-base/proto/types/sentry"
|
||||
"github.com/google/uuid"
|
||||
"github.com/uptrace/bun"
|
||||
@@ -15,7 +14,6 @@ import (
|
||||
|
||||
// AccountPermissionService is the interface for account permission operations
|
||||
type AccountPermissionService interface {
|
||||
Close() error
|
||||
GetAccountPermissions(ctx context.Context, accountID string, orgID, partnerID string) ([]sentry.AccountPermission, error)
|
||||
IsPartnerSuperAdmin(ctx context.Context, accountID, partnerID string) (isPartnerAdmin, isSuperAdmin bool, err error)
|
||||
GetAccountProjectsByPermission(ctx context.Context, accountID, orgID, partnerID string, permission string) ([]sentry.AccountPermission, error)
|
||||
@@ -30,25 +28,16 @@ type AccountPermissionService interface {
|
||||
|
||||
// accountPermissionService implements AccountPermissionService
|
||||
type accountPermissionService struct {
|
||||
dao pg.EntityDAO
|
||||
pdao dao.PermissionDao
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
// NewKubeconfigRevocation return new kubeconfig revocation service
|
||||
func NewAccountPermissionService(db *bun.DB) AccountPermissionService {
|
||||
edao := pg.NewEntityDAO(db)
|
||||
return &accountPermissionService{
|
||||
dao: edao,
|
||||
pdao: dao.NewPermissionDao(edao),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *accountPermissionService) Close() error {
|
||||
return s.dao.Close()
|
||||
return &accountPermissionService{db}
|
||||
}
|
||||
|
||||
func (a *accountPermissionService) GetAccountPermissions(ctx context.Context, accountID string, orgID, partnerID string) ([]sentry.AccountPermission, error) {
|
||||
aps, err := a.pdao.GetAccountPermissions(ctx, uuid.MustParse(accountID), uuid.MustParse(orgID), uuid.MustParse(partnerID))
|
||||
aps, err := dao.GetAccountPermissions(ctx, a.db, uuid.MustParse(accountID), uuid.MustParse(orgID), uuid.MustParse(partnerID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -61,11 +50,11 @@ func (a *accountPermissionService) GetAccountPermissions(ctx context.Context, ac
|
||||
}
|
||||
|
||||
func (a *accountPermissionService) IsPartnerSuperAdmin(ctx context.Context, accountID, partnerID string) (isPartnerAdmin, isSuperAdmin bool, err error) {
|
||||
return a.pdao.IsPartnerSuperAdmin(ctx, uuid.MustParse(accountID), uuid.MustParse(partnerID))
|
||||
return dao.IsPartnerSuperAdmin(ctx, a.db, uuid.MustParse(accountID), uuid.MustParse(partnerID))
|
||||
}
|
||||
|
||||
func (a *accountPermissionService) GetAccountProjectsByPermission(ctx context.Context, accountID, orgID, partnerID string, permission string) ([]sentry.AccountPermission, error) {
|
||||
aps, err := a.pdao.GetAccountProjectsByPermission(ctx, uuid.MustParse(accountID), uuid.MustParse(orgID), uuid.MustParse(partnerID), permission)
|
||||
aps, err := dao.GetAccountProjectsByPermission(ctx, a.db, uuid.MustParse(accountID), uuid.MustParse(orgID), uuid.MustParse(partnerID), permission)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -85,7 +74,7 @@ func (a *accountPermissionService) GetAccountPermissionsByProjectIDPermissions(c
|
||||
projids = append(projids, id)
|
||||
}
|
||||
}
|
||||
aps, err := a.pdao.GetAccountPermissionsByProjectIDPermissions(ctx, uuid.MustParse(accountID), uuid.MustParse(orgID), uuid.MustParse(partnerID), projids, permissions)
|
||||
aps, err := dao.GetAccountPermissionsByProjectIDPermissions(ctx, a.db, uuid.MustParse(accountID), uuid.MustParse(orgID), uuid.MustParse(partnerID), projids, permissions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -98,11 +87,11 @@ func (a *accountPermissionService) GetAccountPermissionsByProjectIDPermissions(c
|
||||
}
|
||||
|
||||
func (a *accountPermissionService) GetAccount(ctx context.Context, accountID string) (*models.Account, error) {
|
||||
return a.pdao.GetAccountBasics(ctx, uuid.MustParse(accountID))
|
||||
return dao.GetAccountBasics(ctx, a.db, uuid.MustParse(accountID))
|
||||
}
|
||||
|
||||
func (a *accountPermissionService) GetAccountGroups(ctx context.Context, accountID string) ([]string, error) {
|
||||
ag, err := a.pdao.GetAccountGroups(ctx, uuid.MustParse(accountID))
|
||||
ag, err := dao.GetAccountGroups(ctx, a.db, uuid.MustParse(accountID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -131,7 +120,7 @@ func (a *accountPermissionService) GetSSOAccount(ctx context.Context, accountID,
|
||||
|
||||
//TODO: this needs to be revisited as sso users for oidc are stored in identities by kratos
|
||||
func (a *accountPermissionService) GetSSOUsersGroupProjectRole(ctx context.Context, orgID string) ([]sentry.SSOAccountGroupProjectRoleData, error) {
|
||||
ssos, err := a.pdao.GetSSOUsersGroupProjectRole(ctx, uuid.MustParse(orgID))
|
||||
ssos, err := dao.GetSSOUsersGroupProjectRole(ctx, a.db, uuid.MustParse(orgID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -144,7 +133,7 @@ func (a *accountPermissionService) GetSSOUsersGroupProjectRole(ctx context.Conte
|
||||
}
|
||||
|
||||
func (a *accountPermissionService) GetAcccountsWithApprovalPermission(ctx context.Context, orgID, partnerID string) ([]string, error) {
|
||||
usernames, err := a.pdao.GetAcccountsWithApprovalPermission(ctx, uuid.MustParse(orgID), uuid.MustParse(partnerID))
|
||||
usernames, err := dao.GetAcccountsWithApprovalPermission(ctx, a.db, uuid.MustParse(orgID), uuid.MustParse(partnerID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -152,7 +141,7 @@ func (a *accountPermissionService) GetAcccountsWithApprovalPermission(ctx contex
|
||||
}
|
||||
|
||||
func (a *accountPermissionService) GetSSOAcccountsWithApprovalPermission(ctx context.Context, orgID, partnerID string) ([]string, error) {
|
||||
usernames, err := a.pdao.GetSSOAcccountsWithApprovalPermission(ctx, uuid.MustParse(orgID), uuid.MustParse(partnerID))
|
||||
usernames, err := dao.GetSSOAcccountsWithApprovalPermission(ctx, a.db, uuid.MustParse(orgID), uuid.MustParse(partnerID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -160,17 +149,17 @@ func (a *accountPermissionService) GetSSOAcccountsWithApprovalPermission(ctx con
|
||||
}
|
||||
|
||||
func (a *accountPermissionService) IsOrgAdmin(ctx context.Context, accountID, partnerID string) (isOrgAdmin bool, err error) {
|
||||
return a.pdao.IsOrgAdmin(ctx, uuid.MustParse(accountID), uuid.MustParse(partnerID))
|
||||
return dao.IsOrgAdmin(ctx, a.db, uuid.MustParse(accountID), uuid.MustParse(partnerID))
|
||||
}
|
||||
|
||||
func (a *accountPermissionService) IsAccountActive(ctx context.Context, accountID, orgID string) (bool, error) {
|
||||
active := false
|
||||
|
||||
group, err := a.pdao.GetDefaultUserGroup(ctx, uuid.MustParse(orgID))
|
||||
group, err := dao.GetDefaultUserGroup(ctx, a.db, uuid.MustParse(orgID))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
ga, err := a.pdao.GetDefaultUserGroupAccount(ctx, uuid.MustParse(accountID), group.ID)
|
||||
ga, err := dao.GetDefaultUserGroupAccount(ctx, a.db, uuid.MustParse(accountID), group.ID)
|
||||
if err != nil {
|
||||
return active, err
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ func TestGetAccountPermissions(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewAccountPermissionService(db)
|
||||
defer ps.Close()
|
||||
|
||||
aid := uuid.New().String()
|
||||
oid := uuid.New().String()
|
||||
@@ -33,7 +32,6 @@ func TestIsPartnerSuperAdmin(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewAccountPermissionService(db)
|
||||
defer ps.Close()
|
||||
|
||||
aid := uuid.New().String()
|
||||
pid := uuid.New().String()
|
||||
@@ -52,7 +50,6 @@ func TestGetAccountProjectsByPermission(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewAccountPermissionService(db)
|
||||
defer ps.Close()
|
||||
|
||||
aid := uuid.New().String()
|
||||
oid := uuid.New().String()
|
||||
@@ -72,7 +69,6 @@ func TestGetAccountPermissionsByProjectIDPermissions(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewAccountPermissionService(db)
|
||||
defer ps.Close()
|
||||
|
||||
projects := []string{"myproject"}
|
||||
permissions := []string{"read"}
|
||||
@@ -94,7 +90,6 @@ func TestIsOrgAdmin(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewAccountPermissionService(db)
|
||||
defer ps.Close()
|
||||
|
||||
aid := uuid.New().String()
|
||||
pid := uuid.New().String()
|
||||
@@ -113,7 +108,6 @@ func TestIsAccountActive(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewAccountPermissionService(db)
|
||||
defer ps.Close()
|
||||
|
||||
aid := uuid.New().String()
|
||||
oid := uuid.New().String()
|
||||
@@ -135,7 +129,6 @@ func TestGetAccount(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewAccountPermissionService(db)
|
||||
defer ps.Close()
|
||||
|
||||
aid := uuid.New().String()
|
||||
|
||||
@@ -153,7 +146,6 @@ func TestGetAccountGroups(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewAccountPermissionService(db)
|
||||
defer ps.Close()
|
||||
|
||||
aid := uuid.New().String()
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
|
||||
// ApiKeyService is the interface for api key operations
|
||||
type ApiKeyService interface {
|
||||
Close() error
|
||||
// create api key
|
||||
Create(ctx context.Context, req *rpcv3.ApiKeyRequest) (*models.ApiKey, error)
|
||||
// get by user
|
||||
@@ -31,14 +30,12 @@ type ApiKeyService interface {
|
||||
|
||||
// apiKeyService implements ApiKeyService
|
||||
type apiKeyService struct {
|
||||
dao pg.EntityDAO
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
// NewApiKeyService return new api key service
|
||||
func NewApiKeyService(db *bun.DB) ApiKeyService {
|
||||
return &apiKeyService{
|
||||
dao: pg.NewEntityDAO(db),
|
||||
}
|
||||
return &apiKeyService{db}
|
||||
}
|
||||
|
||||
func (s *apiKeyService) Create(ctx context.Context, req *rpcv3.ApiKeyRequest) (*models.ApiKey, error) {
|
||||
@@ -52,7 +49,7 @@ func (s *apiKeyService) Create(ctx context.Context, req *rpcv3.ApiKeyRequest) (*
|
||||
Secret: crypto.GenerateSha256Secret(),
|
||||
}
|
||||
|
||||
_, err := s.dao.Create(ctx, apikey)
|
||||
_, err := pg.Create(ctx, s.db, apikey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -60,7 +57,7 @@ func (s *apiKeyService) Create(ctx context.Context, req *rpcv3.ApiKeyRequest) (*
|
||||
}
|
||||
|
||||
func (s *apiKeyService) Delete(ctx context.Context, req *rpcv3.ApiKeyRequest) (*rpcv3.DeleteUserResponse, error) {
|
||||
_, err := s.dao.GetInstance().NewUpdate().Model(&models.ApiKey{}).
|
||||
_, err := s.db.NewUpdate().Model(&models.ApiKey{}).
|
||||
Set("trash = ?", true).
|
||||
Where("name = ?", req.Username).
|
||||
Where("key = ?", req.Id).Exec(ctx)
|
||||
@@ -69,7 +66,7 @@ func (s *apiKeyService) Delete(ctx context.Context, req *rpcv3.ApiKeyRequest) (*
|
||||
|
||||
func (s *apiKeyService) List(ctx context.Context, req *rpcv3.ApiKeyRequest) (*rpcv3.ApiKeyResponseList, error) {
|
||||
var apikeys []models.ApiKey
|
||||
resp, err := s.dao.GetByName(ctx, req.Username, &apikeys)
|
||||
resp, err := pg.GetByName(ctx, s.db, req.Username, &apikeys)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -93,7 +90,7 @@ func (s *apiKeyService) List(ctx context.Context, req *rpcv3.ApiKeyRequest) (*rp
|
||||
|
||||
func (s *apiKeyService) Get(ctx context.Context, req *rpcv3.ApiKeyRequest) (*models.ApiKey, error) {
|
||||
var apikey models.ApiKey
|
||||
_, err := s.dao.GetByName(ctx, req.Username, &apikey)
|
||||
_, err := pg.GetByName(ctx, s.db, req.Username, &apikey)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -102,13 +99,9 @@ func (s *apiKeyService) Get(ctx context.Context, req *rpcv3.ApiKeyRequest) (*mod
|
||||
|
||||
func (s *apiKeyService) GetByKey(ctx context.Context, req *rpcv3.ApiKeyRequest) (*models.ApiKey, error) {
|
||||
var apikey models.ApiKey
|
||||
_, err := s.dao.GetX(ctx, "key", req.Id, &apikey)
|
||||
_, err := pg.GetX(ctx, s.db, "key", req.Id, &apikey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &apikey, err
|
||||
}
|
||||
|
||||
func (s *apiKeyService) Close() error {
|
||||
return s.dao.Close()
|
||||
}
|
||||
|
||||
@@ -24,8 +24,6 @@ var KEKFunc cryptoutil.PasswordFunc
|
||||
|
||||
// BootstrapService is the interface for bootstrap operations
|
||||
type BootstrapService interface {
|
||||
Close() error
|
||||
|
||||
// bootstrap infra methods
|
||||
PatchBootstrapInfra(ctx context.Context, infra *sentry.BootstrapInfra) error
|
||||
GetBootstrapInfra(ctx context.Context, name string) (*sentry.BootstrapInfra, error)
|
||||
@@ -44,33 +42,28 @@ type BootstrapService interface {
|
||||
GetBootstrapAgentForClusterID(ctx context.Context, clusterID string, orgID string) (*sentry.BootstrapAgent, error)
|
||||
SelectBootstrapAgents(ctx context.Context, templateRef string, opts ...query.Option) (*sentry.BootstrapAgentList, error)
|
||||
RegisterBootstrapAgent(ctx context.Context, token string) error
|
||||
DeleteBoostrapAgent(ctx context.Context, templateRef string, opts ...query.Option) error
|
||||
DeleteBootstrapAgent(ctx context.Context, templateRef string, opts ...query.Option) error
|
||||
PatchBootstrapAgent(ctx context.Context, ba *sentry.BootstrapAgent, templateRef string, opts ...query.Option) error
|
||||
}
|
||||
|
||||
// bootstrapService implements BootstrapService
|
||||
type bootstrapService struct {
|
||||
dao pg.EntityDAO
|
||||
bdao dao.BootstrapDao
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
// NewBootstrapService return new bootstrap service
|
||||
func NewBootstrapService(db *bun.DB) BootstrapService {
|
||||
edao := pg.NewEntityDAO(db)
|
||||
return &bootstrapService{
|
||||
dao: edao,
|
||||
bdao: dao.NewBootstrapDao(edao),
|
||||
}
|
||||
return &bootstrapService{db}
|
||||
}
|
||||
|
||||
func (s *bootstrapService) PatchBootstrapInfra(ctx context.Context, infra *sentry.BootstrapInfra) error {
|
||||
return s.bdao.CreateOrUpdateBootstrapInfra(ctx, convertToInfraModel(infra))
|
||||
return dao.CreateOrUpdateBootstrapInfra(ctx, s.db, convertToInfraModel(infra))
|
||||
}
|
||||
|
||||
func (s *bootstrapService) GetBootstrapInfra(ctx context.Context, name string) (*sentry.BootstrapInfra, error) {
|
||||
|
||||
var bi models.BootstrapInfra
|
||||
_, err := s.dao.GetByName(ctx, name, &bi)
|
||||
_, err := pg.GetByName(ctx, s.db, name, &bi)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -96,12 +89,12 @@ func (s *bootstrapService) PatchBootstrapAgentTemplate(ctx context.Context, temp
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
return s.bdao.CreateOrUpdateBootstrapAgentTemplate(ctx, &templ)
|
||||
return dao.CreateOrUpdateBootstrapAgentTemplate(ctx, s.db, &templ)
|
||||
}
|
||||
|
||||
func (s *bootstrapService) GetBootstrapAgentTemplate(ctx context.Context, agentType string) (*sentry.BootstrapAgentTemplate, error) {
|
||||
var template models.BootstrapAgentTemplate
|
||||
_, err := s.dao.GetByName(ctx, agentType, &template)
|
||||
_, err := pg.GetByName(ctx, s.db, agentType, &template)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -110,7 +103,7 @@ func (s *bootstrapService) GetBootstrapAgentTemplate(ctx context.Context, agentT
|
||||
}
|
||||
|
||||
func (s *bootstrapService) GetBootstrapAgentTemplateForToken(ctx context.Context, token string) (*sentry.BootstrapAgentTemplate, error) {
|
||||
bat, err := s.bdao.GetBootstrapAgentTemplateForToken(ctx, token)
|
||||
bat, err := dao.GetBootstrapAgentTemplateForToken(ctx, s.db, token)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -123,7 +116,7 @@ func (s *bootstrapService) SelectBootstrapAgentTemplates(ctx context.Context, op
|
||||
opt(queryOptions)
|
||||
}
|
||||
|
||||
batl, count, err := s.bdao.SelectBootstrapAgentTemplates(ctx, queryOptions)
|
||||
batl, count, err := dao.SelectBootstrapAgentTemplates(ctx, s.db, queryOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -141,7 +134,7 @@ func (s *bootstrapService) SelectBootstrapAgentTemplates(ctx context.Context, op
|
||||
func (s *bootstrapService) CreateBootstrapAgent(ctx context.Context, agent *sentry.BootstrapAgent) error {
|
||||
ba := convertToAgentModel(agent)
|
||||
ba.CreatedAt = time.Now()
|
||||
return s.bdao.CreateBootstrapAgent(ctx, ba)
|
||||
return dao.CreateBootstrapAgent(ctx, s.db, ba)
|
||||
}
|
||||
|
||||
func convertToAgentModel(agent *sentry.BootstrapAgent) *models.BootstrapAgent {
|
||||
@@ -252,7 +245,7 @@ func prepareTemplateResponse(template *models.BootstrapAgentTemplate) *sentry.Bo
|
||||
json.Unmarshal(template.Hosts, &hosts)
|
||||
}
|
||||
templResp := sentry.BootstrapAgentTemplate{
|
||||
Kind: "BootstapAgentTemplate",
|
||||
Kind: "BootstrapAgentTemplate",
|
||||
Metadata: &commonv3.Metadata{
|
||||
Name: template.Name,
|
||||
DisplayName: template.DisplayName,
|
||||
@@ -281,7 +274,7 @@ func (s *bootstrapService) GetBootstrapAgents(ctx context.Context, templateRef s
|
||||
opt(queryOptions)
|
||||
}
|
||||
|
||||
agl, count, err := s.bdao.GetBootstrapAgents(ctx, queryOptions, templateRef)
|
||||
agl, count, err := dao.GetBootstrapAgents(ctx, s.db, queryOptions, templateRef)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -301,7 +294,7 @@ func (s *bootstrapService) GetBootstrapAgent(ctx context.Context, templateRef st
|
||||
for _, opt := range opts {
|
||||
opt(queryOptions)
|
||||
}
|
||||
ba, err := s.bdao.GetBootstrapAgent(ctx, templateRef, queryOptions)
|
||||
ba, err := dao.GetBootstrapAgent(ctx, s.db, templateRef, queryOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -314,7 +307,7 @@ func (s *bootstrapService) SelectBootstrapAgents(ctx context.Context, templateRe
|
||||
opt(queryOptions)
|
||||
}
|
||||
|
||||
agl, count, err := s.bdao.SelectBootstrapAgents(ctx, templateRef, queryOptions)
|
||||
agl, count, err := dao.SelectBootstrapAgents(ctx, s.db, templateRef, queryOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -331,16 +324,19 @@ func (s *bootstrapService) SelectBootstrapAgents(ctx context.Context, templateRe
|
||||
}
|
||||
|
||||
func (s *bootstrapService) RegisterBootstrapAgent(ctx context.Context, token string) error {
|
||||
return s.bdao.RegisterBootstrapAgent(ctx, token)
|
||||
err := s.db.RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error {
|
||||
return dao.RegisterBootstrapAgent(ctx, tx, token)
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *bootstrapService) DeleteBoostrapAgent(ctx context.Context, templateRef string, opts ...query.Option) error {
|
||||
func (s *bootstrapService) DeleteBootstrapAgent(ctx context.Context, templateRef string, opts ...query.Option) error {
|
||||
queryOptions := &commonv3.QueryOptions{}
|
||||
for _, opt := range opts {
|
||||
opt(queryOptions)
|
||||
}
|
||||
|
||||
err := s.bdao.DeleteBootstrapAgent(ctx, templateRef, queryOptions)
|
||||
err := dao.DeleteBootstrapAgent(ctx, s.db, templateRef, queryOptions)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -351,8 +347,8 @@ func (s *bootstrapService) PatchBootstrapAgent(ctx context.Context, ba *sentry.B
|
||||
opt(queryOptions)
|
||||
}
|
||||
|
||||
err := s.dao.GetInstance().RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error {
|
||||
bdb, err := s.bdao.GetBootstrapAgent(ctx, templateRef, queryOptions)
|
||||
err := s.db.RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error {
|
||||
bdb, err := dao.GetBootstrapAgent(ctx, s.db, templateRef, queryOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -376,13 +372,13 @@ func (s *bootstrapService) PatchBootstrapAgent(ctx context.Context, ba *sentry.B
|
||||
}
|
||||
bdb.ModifiedAt = time.Now()
|
||||
bdb.DisplayName = ba.Metadata.DisplayName
|
||||
return s.bdao.UpdateBootstrapAgent(ctx, bdb, queryOptions)
|
||||
return dao.UpdateBootstrapAgent(ctx, s.db, bdb, queryOptions)
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *bootstrapService) GetBootstrapAgentForToken(ctx context.Context, token string) (*sentry.BootstrapAgent, error) {
|
||||
ba, err := s.bdao.GetBootstrapAgentForToken(ctx, token)
|
||||
ba, err := dao.GetBootstrapAgentForToken(ctx, s.db, token)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -390,7 +386,7 @@ func (s *bootstrapService) GetBootstrapAgentForToken(ctx context.Context, token
|
||||
}
|
||||
|
||||
func (s *bootstrapService) GetBootstrapAgentTemplateForHost(ctx context.Context, host string) (*sentry.BootstrapAgentTemplate, error) {
|
||||
bat, err := s.bdao.GetBootstrapAgentTemplateForHost(ctx, host)
|
||||
bat, err := dao.GetBootstrapAgentTemplateForHost(ctx, s.db, host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -400,7 +396,7 @@ func (s *bootstrapService) GetBootstrapAgentTemplateForHost(ctx context.Context,
|
||||
}
|
||||
|
||||
func (s *bootstrapService) GetBootstrapAgentCountForClusterID(ctx context.Context, clusterID string, orgID string) (int, error) {
|
||||
count, err := s.bdao.GetBootstrapAgentCountForClusterID(ctx, clusterID, uuid.MustParse(orgID))
|
||||
count, err := dao.GetBootstrapAgentCountForClusterID(ctx, s.db, clusterID, uuid.MustParse(orgID))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -411,7 +407,7 @@ func (s *bootstrapService) GetBootstrapAgentCountForClusterID(ctx context.Contex
|
||||
}
|
||||
|
||||
func (s *bootstrapService) GetBootstrapAgentForClusterID(ctx context.Context, clusterID string, orgID string) (*sentry.BootstrapAgent, error) {
|
||||
ba, err := s.bdao.GetBootstrapAgentForClusterID(ctx, clusterID, uuid.MustParse(orgID))
|
||||
ba, err := dao.GetBootstrapAgentForClusterID(ctx, s.db, clusterID, uuid.MustParse(orgID))
|
||||
if err != nil || ba == nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -455,7 +451,3 @@ func (s *bootstrapService) GetRelayAgent(ctx context.Context, ClusterScope strin
|
||||
_log.Infow("did not find relay bootstrap agent for", "cluster", ClusterScope, "template", queryOptions.Name)
|
||||
return nil, fmt.Errorf("failed to get relay agent")
|
||||
}
|
||||
|
||||
func (s *bootstrapService) Close() error {
|
||||
return s.dao.Close()
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ const (
|
||||
)
|
||||
|
||||
type ClusterService interface {
|
||||
Close() error
|
||||
// create Cluster
|
||||
Create(ctx context.Context, cluster *infrav3.Cluster) (*infrav3.Cluster, error)
|
||||
// get cluster
|
||||
@@ -90,12 +89,7 @@ type ClusterService interface {
|
||||
|
||||
// clusterService implements ClusterService
|
||||
type clusterService struct {
|
||||
dao pg.EntityDAO
|
||||
cdao dao.ClusterDao
|
||||
eobdao dao.ClusterOperatorBootstrapDao
|
||||
pcdao dao.ProjectClusterDao
|
||||
ctdao dao.ClusterTokenDao
|
||||
cndao dao.ClusterNamespacesDao
|
||||
db *bun.DB
|
||||
downloadData common.DownloadData
|
||||
clusterHandlers []event.Handler
|
||||
bs BootstrapService
|
||||
@@ -103,17 +97,7 @@ type clusterService struct {
|
||||
|
||||
// NewClusterService return new cluster service
|
||||
func NewClusterService(db *bun.DB, data *common.DownloadData, bs BootstrapService) ClusterService {
|
||||
entityDao := pg.NewEntityDAO(db)
|
||||
return &clusterService{
|
||||
dao: entityDao,
|
||||
cdao: dao.NewClusterDao(entityDao),
|
||||
eobdao: dao.NewClusterOperatorBootstrapDao(entityDao),
|
||||
pcdao: dao.NewProjectClusterDao(entityDao),
|
||||
ctdao: dao.NewClusterTokenDao(entityDao),
|
||||
cndao: dao.NewClusterNamespacesDao(entityDao),
|
||||
downloadData: *data,
|
||||
bs: bs,
|
||||
}
|
||||
return &clusterService{db: db, downloadData: *data, bs: bs}
|
||||
}
|
||||
|
||||
func (es *clusterService) Create(ctx context.Context, cluster *infrav3.Cluster) (*infrav3.Cluster, error) {
|
||||
@@ -128,7 +112,7 @@ func (es *clusterService) Create(ctx context.Context, cluster *infrav3.Cluster)
|
||||
}
|
||||
|
||||
var proj models.Project
|
||||
_, err := es.dao.GetByName(ctx, cluster.Metadata.Project, &proj)
|
||||
_, err := pg.GetByName(ctx, es.db, cluster.Metadata.Project, &proj)
|
||||
if err != nil {
|
||||
cluster.Status = &commonv3.Status{
|
||||
ConditionType: "Create",
|
||||
@@ -191,7 +175,7 @@ func (es *clusterService) Create(ctx context.Context, cluster *infrav3.Cluster)
|
||||
return cluster, fmt.Errorf(errormsg)
|
||||
}
|
||||
|
||||
clusterPresent, err := es.dao.GetByNamePartnerOrg(ctx, cluster.Metadata.Name, uuid.NullUUID{UUID: proj.PartnerId, Valid: true},
|
||||
clusterPresent, err := pg.GetByNamePartnerOrg(ctx, es.db, cluster.Metadata.Name, uuid.NullUUID{UUID: proj.PartnerId, Valid: true},
|
||||
uuid.NullUUID{UUID: proj.OrganizationId, Valid: true}, &models.Cluster{})
|
||||
if err != nil && err.Error() == "sql: no rows in result set" {
|
||||
_log.Infof("Skipping as first time cluster create ")
|
||||
@@ -207,7 +191,7 @@ func (es *clusterService) Create(ctx context.Context, cluster *infrav3.Cluster)
|
||||
|
||||
metro := &models.Metro{}
|
||||
if cluster.Spec.Metro != nil && cluster.Spec.Metro.Name != "" {
|
||||
if mdb, err := es.dao.GetByNamePartnerOrg(ctx, cluster.Spec.Metro.Name, uuid.NullUUID{UUID: proj.PartnerId, Valid: true}, uuid.NullUUID{UUID: uuid.Nil, Valid: false}, metro); err != nil {
|
||||
if mdb, err := pg.GetByNamePartnerOrg(ctx, es.db, cluster.Spec.Metro.Name, uuid.NullUUID{UUID: proj.PartnerId, Valid: true}, uuid.NullUUID{UUID: uuid.Nil, Valid: false}, metro); err != nil {
|
||||
errormsg = "Invalid cluster location, provide a valid metro name"
|
||||
cluster.Status = &commonv3.Status{
|
||||
ConditionType: "Create",
|
||||
@@ -276,7 +260,9 @@ func (es *clusterService) Create(ctx context.Context, cluster *infrav3.Cluster)
|
||||
|
||||
cluster.Spec.ClusterData.Health = infrav3.Health_EDGE_IGNORE
|
||||
|
||||
err = es.cdao.CreateCluster(ctx, edb)
|
||||
err = es.db.RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error {
|
||||
return dao.CreateCluster(ctx, tx, edb)
|
||||
})
|
||||
if err != nil {
|
||||
cluster.Status = &commonv3.Status{
|
||||
ConditionType: "Create",
|
||||
@@ -293,7 +279,7 @@ func (es *clusterService) Create(ctx context.Context, cluster *infrav3.Cluster)
|
||||
ProjectID: edb.ProjectId,
|
||||
ClusterID: edb.ID,
|
||||
}
|
||||
err = es.pcdao.CreateProjectCluster(ctx, pc)
|
||||
err = dao.CreateProjectCluster(ctx, es.db, pc)
|
||||
if err != nil {
|
||||
cluster.Status = &commonv3.Status{
|
||||
ConditionType: "Create",
|
||||
@@ -321,11 +307,14 @@ func (es *clusterService) Create(ctx context.Context, cluster *infrav3.Cluster)
|
||||
}
|
||||
_log.Infow("Creating cluster operator yaml", "clusterid", edb.ID)
|
||||
operatorSpecEncoded := base64.StdEncoding.EncodeToString([]byte(operatorSpecStr))
|
||||
boostrapData := models.ClusterOperatorBootstrap{
|
||||
bootstrapData := models.ClusterOperatorBootstrap{
|
||||
ClusterId: edb.ID,
|
||||
YamlContent: operatorSpecEncoded,
|
||||
}
|
||||
es.eobdao.CreateOperatorBootstrap(ctx, &boostrapData)
|
||||
|
||||
es.db.RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error {
|
||||
return dao.CreateOperatorBootstrap(ctx, tx, &bootstrapData)
|
||||
})
|
||||
}
|
||||
|
||||
ev := event.Resource{
|
||||
@@ -355,7 +344,7 @@ func (s *clusterService) Select(ctx context.Context, cluster *infrav3.Cluster, i
|
||||
if err != nil {
|
||||
id = uuid.Nil
|
||||
}
|
||||
c, err := s.cdao.GetCluster(ctx, &models.Cluster{ID: id, Name: cluster.Metadata.Name})
|
||||
c, err := dao.GetCluster(ctx, s.db, &models.Cluster{ID: id, Name: cluster.Metadata.Name})
|
||||
if err != nil {
|
||||
clstr.Status = &commonv3.Status{
|
||||
ConditionStatus: commonv3.ConditionStatus_StatusFailed,
|
||||
@@ -366,7 +355,7 @@ func (s *clusterService) Select(ctx context.Context, cluster *infrav3.Cluster, i
|
||||
}
|
||||
var projects []models.ProjectCluster
|
||||
if isExtended {
|
||||
projects, err = s.pcdao.GetProjectsForCluster(ctx, c.ID)
|
||||
projects, err = dao.GetProjectsForCluster(ctx, s.db, c.ID)
|
||||
if err != nil {
|
||||
clstr.Status = &commonv3.Status{
|
||||
ConditionStatus: commonv3.ConditionStatus_StatusFailed,
|
||||
@@ -379,7 +368,7 @@ func (s *clusterService) Select(ctx context.Context, cluster *infrav3.Cluster, i
|
||||
|
||||
var metro *models.Metro
|
||||
if c.MetroId != uuid.Nil {
|
||||
entity, err := s.dao.GetByID(ctx, c.MetroId, &models.Metro{})
|
||||
entity, err := pg.GetByID(ctx, s.db, c.MetroId, &models.Metro{})
|
||||
if err != nil {
|
||||
_log.Errorf("failed to fetch metro details", err)
|
||||
}
|
||||
@@ -407,7 +396,7 @@ func (s *clusterService) Get(ctx context.Context, opts ...query.Option) (*infrav
|
||||
if err != nil {
|
||||
id = uuid.Nil
|
||||
}
|
||||
c, err := s.cdao.GetCluster(ctx, &models.Cluster{ID: id, Name: queryOptions.Name})
|
||||
c, err := dao.GetCluster(ctx, s.db, &models.Cluster{ID: id, Name: queryOptions.Name})
|
||||
if err != nil {
|
||||
clstr.Status = &commonv3.Status{
|
||||
ConditionStatus: commonv3.ConditionStatus_StatusFailed,
|
||||
@@ -418,7 +407,7 @@ func (s *clusterService) Get(ctx context.Context, opts ...query.Option) (*infrav
|
||||
}
|
||||
var projects []models.ProjectCluster
|
||||
if queryOptions.Extended {
|
||||
projects, err = s.pcdao.GetProjectsForCluster(ctx, c.ID)
|
||||
projects, err = dao.GetProjectsForCluster(ctx, s.db, c.ID)
|
||||
if err != nil {
|
||||
clstr.Status = &commonv3.Status{
|
||||
ConditionStatus: commonv3.ConditionStatus_StatusFailed,
|
||||
@@ -441,19 +430,19 @@ func (s *clusterService) Get(ctx context.Context, opts ...query.Option) (*infrav
|
||||
func (s *clusterService) prepareClusterResponse(ctx context.Context, clstr *infrav3.Cluster, c *models.Cluster, metro *models.Metro, projects []models.ProjectCluster, isExtended bool) *infrav3.Cluster {
|
||||
|
||||
var part models.Partner
|
||||
_, err := s.dao.GetNameById(ctx, c.PartnerId, &part)
|
||||
_, err := pg.GetNameById(ctx, s.db, c.PartnerId, &part)
|
||||
if err != nil {
|
||||
_log.Infow("unable to fetch partner information, ", err.Error())
|
||||
}
|
||||
|
||||
var org models.Organization
|
||||
_, err = s.dao.GetNameById(ctx, c.OrganizationId, &org)
|
||||
_, err = pg.GetNameById(ctx, s.db, c.OrganizationId, &org)
|
||||
if err != nil {
|
||||
_log.Infow("unable to fetch organization information, ", err.Error())
|
||||
}
|
||||
|
||||
var proj models.Project
|
||||
_, err = s.dao.GetNameById(ctx, c.ProjectId, &proj)
|
||||
_, err = pg.GetNameById(ctx, s.db, c.ProjectId, &proj)
|
||||
if err != nil {
|
||||
_log.Infow("unable to fetch project information, ", err.Error())
|
||||
}
|
||||
@@ -539,7 +528,7 @@ func (cs *clusterService) Update(ctx context.Context, cluster *infrav3.Cluster)
|
||||
return cluster, fmt.Errorf("invalid cluster data, name is missing")
|
||||
}
|
||||
|
||||
edb, err := cs.dao.GetByName(ctx, cluster.Metadata.Name, &models.Cluster{})
|
||||
edb, err := pg.GetByName(ctx, cs.db, cluster.Metadata.Name, &models.Cluster{})
|
||||
if err != nil {
|
||||
cluster.Status = &commonv3.Status{
|
||||
ConditionType: "Update",
|
||||
@@ -596,7 +585,7 @@ func (cs *clusterService) Update(ctx context.Context, cluster *infrav3.Cluster)
|
||||
if cluster.Spec.Metro != nil && cdb.MetroId.String() != cluster.Spec.Metro.Id {
|
||||
metro := &models.Metro{}
|
||||
if cluster.Spec.Metro.Name != "" {
|
||||
if mdb, err := cs.dao.GetByNamePartnerOrg(ctx, cluster.Spec.Metro.Name, uuid.NullUUID{UUID: pid, Valid: true}, uuid.NullUUID{UUID: uuid.Nil, Valid: false}, metro); err != nil {
|
||||
if mdb, err := pg.GetByNamePartnerOrg(ctx, cs.db, cluster.Spec.Metro.Name, uuid.NullUUID{UUID: pid, Valid: true}, uuid.NullUUID{UUID: uuid.Nil, Valid: false}, metro); err != nil {
|
||||
errormsg = "Invalid cluster location, provide a valid metro name"
|
||||
cluster.Status = &commonv3.Status{
|
||||
ConditionType: "Update",
|
||||
@@ -631,7 +620,7 @@ func (cs *clusterService) Update(ctx context.Context, cluster *infrav3.Cluster)
|
||||
}
|
||||
|
||||
}
|
||||
err = cs.cdao.UpdateCluster(ctx, cdb)
|
||||
err = dao.UpdateCluster(ctx, cs.db, cdb)
|
||||
if err != nil {
|
||||
cluster.Status = &commonv3.Status{
|
||||
ConditionStatus: commonv3.ConditionStatus_StatusFailed,
|
||||
@@ -719,11 +708,11 @@ func (cs *clusterService) deleteCluster(ctx context.Context, clusterId, projectI
|
||||
ID: uuid.MustParse(clusterId),
|
||||
ProjectId: uuid.MustParse(projectId),
|
||||
}
|
||||
err := cs.pcdao.DeleteProjectsForCluster(ctx, uuid.MustParse(clusterId))
|
||||
err := dao.DeleteProjectsForCluster(ctx, cs.db, uuid.MustParse(clusterId))
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not delete projects for cluster %s", clusterId)
|
||||
}
|
||||
return cs.cdao.DeleteCluster(ctx, &c)
|
||||
return dao.DeleteCluster(ctx, cs.db, &c)
|
||||
}
|
||||
|
||||
func (cs *clusterService) List(ctx context.Context, opts ...query.Option) (*infrav3.ClusterList, error) {
|
||||
@@ -734,12 +723,12 @@ func (cs *clusterService) List(ctx context.Context, opts ...query.Option) (*infr
|
||||
}
|
||||
|
||||
var proj models.Project
|
||||
_, err := cs.dao.GetByName(ctx, queryOptions.Project, &proj)
|
||||
_, err := pg.GetByName(ctx, cs.db, queryOptions.Project, &proj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cdb, err := cs.cdao.ListClusters(ctx, commonv3.QueryOptions{
|
||||
cdb, err := dao.ListClusters(ctx, cs.db, commonv3.QueryOptions{
|
||||
Project: proj.ID.String(),
|
||||
Organization: proj.OrganizationId.String(),
|
||||
Partner: proj.PartnerId.String(),
|
||||
@@ -760,13 +749,13 @@ func (cs *clusterService) List(ctx context.Context, opts ...query.Option) (*infr
|
||||
|
||||
var items []*infrav3.Cluster
|
||||
for _, clstr := range cdb {
|
||||
projects, err := cs.pcdao.GetProjectsForCluster(ctx, clstr.ID)
|
||||
projects, err := dao.GetProjectsForCluster(ctx, cs.db, clstr.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
metro := &models.Metro{}
|
||||
if clstr.MetroId != uuid.Nil {
|
||||
entity, err := cs.dao.GetByID(ctx, clstr.MetroId, &models.Metro{})
|
||||
entity, err := pg.GetByID(ctx, cs.db, clstr.MetroId, &models.Metro{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -831,7 +820,7 @@ func (s *clusterService) UpdateClusterConditionStatus(ctx context.Context, curre
|
||||
func (s *clusterService) UpdateClusterAnnotations(ctx context.Context, cluster *infrav3.Cluster) error {
|
||||
if len(cluster.Metadata.Annotations) > 0 {
|
||||
annBytes, _ := json.Marshal(cluster.Metadata.Annotations)
|
||||
return s.cdao.UpdateClusterAnnotations(ctx, &models.Cluster{
|
||||
return dao.UpdateClusterAnnotations(ctx, s.db, &models.Cluster{
|
||||
ID: uuid.MustParse(cluster.Metadata.Id),
|
||||
Annotations: json.RawMessage(annBytes),
|
||||
})
|
||||
@@ -840,7 +829,7 @@ func (s *clusterService) UpdateClusterAnnotations(ctx context.Context, cluster *
|
||||
}
|
||||
|
||||
func (s *clusterService) ListenClusters(ctx context.Context, mChan chan<- commonv3.Metadata) {
|
||||
listener := pgdriver.NewListener(s.dao.GetInstance())
|
||||
listener := pgdriver.NewListener(s.db)
|
||||
listener.Listen(ctx, clusterNotifyChan)
|
||||
notifyChan := listener.Channel()
|
||||
listenerLoop:
|
||||
@@ -877,11 +866,11 @@ func (s *clusterService) GetClusterProjects(ctx context.Context, cluster *infrav
|
||||
if err != nil {
|
||||
id = uuid.Nil
|
||||
}
|
||||
c, err := s.cdao.GetCluster(ctx, &models.Cluster{ID: id, Name: cluster.Metadata.Name})
|
||||
c, err := dao.GetCluster(ctx, s.db, &models.Cluster{ID: id, Name: cluster.Metadata.Name})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
projects, err := s.pcdao.GetProjectsForCluster(ctx, c.ID)
|
||||
projects, err := dao.GetProjectsForCluster(ctx, s.db, c.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -895,7 +884,7 @@ func (s *clusterService) UpdateStatus(ctx context.Context, current *infrav3.Clus
|
||||
opt(&queryOptions)
|
||||
}
|
||||
|
||||
isAllowed, err := s.pcdao.ValidateClusterAccess(ctx, queryOptions)
|
||||
isAllowed, err := dao.ValidateClusterAccess(ctx, s.db, queryOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -958,7 +947,7 @@ func (s *clusterService) deleteBootstrapAgentForCluster(ctx context.Context, clu
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.bs.DeleteBoostrapAgent(ctx, templateRef, query.WithMeta(agent.Metadata))
|
||||
err = s.bs.DeleteBootstrapAgent(ctx, templateRef, query.WithMeta(agent.Metadata))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1163,7 +1152,7 @@ func (s *clusterService) notifyCluster(ctx context.Context, c *infrav3.Cluster)
|
||||
return
|
||||
}
|
||||
|
||||
err = s.cdao.Notify(clusterNotifyChan, string(b))
|
||||
err = dao.Notify(s.db, clusterNotifyChan, string(b))
|
||||
if err != nil {
|
||||
_log.Infow("unable to send cluster notification", "error", err)
|
||||
return
|
||||
@@ -1173,7 +1162,3 @@ func (s *clusterService) notifyCluster(ctx context.Context, c *infrav3.Cluster)
|
||||
func (s *clusterService) AddEventHandler(evh event.Handler) {
|
||||
s.clusterHandlers = append(s.clusterHandlers, evh)
|
||||
}
|
||||
|
||||
func (s *clusterService) Close() error {
|
||||
return s.dao.Close()
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ func TestCreateCluster(t *testing.T) {
|
||||
}
|
||||
|
||||
ps := NewClusterService(db, downloadData, NewBootstrapService(db))
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
cuuid := uuid.New().String()
|
||||
@@ -77,7 +76,6 @@ func TestUpdateCluster(t *testing.T) {
|
||||
}
|
||||
|
||||
ps := NewClusterService(db, downloadData, NewBootstrapService(db))
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
cuuid := uuid.New().String()
|
||||
@@ -112,7 +110,6 @@ func TestSelectCluster(t *testing.T) {
|
||||
}
|
||||
|
||||
ps := NewClusterService(db, downloadData, NewBootstrapService(db))
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
cuuid := uuid.New().String()
|
||||
@@ -147,7 +144,6 @@ func TestGetCluster(t *testing.T) {
|
||||
}
|
||||
|
||||
ps := NewClusterService(db, downloadData, NewBootstrapService(db))
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
cuuid := uuid.New().String()
|
||||
@@ -181,7 +177,6 @@ func TestListCluster(t *testing.T) {
|
||||
}
|
||||
|
||||
ps := NewClusterService(db, downloadData, NewBootstrapService(db))
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
ouuid := uuid.New().String()
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/RafaySystems/rcloud-base/internal/dao"
|
||||
"github.com/RafaySystems/rcloud-base/internal/models"
|
||||
"github.com/RafaySystems/rcloud-base/internal/persistence/provider/pg"
|
||||
"github.com/RafaySystems/rcloud-base/internal/utils"
|
||||
authzv1 "github.com/RafaySystems/rcloud-base/proto/types/authz"
|
||||
v3 "github.com/RafaySystems/rcloud-base/proto/types/commonpb/v3"
|
||||
userv3 "github.com/RafaySystems/rcloud-base/proto/types/userpb/v3"
|
||||
@@ -25,7 +24,6 @@ const (
|
||||
|
||||
// GroupService is the interface for group operations
|
||||
type GroupService interface {
|
||||
Close() error
|
||||
// create group
|
||||
Create(context.Context, *userv3.Group) (*userv3.Group, error)
|
||||
// get group by id
|
||||
@@ -42,41 +40,34 @@ type GroupService interface {
|
||||
|
||||
// groupService implements GroupService
|
||||
type groupService struct {
|
||||
dao pg.EntityDAO
|
||||
gdao dao.GroupDAO
|
||||
l utils.Lookup
|
||||
azc AuthzService
|
||||
db *bun.DB
|
||||
azc AuthzService
|
||||
}
|
||||
|
||||
// NewGroupService return new group service
|
||||
func NewGroupService(db *bun.DB, azc AuthzService) GroupService {
|
||||
return &groupService{
|
||||
dao: pg.NewEntityDAO(db),
|
||||
gdao: dao.NewGroupDAO(db),
|
||||
l: utils.NewLookup(db),
|
||||
azc: azc,
|
||||
}
|
||||
return &groupService{db: db, azc: azc}
|
||||
}
|
||||
|
||||
func (s *groupService) deleteGroupRoleRelaitons(ctx context.Context, groupId uuid.UUID, group *userv3.Group) (*userv3.Group, error) {
|
||||
// delete previous entries
|
||||
// TODO: single delete command
|
||||
err := s.dao.DeleteX(ctx, "group_id", groupId, &models.GroupRole{})
|
||||
err := pg.DeleteX(ctx, s.db, "group_id", groupId, &models.GroupRole{})
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
err = s.dao.DeleteX(ctx, "group_id", groupId, &models.ProjectGroupRole{})
|
||||
err = pg.DeleteX(ctx, s.db, "group_id", groupId, &models.ProjectGroupRole{})
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
err = s.dao.DeleteX(ctx, "group_id", groupId, &models.ProjectGroupNamespaceRole{})
|
||||
err = pg.DeleteX(ctx, s.db, "group_id", groupId, &models.ProjectGroupNamespaceRole{})
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
|
||||
_, err = s.azc.DeletePolicies(ctx, &authzv1.Policy{Sub: "g:" + group.GetMetadata().GetName()})
|
||||
if err != nil {
|
||||
return &userv3.Group{}, fmt.Errorf("unable to delete gorup-role relations from authz; %v", err)
|
||||
return &userv3.Group{}, fmt.Errorf("unable to delete group-role relations from authz; %v", err)
|
||||
}
|
||||
return group, nil
|
||||
}
|
||||
@@ -92,7 +83,7 @@ func (s *groupService) createGroupRoleRelations(ctx context.Context, group *user
|
||||
var ps []*authzv1.Policy
|
||||
for _, pnr := range projectNamespaceRoles {
|
||||
role := pnr.GetRole()
|
||||
entity, err := s.dao.GetIdByName(ctx, role, &models.Role{})
|
||||
entity, err := pg.GetIdByName(ctx, s.db, role, &models.Role{})
|
||||
if err != nil {
|
||||
return &userv3.Group{}, fmt.Errorf("unable to find role '%v'", role)
|
||||
}
|
||||
@@ -108,7 +99,7 @@ func (s *groupService) createGroupRoleRelations(ctx context.Context, group *user
|
||||
namespaceId := pnr.GetNamespace() // TODO: lookup id from name
|
||||
switch {
|
||||
case namespaceId != 0:
|
||||
projectId, err := s.l.GetProjectId(ctx, project)
|
||||
projectId, err := pg.GetProjectId(ctx, s.db, project)
|
||||
if err != nil {
|
||||
return &userv3.Group{}, fmt.Errorf("unable to find project '%v'", project)
|
||||
}
|
||||
@@ -133,7 +124,7 @@ func (s *groupService) createGroupRoleRelations(ctx context.Context, group *user
|
||||
Act: "*",
|
||||
})
|
||||
case project != "":
|
||||
projectId, err := s.l.GetProjectId(ctx, project)
|
||||
projectId, err := pg.GetProjectId(ctx, s.db, project)
|
||||
if err != nil {
|
||||
return &userv3.Group{}, fmt.Errorf("unable to find project '%v'", project)
|
||||
}
|
||||
@@ -177,19 +168,19 @@ func (s *groupService) createGroupRoleRelations(ctx context.Context, group *user
|
||||
}
|
||||
}
|
||||
if len(pgnrs) > 0 {
|
||||
_, err := s.dao.Create(ctx, &pgnrs)
|
||||
_, err := pg.Create(ctx, s.db, &pgnrs)
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
}
|
||||
if len(pgrs) > 0 {
|
||||
_, err := s.dao.Create(ctx, &pgrs)
|
||||
_, err := pg.Create(ctx, s.db, &pgrs)
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
}
|
||||
if len(grs) > 0 {
|
||||
_, err := s.dao.Create(ctx, &grs)
|
||||
_, err := pg.Create(ctx, s.db, &grs)
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
@@ -206,14 +197,14 @@ func (s *groupService) createGroupRoleRelations(ctx context.Context, group *user
|
||||
}
|
||||
|
||||
func (s *groupService) deleteGroupAccountRelations(ctx context.Context, groupId uuid.UUID, group *userv3.Group) (*userv3.Group, error) {
|
||||
err := s.dao.DeleteX(ctx, "group_id", groupId, &models.GroupAccount{})
|
||||
err := pg.DeleteX(ctx, s.db, "group_id", groupId, &models.GroupAccount{})
|
||||
if err != nil {
|
||||
return &userv3.Group{}, fmt.Errorf("unable to delete user; %v", err)
|
||||
}
|
||||
|
||||
_, err = s.azc.DeleteUserGroups(ctx, &authzv1.UserGroup{Grp: "g:" + group.GetMetadata().GetName()})
|
||||
if err != nil {
|
||||
return &userv3.Group{}, fmt.Errorf("unable to delete gorup-user relations from authz; %v", err)
|
||||
return &userv3.Group{}, fmt.Errorf("unable to delete group-user relations from authz; %v", err)
|
||||
}
|
||||
return group, nil
|
||||
}
|
||||
@@ -225,7 +216,7 @@ func (s *groupService) createGroupAccountRelations(ctx context.Context, groupId
|
||||
var ugs []*authzv1.UserGroup
|
||||
for _, account := range unique(group.GetSpec().GetUsers()) {
|
||||
// FIXME: do combined lookup
|
||||
entity, err := s.dao.GetIdByTraits(ctx, account, &models.KratosIdentities{})
|
||||
entity, err := pg.GetIdByTraits(ctx, s.db, account, &models.KratosIdentities{})
|
||||
if err != nil {
|
||||
return &userv3.Group{}, fmt.Errorf("unable to find user '%v'", account)
|
||||
}
|
||||
@@ -248,13 +239,13 @@ func (s *groupService) createGroupAccountRelations(ctx context.Context, groupId
|
||||
if len(grpaccs) == 0 {
|
||||
return group, nil
|
||||
}
|
||||
_, err := s.dao.Create(ctx, &grpaccs)
|
||||
_, err := pg.Create(ctx, s.db, &grpaccs)
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
|
||||
// TODO: revert our db inserts if this fails
|
||||
// Just FYI, the succcess can be false if we delete the db directly but casbin has it available internally
|
||||
// Just FYI, the success can be false if we delete the db directly but casbin has it available internally
|
||||
_, err = s.azc.CreateUserGroups(ctx, &authzv1.UserGroups{UserGroups: ugs})
|
||||
if err != nil {
|
||||
return &userv3.Group{}, fmt.Errorf("unable to create mapping in authz; %v", err)
|
||||
@@ -266,11 +257,11 @@ func (s *groupService) createGroupAccountRelations(ctx context.Context, groupId
|
||||
func (s *groupService) getPartnerOrganization(ctx context.Context, group *userv3.Group) (uuid.UUID, uuid.UUID, error) {
|
||||
partner := group.GetMetadata().GetPartner()
|
||||
org := group.GetMetadata().GetOrganization()
|
||||
partnerId, err := s.l.GetPartnerId(ctx, partner)
|
||||
partnerId, err := pg.GetPartnerId(ctx, s.db, partner)
|
||||
if err != nil {
|
||||
return uuid.Nil, uuid.Nil, err
|
||||
}
|
||||
organizationId, err := s.l.GetOrganizationId(ctx, org)
|
||||
organizationId, err := pg.GetOrganizationId(ctx, s.db, org)
|
||||
if err != nil {
|
||||
return partnerId, uuid.Nil, err
|
||||
}
|
||||
@@ -283,7 +274,7 @@ func (s *groupService) Create(ctx context.Context, group *userv3.Group) (*userv3
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get partner and org id")
|
||||
}
|
||||
g, _ := s.dao.GetIdByNamePartnerOrg(ctx, group.GetMetadata().GetName(), uuid.NullUUID{UUID: partnerId, Valid: true}, uuid.NullUUID{UUID: organizationId, Valid: true}, &models.Group{})
|
||||
g, _ := pg.GetIdByNamePartnerOrg(ctx, s.db, group.GetMetadata().GetName(), uuid.NullUUID{UUID: partnerId, Valid: true}, uuid.NullUUID{UUID: organizationId, Valid: true}, &models.Group{})
|
||||
if g != nil {
|
||||
return nil, fmt.Errorf("group '%v' already exists", group.GetMetadata().GetName())
|
||||
}
|
||||
@@ -298,7 +289,7 @@ func (s *groupService) Create(ctx context.Context, group *userv3.Group) (*userv3
|
||||
PartnerId: partnerId,
|
||||
Type: group.GetSpec().GetType(),
|
||||
}
|
||||
entity, err := s.dao.Create(ctx, &grp)
|
||||
entity, err := pg.Create(ctx, s.db, &grp)
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
@@ -335,7 +326,7 @@ func (s *groupService) toV3Group(ctx context.Context, group *userv3.Group, grp *
|
||||
Labels: labels,
|
||||
ModifiedAt: timestamppb.New(grp.ModifiedAt),
|
||||
}
|
||||
users, err := s.gdao.GetUsers(ctx, grp.ID)
|
||||
users, err := dao.GetUsers(ctx, s.db, grp.ID)
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
@@ -344,7 +335,7 @@ func (s *groupService) toV3Group(ctx context.Context, group *userv3.Group, grp *
|
||||
userNames = append(userNames, u.Traits["email"].(string))
|
||||
}
|
||||
|
||||
roles, err := s.gdao.GetRoles(ctx, grp.ID)
|
||||
roles, err := dao.GetGroupRoles(ctx, s.db, grp.ID)
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
@@ -362,7 +353,7 @@ func (s *groupService) GetByID(ctx context.Context, group *userv3.Group) (*userv
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
entity, err := s.dao.GetByID(ctx, uid, &models.Group{})
|
||||
entity, err := pg.GetByID(ctx, s.db, uid, &models.Group{})
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
@@ -380,7 +371,7 @@ func (s *groupService) GetByName(ctx context.Context, group *userv3.Group) (*use
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get partner and org id")
|
||||
}
|
||||
entity, err := s.dao.GetByNamePartnerOrg(ctx, name, uuid.NullUUID{UUID: partnerId, Valid: true}, uuid.NullUUID{UUID: organizationId, Valid: true}, &models.Group{})
|
||||
entity, err := pg.GetByNamePartnerOrg(ctx, s.db, name, uuid.NullUUID{UUID: partnerId, Valid: true}, uuid.NullUUID{UUID: organizationId, Valid: true}, &models.Group{})
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
@@ -399,7 +390,7 @@ func (s *groupService) Update(ctx context.Context, group *userv3.Group) (*userv3
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get partner and org id")
|
||||
}
|
||||
entity, err := s.dao.GetByNamePartnerOrg(ctx, name, uuid.NullUUID{UUID: partnerId, Valid: true}, uuid.NullUUID{UUID: organizationId, Valid: true}, &models.Group{})
|
||||
entity, err := pg.GetByNamePartnerOrg(ctx, s.db, name, uuid.NullUUID{UUID: partnerId, Valid: true}, uuid.NullUUID{UUID: organizationId, Valid: true}, &models.Group{})
|
||||
if err != nil {
|
||||
return &userv3.Group{}, fmt.Errorf("no group found with name '%v'", name)
|
||||
}
|
||||
@@ -429,7 +420,7 @@ func (s *groupService) Update(ctx context.Context, group *userv3.Group) (*userv3
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
|
||||
_, err = s.dao.Update(ctx, grp.ID, grp)
|
||||
_, err = pg.Update(ctx, s.db, grp.ID, grp)
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
@@ -451,7 +442,7 @@ func (s *groupService) Delete(ctx context.Context, group *userv3.Group) (*userv3
|
||||
if err != nil {
|
||||
return &userv3.Group{}, fmt.Errorf("unable to get partner and org id")
|
||||
}
|
||||
entity, err := s.dao.GetByNamePartnerOrg(ctx, name, uuid.NullUUID{UUID: partnerId, Valid: true}, uuid.NullUUID{UUID: organizationId, Valid: true}, &models.Group{})
|
||||
entity, err := pg.GetByNamePartnerOrg(ctx, s.db, name, uuid.NullUUID{UUID: partnerId, Valid: true}, uuid.NullUUID{UUID: organizationId, Valid: true}, &models.Group{})
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
@@ -464,7 +455,7 @@ func (s *groupService) Delete(ctx context.Context, group *userv3.Group) (*userv3
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
err = s.dao.Delete(ctx, grp.ID, grp)
|
||||
err = pg.Delete(ctx, s.db, grp.ID, grp)
|
||||
if err != nil {
|
||||
return &userv3.Group{}, err
|
||||
}
|
||||
@@ -483,16 +474,16 @@ func (s *groupService) List(ctx context.Context, group *userv3.Group) (*userv3.G
|
||||
},
|
||||
}
|
||||
if len(group.Metadata.Organization) > 0 {
|
||||
orgId, err := s.l.GetOrganizationId(ctx, group.Metadata.Organization)
|
||||
orgId, err := pg.GetOrganizationId(ctx, s.db, group.Metadata.Organization)
|
||||
if err != nil {
|
||||
return groupList, err
|
||||
}
|
||||
partId, err := s.l.GetPartnerId(ctx, group.Metadata.Partner)
|
||||
partId, err := pg.GetPartnerId(ctx, s.db, group.Metadata.Partner)
|
||||
if err != nil {
|
||||
return groupList, err
|
||||
}
|
||||
var grps []models.Group
|
||||
entities, err := s.dao.List(ctx, uuid.NullUUID{UUID: partId, Valid: true}, uuid.NullUUID{UUID: orgId, Valid: true}, &grps)
|
||||
entities, err := pg.List(ctx, s.db, uuid.NullUUID{UUID: partId, Valid: true}, uuid.NullUUID{UUID: orgId, Valid: true}, &grps)
|
||||
if err != nil {
|
||||
return groupList, err
|
||||
}
|
||||
@@ -518,7 +509,3 @@ func (s *groupService) List(ctx context.Context, group *userv3.Group) (*userv3.G
|
||||
}
|
||||
return groupList, nil
|
||||
}
|
||||
|
||||
func (s *groupService) Close() error {
|
||||
return s.dao.Close()
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/RafaySystems/rcloud-base/internal/dao"
|
||||
"github.com/RafaySystems/rcloud-base/internal/models"
|
||||
"github.com/RafaySystems/rcloud-base/internal/persistence/provider/pg"
|
||||
"github.com/RafaySystems/rcloud-base/proto/types/sentry"
|
||||
"github.com/google/uuid"
|
||||
"github.com/uptrace/bun"
|
||||
@@ -14,7 +13,6 @@ import (
|
||||
|
||||
// GroupPermissionService is the interface for group permission operations
|
||||
type GroupPermissionService interface {
|
||||
Close() error
|
||||
GetGroupPermissions(ctx context.Context, groupNames []string, orgID, partnerID string) ([]sentry.GroupPermission, error)
|
||||
GetGroupProjectsByPermission(ctx context.Context, groupNames []string, orgID, partnerID string, permission string) ([]sentry.GroupPermission, error)
|
||||
GetGroupPermissionsByProjectIDPermissions(ctx context.Context, groupNames []string, orgID, partnerID string, projects []string, permissions []string) ([]sentry.GroupPermission, error)
|
||||
@@ -23,25 +21,16 @@ type GroupPermissionService interface {
|
||||
|
||||
// groupPermissionService implements GroupPermissionService
|
||||
type groupPermissionService struct {
|
||||
dao pg.EntityDAO
|
||||
pdao dao.PermissionDao
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
// NewKubeconfigRevocation return new kubeconfig revocation service
|
||||
func NewGroupPermissionService(db *bun.DB) GroupPermissionService {
|
||||
edao := pg.NewEntityDAO(db)
|
||||
return &groupPermissionService{
|
||||
dao: edao,
|
||||
pdao: dao.NewPermissionDao(edao),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *groupPermissionService) Close() error {
|
||||
return s.dao.Close()
|
||||
return &groupPermissionService{db}
|
||||
}
|
||||
|
||||
func (s *groupPermissionService) GetGroupPermissions(ctx context.Context, groupNames []string, orgID, partnerID string) ([]sentry.GroupPermission, error) {
|
||||
gps, err := s.pdao.GetGroupPermissions(ctx, groupNames, uuid.MustParse(orgID), uuid.MustParse(partnerID))
|
||||
gps, err := dao.GetGroupPermissions(ctx, s.db, groupNames, uuid.MustParse(orgID), uuid.MustParse(partnerID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -53,8 +42,8 @@ func (s *groupPermissionService) GetGroupPermissions(ctx context.Context, groupN
|
||||
return groupPermissions, nil
|
||||
}
|
||||
|
||||
func (a *groupPermissionService) GetGroupProjectsByPermission(ctx context.Context, groupNames []string, orgID, partnerID string, permission string) ([]sentry.GroupPermission, error) {
|
||||
aps, err := a.pdao.GetGroupProjectsByPermission(ctx, groupNames, uuid.MustParse(orgID), uuid.MustParse(partnerID), permission)
|
||||
func (s *groupPermissionService) GetGroupProjectsByPermission(ctx context.Context, groupNames []string, orgID, partnerID string, permission string) ([]sentry.GroupPermission, error) {
|
||||
aps, err := dao.GetGroupProjectsByPermission(ctx, s.db, groupNames, uuid.MustParse(orgID), uuid.MustParse(partnerID), permission)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -67,7 +56,7 @@ func (a *groupPermissionService) GetGroupProjectsByPermission(ctx context.Contex
|
||||
}
|
||||
|
||||
func (s *groupPermissionService) GetGroupPermissionsByProjectIDPermissions(ctx context.Context, groupNames []string, orgID, partnerID string, projects []string, permissions []string) ([]sentry.GroupPermission, error) {
|
||||
gps, err := s.pdao.GetGroupPermissionsByProjectIDPermissions(ctx, groupNames, uuid.MustParse(orgID), uuid.MustParse(partnerID), projects, permissions)
|
||||
gps, err := dao.GetGroupPermissionsByProjectIDPermissions(ctx, s.db, groupNames, uuid.MustParse(orgID), uuid.MustParse(partnerID), projects, permissions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -80,7 +69,7 @@ func (s *groupPermissionService) GetGroupPermissionsByProjectIDPermissions(ctx c
|
||||
}
|
||||
|
||||
func (s *groupPermissionService) GetProjectByGroup(ctx context.Context, groupNames []string, orgID, partnerID string) ([]sentry.GroupPermission, error) {
|
||||
gps, err := s.pdao.GetProjectByGroup(ctx, groupNames, uuid.MustParse(orgID), uuid.MustParse(partnerID))
|
||||
gps, err := dao.GetProjectByGroup(ctx, s.db, groupNames, uuid.MustParse(orgID), uuid.MustParse(partnerID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ func TestGetGroupPermissions(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewGroupPermissionService(db)
|
||||
defer ps.Close()
|
||||
|
||||
groupNames := []string{"mygroup", "admin"}
|
||||
gid := uuid.New()
|
||||
@@ -34,7 +33,6 @@ func TestGetGroupProjectsByPermission(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewGroupPermissionService(db)
|
||||
defer ps.Close()
|
||||
|
||||
groupNames := []string{"mygroup", "admin"}
|
||||
gid := uuid.New()
|
||||
@@ -55,7 +53,6 @@ func TestGetGroupPermissionsByProjectIDPermissions(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewGroupPermissionService(db)
|
||||
defer ps.Close()
|
||||
|
||||
groupNames := []string{"mygroup", "admin"}
|
||||
projectNames := []string{"myproject"}
|
||||
|
||||
@@ -83,7 +83,6 @@ func TestCreateGroupNoUsersNoRoles(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
gs := NewGroupService(db, &mazc)
|
||||
defer gs.Close()
|
||||
|
||||
guuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -117,7 +116,6 @@ func TestCreateGroupDuplicate(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
gs := NewGroupService(db, &mazc)
|
||||
defer gs.Close()
|
||||
|
||||
guuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -161,7 +159,6 @@ func TestCreateGroupWithUsersNoRoles(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
gs := NewGroupService(db, &mazc)
|
||||
defer gs.Close()
|
||||
|
||||
guuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -226,7 +223,6 @@ func TestCreateGroupNoUsersWithRoles(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
gs := NewGroupService(db, &mazc)
|
||||
defer gs.Close()
|
||||
|
||||
guuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -303,7 +299,6 @@ func TestCreateGroupWithUsersWithRoles(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
gs := NewGroupService(db, &mazc)
|
||||
defer gs.Close()
|
||||
|
||||
guuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -384,7 +379,6 @@ func TestUpdateGroupWithUsersWithRoles(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
gs := NewGroupService(db, &mazc)
|
||||
defer gs.Close()
|
||||
|
||||
guuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -457,7 +451,6 @@ func TestGroupDelete(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
gs := NewGroupService(db, &mazc)
|
||||
defer gs.Close()
|
||||
|
||||
guuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -496,7 +489,6 @@ func TestGroupDeleteNonExist(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
gs := NewGroupService(db, &mazc)
|
||||
defer gs.Close()
|
||||
|
||||
guuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -520,7 +512,6 @@ func TestGroupGetByName(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
gs := NewGroupService(db, &mazc)
|
||||
defer gs.Close()
|
||||
|
||||
guuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -571,7 +562,6 @@ func TestGroupGetById(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
gs := NewGroupService(db, &mazc)
|
||||
defer gs.Close()
|
||||
|
||||
guuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -618,7 +608,6 @@ func TestGroupList(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
gs := NewGroupService(db, &mazc)
|
||||
defer gs.Close()
|
||||
|
||||
guuid1 := uuid.New().String()
|
||||
guuid2 := uuid.New().String()
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
|
||||
"github.com/RafaySystems/rcloud-base/internal/models"
|
||||
"github.com/RafaySystems/rcloud-base/internal/persistence/provider/pg"
|
||||
"github.com/RafaySystems/rcloud-base/internal/utils"
|
||||
commonv3 "github.com/RafaySystems/rcloud-base/proto/types/commonpb/v3"
|
||||
systemv3 "github.com/RafaySystems/rcloud-base/proto/types/systempb/v3"
|
||||
"github.com/google/uuid"
|
||||
@@ -35,17 +34,12 @@ type IdpService interface {
|
||||
}
|
||||
|
||||
type idpService struct {
|
||||
dao pg.EntityDAO
|
||||
db *bun.DB
|
||||
appHost string
|
||||
l utils.Lookup
|
||||
}
|
||||
|
||||
func NewIdpService(db *bun.DB, hostUrl string) IdpService {
|
||||
return &idpService{
|
||||
dao: pg.NewEntityDAO(db),
|
||||
appHost: hostUrl,
|
||||
l: utils.NewLookup(db),
|
||||
}
|
||||
return &idpService{db: db, appHost: hostUrl}
|
||||
}
|
||||
|
||||
func generateAcsURL(id string, hostUrl string) string {
|
||||
@@ -110,11 +104,11 @@ func generateSpCert(host string) (string, string, error) {
|
||||
func (s *idpService) getPartnerOrganization(ctx context.Context, provider *systemv3.Idp) (uuid.UUID, uuid.UUID, error) {
|
||||
partner := provider.GetMetadata().GetPartner()
|
||||
org := provider.GetMetadata().GetOrganization()
|
||||
partnerId, err := s.l.GetPartnerId(ctx, partner)
|
||||
partnerId, err := pg.GetPartnerId(ctx, s.db, partner)
|
||||
if err != nil {
|
||||
return uuid.Nil, uuid.Nil, err
|
||||
}
|
||||
organizationId, err := s.l.GetOrganizationId(ctx, org)
|
||||
organizationId, err := pg.GetOrganizationId(ctx, s.db, org)
|
||||
if err != nil {
|
||||
return partnerId, uuid.Nil, err
|
||||
}
|
||||
@@ -137,8 +131,9 @@ func (s *idpService) Create(ctx context.Context, idp *systemv3.Idp) (*systemv3.I
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get partner and org id")
|
||||
}
|
||||
i, _ := s.dao.GetIdByNamePartnerOrg(
|
||||
i, _ := pg.GetIdByNamePartnerOrg(
|
||||
ctx,
|
||||
s.db,
|
||||
idp.GetMetadata().GetName(),
|
||||
uuid.NullUUID{UUID: partnerId, Valid: true},
|
||||
uuid.NullUUID{UUID: organizationId, Valid: true},
|
||||
@@ -149,7 +144,7 @@ func (s *idpService) Create(ctx context.Context, idp *systemv3.Idp) (*systemv3.I
|
||||
}
|
||||
|
||||
e := &models.Idp{}
|
||||
s.dao.GetX(ctx, "domain", domain, e)
|
||||
pg.GetX(ctx, s.db, "domain", domain, e)
|
||||
if e.Domain == domain {
|
||||
return &systemv3.Idp{}, fmt.Errorf("DUPLICATE DOMAIN")
|
||||
}
|
||||
@@ -181,7 +176,7 @@ func (s *idpService) Create(ctx context.Context, idp *systemv3.Idp) (*systemv3.I
|
||||
entity.SpCert = spcert
|
||||
entity.SpKey = spkey
|
||||
}
|
||||
_, err = s.dao.Create(ctx, entity)
|
||||
_, err = pg.Create(ctx, s.db, entity)
|
||||
if err != nil {
|
||||
return &systemv3.Idp{}, err
|
||||
}
|
||||
@@ -219,8 +214,8 @@ func (s *idpService) GetByID(ctx context.Context, idp *systemv3.Idp) (*systemv3.
|
||||
return &systemv3.Idp{}, err
|
||||
}
|
||||
entity := &models.Idp{}
|
||||
// TODO: Check for existance of id before GetByID
|
||||
_, err = s.dao.GetByID(ctx, id, entity)
|
||||
// TODO: Check for existence of id before GetByID
|
||||
_, err = pg.GetByID(ctx, s.db, id, entity)
|
||||
if err != nil {
|
||||
return &systemv3.Idp{}, err
|
||||
}
|
||||
@@ -261,7 +256,7 @@ func (s *idpService) GetByName(ctx context.Context, idp *systemv3.Idp) (*systemv
|
||||
return &systemv3.Idp{}, status.Error(codes.InvalidArgument, "EMPTY NAME")
|
||||
}
|
||||
entity := &models.Idp{}
|
||||
_, err := s.dao.GetByName(ctx, name, entity)
|
||||
_, err := pg.GetByName(ctx, s.db, name, entity)
|
||||
if err != nil {
|
||||
return &systemv3.Idp{}, err
|
||||
}
|
||||
@@ -307,14 +302,14 @@ func (s *idpService) Update(ctx context.Context, idp *systemv3.Idp) (*systemv3.I
|
||||
return &systemv3.Idp{}, status.Error(codes.InvalidArgument, "EMPTY DOMAIN")
|
||||
}
|
||||
|
||||
_, err := s.dao.GetByName(ctx, name, existingIdp)
|
||||
_, err := pg.GetByName(ctx, s.db, name, existingIdp)
|
||||
if err != nil {
|
||||
// TODO: Handle both db and idp not exist errors
|
||||
// separately.
|
||||
return &systemv3.Idp{}, status.Errorf(codes.InvalidArgument, "IDP %q NOT EXIST", name)
|
||||
}
|
||||
|
||||
s.dao.GetX(ctx, "domain", domain, existingIdp)
|
||||
pg.GetX(ctx, s.db, "domain", domain, existingIdp)
|
||||
if existingIdp.Domain == domain {
|
||||
return &systemv3.Idp{}, status.Error(codes.InvalidArgument, "DUPLICATE DOMAIN")
|
||||
}
|
||||
@@ -357,7 +352,7 @@ func (s *idpService) Update(ctx context.Context, idp *systemv3.Idp) (*systemv3.I
|
||||
entity.SpKey = spkey
|
||||
}
|
||||
|
||||
_, err = s.dao.Update(ctx, existingIdp.Id, entity)
|
||||
_, err = pg.Update(ctx, s.db, existingIdp.Id, entity)
|
||||
if err != nil {
|
||||
return &systemv3.Idp{}, err
|
||||
}
|
||||
@@ -395,7 +390,7 @@ func (s *idpService) List(ctx context.Context) (*systemv3.IdpList, error) {
|
||||
orgID uuid.NullUUID
|
||||
parID uuid.NullUUID
|
||||
)
|
||||
_, err := s.dao.List(ctx, parID, orgID, &entities)
|
||||
_, err := pg.List(ctx, s.db, parID, orgID, &entities)
|
||||
if err != nil {
|
||||
return &systemv3.IdpList{}, err
|
||||
}
|
||||
@@ -448,12 +443,12 @@ func (s *idpService) Delete(ctx context.Context, idp *systemv3.Idp) error {
|
||||
return status.Error(codes.InvalidArgument, "EMPTY NAME")
|
||||
}
|
||||
|
||||
_, err := s.dao.GetByName(ctx, name, entity)
|
||||
_, err := pg.GetByName(ctx, s.db, name, entity)
|
||||
if err != nil {
|
||||
return status.Errorf(codes.InvalidArgument, "IDP %q NOT EXISTS", name)
|
||||
}
|
||||
|
||||
err = s.dao.Delete(ctx, entity.Id, &models.Idp{})
|
||||
err = pg.Delete(ctx, s.db, entity.Id, &models.Idp{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/RafaySystems/rcloud-base/internal/constants"
|
||||
"github.com/RafaySystems/rcloud-base/internal/dao"
|
||||
"github.com/RafaySystems/rcloud-base/internal/models"
|
||||
"github.com/RafaySystems/rcloud-base/internal/persistence/provider/pg"
|
||||
"github.com/RafaySystems/rcloud-base/proto/types/sentry"
|
||||
"github.com/google/uuid"
|
||||
"github.com/uptrace/bun"
|
||||
@@ -17,32 +16,22 @@ import (
|
||||
|
||||
// KubeconfigRevocation is the interface for bootstrap operations
|
||||
type KubeconfigRevocationService interface {
|
||||
Close() error
|
||||
Get(ctx context.Context, orgID string, accountID string, isSSOUser bool) (*sentry.KubeconfigRevocation, error)
|
||||
Patch(ctx context.Context, kr *sentry.KubeconfigRevocation) error
|
||||
}
|
||||
|
||||
// bootstrapService implements BootstrapService
|
||||
type kubeconfigRevocationService struct {
|
||||
dao pg.EntityDAO
|
||||
kdao dao.KubeconfigDao
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
// NewKubeconfigRevocation return new kubeconfig revocation service
|
||||
func NewKubeconfigRevocationService(db *bun.DB) KubeconfigRevocationService {
|
||||
edao := pg.NewEntityDAO(db)
|
||||
return &kubeconfigRevocationService{
|
||||
dao: edao,
|
||||
kdao: dao.NewKubeconfigDao(edao),
|
||||
}
|
||||
}
|
||||
|
||||
func (krs *kubeconfigRevocationService) Close() error {
|
||||
return krs.dao.Close()
|
||||
return &kubeconfigRevocationService{db}
|
||||
}
|
||||
|
||||
func (krs *kubeconfigRevocationService) Get(ctx context.Context, orgID string, accountID string, isSSOUser bool) (*sentry.KubeconfigRevocation, error) {
|
||||
kr, err := krs.kdao.GetKubeconfigRevocation(ctx, uuid.MustParse(orgID), uuid.MustParse(accountID), isSSOUser)
|
||||
kr, err := dao.GetKubeconfigRevocation(ctx, krs.db, uuid.MustParse(orgID), uuid.MustParse(accountID), isSSOUser)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, constants.ErrNotFound
|
||||
} else if err != nil {
|
||||
@@ -63,14 +52,14 @@ func prepareKubeCfgRevocationResponse(kr *models.KubeconfigRevocation) *sentry.K
|
||||
}
|
||||
|
||||
func (krs *kubeconfigRevocationService) Patch(ctx context.Context, kr *sentry.KubeconfigRevocation) error {
|
||||
err := krs.dao.GetInstance().RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error {
|
||||
_, err := krs.kdao.GetKubeconfigRevocation(ctx, uuid.MustParse(kr.OrganizationID), uuid.MustParse(kr.AccountID), kr.IsSSOUser)
|
||||
err := krs.db.RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error {
|
||||
_, err := dao.GetKubeconfigRevocation(ctx, krs.db, uuid.MustParse(kr.OrganizationID), uuid.MustParse(kr.AccountID), kr.IsSSOUser)
|
||||
if err != nil && err == sql.ErrNoRows {
|
||||
kcr := convertToModel(kr)
|
||||
kcr.CreatedAt = time.Now()
|
||||
return krs.kdao.CreateKubeconfigRevocation(ctx, kcr)
|
||||
return dao.CreateKubeconfigRevocation(ctx, krs.db, kcr)
|
||||
}
|
||||
return krs.kdao.UpdateKubeconfigRevocation(ctx, convertToModel(kr))
|
||||
return dao.UpdateKubeconfigRevocation(ctx, krs.db, convertToModel(kr))
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ func TestGetKubeconfigRevocation(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewKubeconfigRevocationService(db)
|
||||
defer ps.Close()
|
||||
|
||||
ouuid := uuid.New().String()
|
||||
cuuid := uuid.New().String()
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/RafaySystems/rcloud-base/internal/constants"
|
||||
"github.com/RafaySystems/rcloud-base/internal/dao"
|
||||
"github.com/RafaySystems/rcloud-base/internal/models"
|
||||
"github.com/RafaySystems/rcloud-base/internal/persistence/provider/pg"
|
||||
"github.com/RafaySystems/rcloud-base/proto/types/sentry"
|
||||
"github.com/google/uuid"
|
||||
"github.com/uptrace/bun"
|
||||
@@ -17,28 +16,18 @@ import (
|
||||
|
||||
// KubeconfigSettingService is the interface for kube config setting operations
|
||||
type KubeconfigSettingService interface {
|
||||
Close() error
|
||||
Get(ctx context.Context, orgID string, accountID string, isSSO bool) (*sentry.KubeconfigSetting, error)
|
||||
Patch(ctx context.Context, ks *sentry.KubeconfigSetting) error
|
||||
}
|
||||
|
||||
// kubeconfigSettingService implements KubeconfigSettingService
|
||||
type kubeconfigSettingService struct {
|
||||
dao pg.EntityDAO
|
||||
kdao dao.KubeconfigDao
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
// NewKubeconfigSettingService return new kubeconfig setting service
|
||||
func NewKubeconfigSettingService(db *bun.DB) KubeconfigSettingService {
|
||||
edao := pg.NewEntityDAO(db)
|
||||
return &kubeconfigSettingService{
|
||||
dao: edao,
|
||||
kdao: dao.NewKubeconfigDao(edao),
|
||||
}
|
||||
}
|
||||
|
||||
func (krs *kubeconfigSettingService) Close() error {
|
||||
return krs.dao.Close()
|
||||
return &kubeconfigSettingService{db}
|
||||
}
|
||||
|
||||
func (kss *kubeconfigSettingService) Get(ctx context.Context, orgID string, accountID string, isSSO bool) (*sentry.KubeconfigSetting, error) {
|
||||
@@ -51,7 +40,7 @@ func (kss *kubeconfigSettingService) Get(ctx context.Context, orgID string, acco
|
||||
_log.Info("account identifier is empty")
|
||||
}
|
||||
|
||||
kr, err := kss.kdao.GetKubeconfigSetting(ctx, oid, aid, isSSO)
|
||||
kr, err := dao.GetKubeconfigSetting(ctx, kss.db, oid, aid, isSSO)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, constants.ErrNotFound
|
||||
} else if err != nil {
|
||||
@@ -65,15 +54,15 @@ func (kss *kubeconfigSettingService) Patch(ctx context.Context, ks *sentry.Kubec
|
||||
if err != nil {
|
||||
accId = uuid.Nil
|
||||
}
|
||||
err = kss.dao.GetInstance().RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error {
|
||||
_, err := kss.kdao.GetKubeconfigSetting(ctx, uuid.MustParse(ks.OrganizationID), accId, ks.IsSSOUser)
|
||||
err = kss.db.RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error {
|
||||
_, err := dao.GetKubeconfigSetting(ctx, kss.db, uuid.MustParse(ks.OrganizationID), accId, ks.IsSSOUser)
|
||||
db := convertToKubeCfgSettingModel(ks)
|
||||
if err != nil && err == sql.ErrNoRows {
|
||||
db.CreatedAt = time.Now()
|
||||
return kss.kdao.CreateKubeconfigSetting(ctx, convertToKubeCfgSettingModel(ks))
|
||||
return dao.CreateKubeconfigSetting(ctx, kss.db, convertToKubeCfgSettingModel(ks))
|
||||
}
|
||||
db.ModifiedAt = time.Now()
|
||||
return kss.kdao.UpdateKubeconfigSetting(ctx, convertToKubeCfgSettingModel(ks))
|
||||
return dao.UpdateKubeconfigSetting(ctx, kss.db, convertToKubeCfgSettingModel(ks))
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/RafaySystems/rcloud-base/internal/constants"
|
||||
"github.com/RafaySystems/rcloud-base/internal/dao"
|
||||
"github.com/RafaySystems/rcloud-base/internal/models"
|
||||
"github.com/RafaySystems/rcloud-base/internal/persistence/provider/pg"
|
||||
"github.com/RafaySystems/rcloud-base/proto/types/sentry"
|
||||
"github.com/google/uuid"
|
||||
"github.com/uptrace/bun"
|
||||
@@ -17,32 +16,22 @@ import (
|
||||
|
||||
// KubectlClusterSettingsService is the interface for kubectl cluster setting operations
|
||||
type KubectlClusterSettingsService interface {
|
||||
Close() error
|
||||
Get(ctx context.Context, orgID string, clusterID string) (*sentry.KubectlClusterSettings, error)
|
||||
Patch(ctx context.Context, kc *sentry.KubectlClusterSettings) error
|
||||
}
|
||||
|
||||
// kubectlClusterSettingsService implements KubectlClusterSettingsService
|
||||
type kubectlClusterSettingsService struct {
|
||||
dao pg.EntityDAO
|
||||
kdao dao.KubeconfigDao
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
// NewKubectlClusterSettingsService return new kubectl cluster setting service
|
||||
func NewkubectlClusterSettingsService(db *bun.DB) KubectlClusterSettingsService {
|
||||
edao := pg.NewEntityDAO(db)
|
||||
return &kubectlClusterSettingsService{
|
||||
dao: edao,
|
||||
kdao: dao.NewKubeconfigDao(edao),
|
||||
}
|
||||
}
|
||||
|
||||
func (kcs *kubectlClusterSettingsService) Close() error {
|
||||
return kcs.dao.Close()
|
||||
return &kubectlClusterSettingsService{db}
|
||||
}
|
||||
|
||||
func (kcs *kubectlClusterSettingsService) Get(ctx context.Context, orgID string, clusterID string) (*sentry.KubectlClusterSettings, error) {
|
||||
kc, err := kcs.kdao.GetkubectlClusterSettings(ctx, uuid.MustParse(orgID), clusterID)
|
||||
kc, err := dao.GetkubectlClusterSettings(ctx, kcs.db, uuid.MustParse(orgID), clusterID)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, constants.ErrNotFound
|
||||
} else if err != nil {
|
||||
@@ -52,19 +41,19 @@ func (kcs *kubectlClusterSettingsService) Get(ctx context.Context, orgID string,
|
||||
}
|
||||
|
||||
func (kcs *kubectlClusterSettingsService) Patch(ctx context.Context, kc *sentry.KubectlClusterSettings) error {
|
||||
err := kcs.dao.GetInstance().RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error {
|
||||
_, err := kcs.kdao.GetkubectlClusterSettings(ctx, uuid.MustParse(kc.OrganizationID), kc.Name)
|
||||
err := kcs.db.RunInTx(ctx, &sql.TxOptions{}, func(ctx context.Context, tx bun.Tx) error {
|
||||
_, err := dao.GetkubectlClusterSettings(ctx, kcs.db, uuid.MustParse(kc.OrganizationID), kc.Name)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
kcsdb := convertToKubeCtlSettingModel(kc)
|
||||
kcsdb.CreatedAt = time.Now()
|
||||
kcs.kdao.CreatekubectlClusterSettings(ctx, kcsdb)
|
||||
dao.CreatekubectlClusterSettings(ctx, kcs.db, kcsdb)
|
||||
}
|
||||
return err
|
||||
}
|
||||
kcsdb := convertToKubeCtlSettingModel(kc)
|
||||
kcsdb.ModifiedAt = time.Now()
|
||||
return kcs.kdao.UpdatekubectlClusterSettings(ctx, kcsdb)
|
||||
return dao.UpdatekubectlClusterSettings(ctx, kcs.db, kcsdb)
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ func TestGetKubectlSetting(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewkubectlClusterSettingsService(db)
|
||||
defer ps.Close()
|
||||
|
||||
ouuid := uuid.New().String()
|
||||
cuuid := uuid.New().String()
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
|
||||
// MetroService is the interface for metro operations
|
||||
type MetroService interface {
|
||||
Close() error
|
||||
// create metro
|
||||
Create(ctx context.Context, metro *infrav3.Location) (*infrav3.Location, error)
|
||||
// get metro by id
|
||||
@@ -34,20 +33,18 @@ type MetroService interface {
|
||||
|
||||
// metroService implements MetroService
|
||||
type metroService struct {
|
||||
dao pg.EntityDAO
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
// NewProjectService return new project service
|
||||
func NewMetroService(db *bun.DB) MetroService {
|
||||
return &metroService{
|
||||
dao: pg.NewEntityDAO(db),
|
||||
}
|
||||
return &metroService{db}
|
||||
}
|
||||
|
||||
func (s *metroService) Create(ctx context.Context, metro *infrav3.Location) (*infrav3.Location, error) {
|
||||
|
||||
var part models.Partner
|
||||
_, err := s.dao.GetByName(ctx, metro.Metadata.Partner, &part)
|
||||
_, err := pg.GetByName(ctx, s.db, metro.Metadata.Partner, &part)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -68,7 +65,7 @@ func (s *metroService) Create(ctx context.Context, metro *infrav3.Location) (*in
|
||||
OrganizationId: uuid.Nil,
|
||||
PartnerId: part.ID,
|
||||
}
|
||||
_, err = s.dao.Create(ctx, &metrodb)
|
||||
_, err = pg.Create(ctx, s.db, &metrodb)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -81,7 +78,7 @@ func (s *metroService) GetByName(ctx context.Context, name string) (*infrav3.Loc
|
||||
|
||||
var metro infrav3.Location
|
||||
|
||||
entity, err := s.dao.GetByName(ctx, name, &models.Metro{})
|
||||
entity, err := pg.GetByName(ctx, s.db, name, &models.Metro{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -112,7 +109,7 @@ func (s *metroService) GetByName(ctx context.Context, name string) (*infrav3.Loc
|
||||
func (s *metroService) GetById(ctx context.Context, id uuid.UUID) (*infrav3.Location, error) {
|
||||
var location infrav3.Location
|
||||
|
||||
entity, err := s.dao.GetByID(ctx, id, &models.Metro{})
|
||||
entity, err := pg.GetByID(ctx, s.db, id, &models.Metro{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -144,7 +141,7 @@ func (s *metroService) GetById(ctx context.Context, id uuid.UUID) (*infrav3.Loca
|
||||
|
||||
func (s *metroService) Update(ctx context.Context, metro *infrav3.Location) (*infrav3.Location, error) {
|
||||
|
||||
entity, err := s.dao.GetByName(ctx, metro.Metadata.Name, &models.Metro{})
|
||||
entity, err := pg.GetByName(ctx, s.db, metro.Metadata.Name, &models.Metro{})
|
||||
if err != nil {
|
||||
return metro, err
|
||||
}
|
||||
@@ -160,7 +157,7 @@ func (s *metroService) Update(ctx context.Context, metro *infrav3.Location) (*in
|
||||
metrodb.Longitude = metro.Spec.Longitude
|
||||
metrodb.ModifiedAt = time.Now()
|
||||
|
||||
_, err = s.dao.Update(ctx, metrodb.ID, metrodb)
|
||||
_, err = pg.Update(ctx, s.db, metrodb.ID, metrodb)
|
||||
if err != nil {
|
||||
return metro, err
|
||||
}
|
||||
@@ -171,12 +168,12 @@ func (s *metroService) Update(ctx context.Context, metro *infrav3.Location) (*in
|
||||
|
||||
func (s *metroService) Delete(ctx context.Context, metro *infrav3.Location) (*infrav3.Location, error) {
|
||||
|
||||
entity, err := s.dao.GetByName(ctx, metro.Metadata.Name, &models.Metro{})
|
||||
entity, err := pg.GetByName(ctx, s.db, metro.Metadata.Name, &models.Metro{})
|
||||
if err != nil {
|
||||
return metro, err
|
||||
}
|
||||
if metrodb, ok := entity.(*models.Metro); ok {
|
||||
err = s.dao.Delete(ctx, metrodb.ID, metrodb)
|
||||
err = pg.Delete(ctx, s.db, metrodb.ID, metrodb)
|
||||
if err != nil {
|
||||
return metro, err
|
||||
}
|
||||
@@ -191,12 +188,12 @@ func (s *metroService) List(ctx context.Context, partner string) (*infrav3.Locat
|
||||
var metrodbs []models.Metro
|
||||
|
||||
var part models.Partner
|
||||
_, err := s.dao.GetByName(ctx, partner, &part)
|
||||
_, err := pg.GetByName(ctx, s.db, partner, &part)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
entities, err := s.dao.List(ctx, uuid.NullUUID{UUID: part.ID, Valid: true}, uuid.NullUUID{UUID: uuid.Nil, Valid: false}, &metrodbs)
|
||||
entities, err := pg.List(ctx, s.db, uuid.NullUUID{UUID: part.ID, Valid: true}, uuid.NullUUID{UUID: uuid.Nil, Valid: false}, &metrodbs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -229,7 +226,7 @@ func (s *metroService) List(ctx context.Context, partner string) (*infrav3.Locat
|
||||
}
|
||||
|
||||
func (s *metroService) GetIDByName(ctx context.Context, name string) (uuid.UUID, error) {
|
||||
entity, err := s.dao.GetByName(ctx, name, &models.Metro{})
|
||||
entity, err := pg.GetByName(ctx, s.db, name, &models.Metro{})
|
||||
if err != nil {
|
||||
return uuid.Nil, err
|
||||
}
|
||||
@@ -239,7 +236,3 @@ func (s *metroService) GetIDByName(ctx context.Context, name string) (uuid.UUID,
|
||||
}
|
||||
return uuid.Nil, nil
|
||||
}
|
||||
|
||||
func (s *metroService) Close() error {
|
||||
return s.dao.Close()
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ func TestCreateMetro(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewMetroService(db)
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
muuid := uuid.New().String()
|
||||
@@ -49,7 +48,6 @@ func TestCreateMetroDuplicate(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
gs := NewMetroService(db)
|
||||
defer gs.Close()
|
||||
|
||||
muuid := uuid.New().String()
|
||||
|
||||
@@ -72,7 +70,6 @@ func TestMetroDelete(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewMetroService(db)
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
|
||||
@@ -97,7 +94,6 @@ func TestMetroDeleteNonExist(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewMetroService(db)
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
|
||||
@@ -119,7 +115,6 @@ func TestMetroGetByName(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewMetroService(db)
|
||||
defer ps.Close()
|
||||
|
||||
muuid := uuid.New().String()
|
||||
|
||||
@@ -142,7 +137,6 @@ func TestMetroUpdate(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewMetroService(db)
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"github.com/RafaySystems/rcloud-base/internal/cluster/dao"
|
||||
"github.com/RafaySystems/rcloud-base/internal/models"
|
||||
"github.com/RafaySystems/rcloud-base/pkg/converter"
|
||||
"github.com/RafaySystems/rcloud-base/pkg/patch"
|
||||
@@ -17,7 +18,7 @@ import (
|
||||
|
||||
func (s *clusterService) GetNamespacesForConditions(ctx context.Context, conditions []scheduler.ClusterNamespaceCondition, clusterID string) (*scheduler.ClusterNamespaceList, error) {
|
||||
|
||||
cns, count, err := s.cndao.GetNamespacesForConditions(ctx, uuid.MustParse(clusterID), conditions)
|
||||
cns, count, err := dao.GetNamespacesForConditions(ctx, s.db, uuid.MustParse(clusterID), conditions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -65,7 +66,7 @@ func (s *clusterService) GetNamespacesForConditions(ctx context.Context, conditi
|
||||
|
||||
func (s *clusterService) GetNamespaces(ctx context.Context, clusterID string) (*scheduler.ClusterNamespaceList, error) {
|
||||
|
||||
cns, err := s.cndao.GetNamespaces(ctx, uuid.MustParse(clusterID))
|
||||
cns, err := dao.GetNamespaces(ctx, s.db, uuid.MustParse(clusterID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -113,7 +114,7 @@ func (s *clusterService) GetNamespaces(ctx context.Context, clusterID string) (*
|
||||
|
||||
func (s *clusterService) GetNamespace(ctx context.Context, namespace string, clusterID string) (*scheduler.ClusterNamespace, error) {
|
||||
|
||||
cn, err := s.cndao.GetNamespace(ctx, uuid.MustParse(clusterID), namespace)
|
||||
cn, err := dao.GetNamespace(ctx, s.db, uuid.MustParse(clusterID), namespace)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -173,7 +174,7 @@ func (s *clusterService) UpdateNamespaceStatus(ctx context.Context, current *sch
|
||||
Status: converter.ConvertToJsonRawMessage(existing.Status),
|
||||
}
|
||||
|
||||
err = s.cndao.UpdateNamespaceStatus(ctx, &cn)
|
||||
err = dao.UpdateNamespaceStatus(ctx, s.db, &cn)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -192,6 +193,6 @@ func (s *clusterService) UpdateNamespaceStatus(ctx context.Context, current *sch
|
||||
}
|
||||
|
||||
func (s *clusterService) GetNamespaceHashes(ctx context.Context, clusterID string) ([]infrav3.NameHash, error) {
|
||||
nameHashes, err := s.cndao.GetNamespaceHashes(ctx, uuid.MustParse(clusterID))
|
||||
nameHashes, err := dao.GetNamespaceHashes(ctx, s.db, uuid.MustParse(clusterID))
|
||||
return nameHashes, err
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
"github.com/RafaySystems/rcloud-base/internal/models"
|
||||
"github.com/RafaySystems/rcloud-base/internal/persistence/provider/pg"
|
||||
"github.com/RafaySystems/rcloud-base/internal/utils"
|
||||
commonv3 "github.com/RafaySystems/rcloud-base/proto/types/commonpb/v3"
|
||||
systemv3 "github.com/RafaySystems/rcloud-base/proto/types/systempb/v3"
|
||||
"github.com/google/uuid"
|
||||
@@ -30,17 +29,12 @@ type OIDCProviderService interface {
|
||||
}
|
||||
|
||||
type oidcProvider struct {
|
||||
dao pg.EntityDAO
|
||||
db *bun.DB
|
||||
kratosUrl string
|
||||
l utils.Lookup
|
||||
}
|
||||
|
||||
func NewOIDCProviderService(db *bun.DB, kratosUrl string) OIDCProviderService {
|
||||
return &oidcProvider{
|
||||
dao: pg.NewEntityDAO(db),
|
||||
kratosUrl: kratosUrl,
|
||||
l: utils.NewLookup(db),
|
||||
}
|
||||
return &oidcProvider{db: db, kratosUrl: kratosUrl}
|
||||
}
|
||||
|
||||
func generateCallbackUrl(id string, kUrl string) string {
|
||||
@@ -56,11 +50,11 @@ func validateURL(rawURL string) error {
|
||||
func (s *oidcProvider) getPartnerOrganization(ctx context.Context, provider *systemv3.OIDCProvider) (uuid.UUID, uuid.UUID, error) {
|
||||
partner := provider.GetMetadata().GetPartner()
|
||||
org := provider.GetMetadata().GetOrganization()
|
||||
partnerId, err := s.l.GetPartnerId(ctx, partner)
|
||||
partnerId, err := pg.GetPartnerId(ctx, s.db, partner)
|
||||
if err != nil {
|
||||
return uuid.Nil, uuid.Nil, err
|
||||
}
|
||||
organizationId, err := s.l.GetOrganizationId(ctx, org)
|
||||
organizationId, err := pg.GetOrganizationId(ctx, s.db, org)
|
||||
if err != nil {
|
||||
return partnerId, uuid.Nil, err
|
||||
}
|
||||
@@ -81,8 +75,9 @@ func (s *oidcProvider) Create(ctx context.Context, provider *systemv3.OIDCProvid
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get partner and org id")
|
||||
}
|
||||
p, _ := s.dao.GetIdByNamePartnerOrg(
|
||||
p, _ := pg.GetIdByNamePartnerOrg(
|
||||
ctx,
|
||||
s.db,
|
||||
provider.GetMetadata().GetName(),
|
||||
uuid.NullUUID{UUID: partnerId, Valid: true},
|
||||
uuid.NullUUID{UUID: organizationId, Valid: true},
|
||||
@@ -129,7 +124,7 @@ func (s *oidcProvider) Create(ctx context.Context, provider *systemv3.OIDCProvid
|
||||
RequestedClaims: provider.Spec.GetRequestedClaims().AsMap(),
|
||||
Predefined: provider.Spec.GetPredefined(),
|
||||
}
|
||||
_, err = s.dao.Create(ctx, entity)
|
||||
_, err = pg.Create(ctx, s.db, entity)
|
||||
if err != nil {
|
||||
return &systemv3.OIDCProvider{}, err
|
||||
}
|
||||
@@ -167,7 +162,7 @@ func (s *oidcProvider) GetByID(ctx context.Context, provider *systemv3.OIDCProvi
|
||||
}
|
||||
|
||||
entity := &models.OIDCProvider{}
|
||||
_, err = s.dao.GetByID(ctx, id, entity)
|
||||
_, err = pg.GetByID(ctx, s.db, id, entity)
|
||||
// TODO: Return proper error for Id not exist
|
||||
if err != nil {
|
||||
return &systemv3.OIDCProvider{}, err
|
||||
@@ -206,7 +201,7 @@ func (s *oidcProvider) GetByName(ctx context.Context, provider *systemv3.OIDCPro
|
||||
}
|
||||
|
||||
entity := &models.OIDCProvider{}
|
||||
_, err := s.dao.GetByName(ctx, name, entity)
|
||||
_, err := pg.GetByName(ctx, s.db, name, entity)
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
@@ -251,7 +246,7 @@ func (s *oidcProvider) List(ctx context.Context) (*systemv3.OIDCProviderList, er
|
||||
orgID uuid.NullUUID
|
||||
parID uuid.NullUUID
|
||||
)
|
||||
_, err := s.dao.List(ctx, parID, orgID, &entities)
|
||||
_, err := pg.List(ctx, s.db, parID, orgID, &entities)
|
||||
if err != nil {
|
||||
return &systemv3.OIDCProviderList{}, nil
|
||||
}
|
||||
@@ -307,7 +302,7 @@ func (s *oidcProvider) Update(ctx context.Context, provider *systemv3.OIDCProvid
|
||||
}
|
||||
|
||||
existingP := &models.OIDCProvider{}
|
||||
_, err = s.dao.GetByName(ctx, name, existingP)
|
||||
_, err = pg.GetByName(ctx, s.db, name, existingP)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return &systemv3.OIDCProvider{}, status.Errorf(codes.InvalidArgument, "OIDC PROVIDER %q NOT EXIST", name)
|
||||
@@ -352,7 +347,7 @@ func (s *oidcProvider) Update(ctx context.Context, provider *systemv3.OIDCProvid
|
||||
RequestedClaims: provider.Spec.GetRequestedClaims().AsMap(),
|
||||
Predefined: provider.Spec.GetPredefined(),
|
||||
}
|
||||
_, err = s.dao.Update(ctx, existingP.Id, entity)
|
||||
_, err = pg.Update(ctx, s.db, existingP.Id, entity)
|
||||
if err != nil {
|
||||
return &systemv3.OIDCProvider{}, err
|
||||
}
|
||||
@@ -389,12 +384,12 @@ func (s *oidcProvider) Delete(ctx context.Context, provider *systemv3.OIDCProvid
|
||||
if len(name) == 0 {
|
||||
return status.Error(codes.InvalidArgument, "EMPTY NAME")
|
||||
}
|
||||
_, err := s.dao.GetByName(ctx, name, entity)
|
||||
_, err := pg.GetByName(ctx, s.db, name, entity)
|
||||
if err != nil {
|
||||
return status.Errorf(codes.InvalidArgument, "OIDC PROVIDER %q NOT EXIST", name)
|
||||
}
|
||||
|
||||
err = s.dao.Delete(ctx, entity.Id, &models.OIDCProvider{})
|
||||
err = pg.Delete(ctx, s.db, entity.Id, &models.OIDCProvider{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ const (
|
||||
|
||||
// OrganizationService is the interface for organization operations
|
||||
type OrganizationService interface {
|
||||
Close() error
|
||||
// create organization
|
||||
Create(ctx context.Context, organization *systemv3.Organization) (*systemv3.Organization, error)
|
||||
// get organization by id
|
||||
@@ -39,20 +38,18 @@ type OrganizationService interface {
|
||||
|
||||
// organizationService implements OrganizationService
|
||||
type organizationService struct {
|
||||
dao pg.EntityDAO
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
// NewOrganizationService return new organization service
|
||||
func NewOrganizationService(db *bun.DB) OrganizationService {
|
||||
return &organizationService{
|
||||
dao: pg.NewEntityDAO(db),
|
||||
}
|
||||
return &organizationService{db}
|
||||
}
|
||||
|
||||
func (s *organizationService) Create(ctx context.Context, org *systemv3.Organization) (*systemv3.Organization, error) {
|
||||
|
||||
var partner models.Partner
|
||||
_, err := s.dao.GetByName(ctx, org.Metadata.Partner, &partner)
|
||||
_, err := pg.GetByName(ctx, s.db, org.Metadata.Partner, &partner)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -99,7 +96,7 @@ func (s *organizationService) Create(ctx context.Context, org *systemv3.Organiza
|
||||
CreatedAt: time.Now(),
|
||||
ModifiedAt: time.Now(),
|
||||
}
|
||||
entity, err := s.dao.Create(ctx, &organization)
|
||||
entity, err := pg.Create(ctx, s.db, &organization)
|
||||
if err != nil {
|
||||
org.Status = &v3.Status{
|
||||
ConditionType: "Create",
|
||||
@@ -143,7 +140,7 @@ func (s *organizationService) GetByID(ctx context.Context, id string) (*systemv3
|
||||
}
|
||||
return organization, err
|
||||
}
|
||||
entity, err := s.dao.GetByID(ctx, uid, &models.Organization{})
|
||||
entity, err := pg.GetByID(ctx, s.db, uid, &models.Organization{})
|
||||
if err != nil {
|
||||
organization.Status = &v3.Status{
|
||||
ConditionType: "Describe",
|
||||
@@ -156,7 +153,7 @@ func (s *organizationService) GetByID(ctx context.Context, id string) (*systemv3
|
||||
if org, ok := entity.(*models.Organization); ok {
|
||||
|
||||
var partner models.Partner
|
||||
_, err := s.dao.GetByID(ctx, org.PartnerId, &partner)
|
||||
_, err := pg.GetByID(ctx, s.db, org.PartnerId, &partner)
|
||||
if err != nil {
|
||||
organization.Status = &v3.Status{
|
||||
ConditionType: "Describe",
|
||||
@@ -206,7 +203,7 @@ func (s *organizationService) GetByName(ctx context.Context, name string) (*syst
|
||||
Name: name,
|
||||
},
|
||||
}
|
||||
entity, err := s.dao.GetByName(ctx, name, &models.Organization{})
|
||||
entity, err := pg.GetByName(ctx, s.db, name, &models.Organization{})
|
||||
if err != nil {
|
||||
organization.Metadata = &v3.Metadata{
|
||||
Name: name,
|
||||
@@ -223,7 +220,7 @@ func (s *organizationService) GetByName(ctx context.Context, name string) (*syst
|
||||
if org, ok := entity.(*models.Organization); ok {
|
||||
|
||||
var partner models.Partner
|
||||
_, err := s.dao.GetByID(ctx, org.PartnerId, &partner)
|
||||
_, err := pg.GetByID(ctx, s.db, org.PartnerId, &partner)
|
||||
if err != nil {
|
||||
organization.Metadata = &v3.Metadata{
|
||||
Name: name,
|
||||
@@ -254,7 +251,7 @@ func (s *organizationService) GetByName(ctx context.Context, name string) (*syst
|
||||
|
||||
func (s *organizationService) Update(ctx context.Context, organization *systemv3.Organization) (*systemv3.Organization, error) {
|
||||
|
||||
entity, err := s.dao.GetByName(ctx, organization.Metadata.Name, &models.Organization{})
|
||||
entity, err := pg.GetByName(ctx, s.db, organization.Metadata.Name, &models.Organization{})
|
||||
if err != nil {
|
||||
organization.Status = &v3.Status{
|
||||
ConditionType: "Update",
|
||||
@@ -298,7 +295,7 @@ func (s *organizationService) Update(ctx context.Context, organization *systemv3
|
||||
org.IsTOTPEnabled = organization.GetSpec().GetIsTotpEnabled()
|
||||
org.AreClustersShared = organization.GetSpec().GetAreClustersShared()
|
||||
|
||||
_, err = s.dao.Update(ctx, org.ID, org)
|
||||
_, err = pg.Update(ctx, s.db, org.ID, org)
|
||||
if err != nil {
|
||||
organization.Status = &v3.Status{
|
||||
ConditionType: "Update",
|
||||
@@ -324,7 +321,7 @@ func (s *organizationService) Update(ctx context.Context, organization *systemv3
|
||||
|
||||
func (s *organizationService) Delete(ctx context.Context, organization *systemv3.Organization) (*systemv3.Organization, error) {
|
||||
|
||||
entity, err := s.dao.GetByName(ctx, organization.Metadata.Name, &models.Organization{})
|
||||
entity, err := pg.GetByName(ctx, s.db, organization.Metadata.Name, &models.Organization{})
|
||||
if err != nil {
|
||||
organization.Status = &v3.Status{
|
||||
ConditionType: "Delete",
|
||||
@@ -337,7 +334,7 @@ func (s *organizationService) Delete(ctx context.Context, organization *systemv3
|
||||
|
||||
if org, ok := entity.(*models.Organization); ok {
|
||||
org.Trash = true
|
||||
_, err := s.dao.Update(ctx, org.ID, org)
|
||||
_, err := pg.Update(ctx, s.db, org.ID, org)
|
||||
if err != nil {
|
||||
organization.Status = &v3.Status{
|
||||
ConditionType: "Delete",
|
||||
@@ -372,13 +369,13 @@ func (s *organizationService) List(ctx context.Context, organization *systemv3.O
|
||||
}
|
||||
if len(organization.Metadata.Partner) > 0 {
|
||||
var partner models.Partner
|
||||
_, err := s.dao.GetByName(ctx, organization.Metadata.Partner, &partner)
|
||||
_, err := pg.GetByName(ctx, s.db, organization.Metadata.Partner, &partner)
|
||||
if err != nil {
|
||||
return organinzationList, err
|
||||
}
|
||||
|
||||
var orgs []models.Organization
|
||||
entities, err := s.dao.List(ctx, uuid.NullUUID{UUID: partner.ID, Valid: true}, uuid.NullUUID{UUID: uuid.Nil}, &orgs)
|
||||
entities, err := pg.List(ctx, s.db, uuid.NullUUID{UUID: partner.ID, Valid: true}, uuid.NullUUID{UUID: uuid.Nil}, &orgs)
|
||||
if err != nil {
|
||||
return organinzationList, err
|
||||
}
|
||||
@@ -470,7 +467,3 @@ func prepareOrganizationResponse(organization *systemv3.Organization, org *model
|
||||
|
||||
return organization, nil
|
||||
}
|
||||
|
||||
func (s *organizationService) Close() error {
|
||||
return s.dao.Close()
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ func TestCreateOrganization(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewOrganizationService(db)
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
ouuid := uuid.New().String()
|
||||
@@ -49,7 +48,6 @@ func TestCreateOrganizationDuplicate(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
gs := NewOrganizationService(db)
|
||||
defer gs.Close()
|
||||
|
||||
ouuid := uuid.New().String()
|
||||
|
||||
@@ -72,7 +70,6 @@ func TestOrganizationDelete(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewOrganizationService(db)
|
||||
defer ps.Close()
|
||||
|
||||
ouuid := uuid.New().String()
|
||||
|
||||
@@ -96,7 +93,6 @@ func TestOrganizationDeleteNonExist(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewOrganizationService(db)
|
||||
defer ps.Close()
|
||||
|
||||
ouuid := uuid.New().String()
|
||||
|
||||
@@ -117,7 +113,6 @@ func TestOrganizationGetByName(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewOrganizationService(db)
|
||||
defer ps.Close()
|
||||
|
||||
partuuid := uuid.New().String()
|
||||
ouuid := uuid.New().String()
|
||||
@@ -143,7 +138,6 @@ func TestOrganizationGetById(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewOrganizationService(db)
|
||||
defer ps.Close()
|
||||
|
||||
partuuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -169,7 +163,6 @@ func TestOrganizationUpdate(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewOrganizationService(db)
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
|
||||
// PartnerService is the interface for partner operations
|
||||
type PartnerService interface {
|
||||
Close() error
|
||||
// create partner
|
||||
Create(ctx context.Context, partner *systemv3.Partner) (*systemv3.Partner, error)
|
||||
// get partner by id
|
||||
@@ -31,14 +30,12 @@ type PartnerService interface {
|
||||
|
||||
// partnerService implements PartnerService
|
||||
type partnerService struct {
|
||||
dao pg.EntityDAO
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
// NewPartnerService return new partner service
|
||||
func NewPartnerService(db *bun.DB) PartnerService {
|
||||
return &partnerService{
|
||||
dao: pg.NewEntityDAO(db),
|
||||
}
|
||||
return &partnerService{db}
|
||||
}
|
||||
|
||||
func (s *partnerService) Create(ctx context.Context, partner *systemv3.Partner) (*systemv3.Partner, error) {
|
||||
@@ -68,7 +65,7 @@ func (s *partnerService) Create(ctx context.Context, partner *systemv3.Partner)
|
||||
CreatedAt: time.Now(),
|
||||
ModifiedAt: time.Now(),
|
||||
}
|
||||
entity, err := s.dao.Create(ctx, &part)
|
||||
entity, err := pg.Create(ctx, s.db, &part)
|
||||
if err != nil {
|
||||
partner.Status = &v3.Status{
|
||||
ConditionStatus: v3.ConditionStatus_StatusFailed,
|
||||
@@ -113,7 +110,7 @@ func (s *partnerService) GetByID(ctx context.Context, id string) (*systemv3.Part
|
||||
}
|
||||
return partner, err
|
||||
}
|
||||
entity, err := s.dao.GetByID(ctx, uid, &models.Partner{})
|
||||
entity, err := pg.GetByID(ctx, s.db, uid, &models.Partner{})
|
||||
if err != nil {
|
||||
partner.Status = &v3.Status{
|
||||
ConditionType: "Describe",
|
||||
@@ -182,7 +179,7 @@ func (s *partnerService) GetByName(ctx context.Context, name string) (*systemv3.
|
||||
},
|
||||
}
|
||||
|
||||
entity, err := s.dao.GetByName(ctx, name, &models.Partner{})
|
||||
entity, err := pg.GetByName(ctx, s.db, name, &models.Partner{})
|
||||
if err != nil {
|
||||
partner.Status = &v3.Status{
|
||||
ConditionType: "Describe",
|
||||
@@ -244,7 +241,7 @@ func (s *partnerService) GetByName(ctx context.Context, name string) (*systemv3.
|
||||
|
||||
func (s *partnerService) Update(ctx context.Context, partner *systemv3.Partner) (*systemv3.Partner, error) {
|
||||
|
||||
entity, err := s.dao.GetByName(ctx, partner.Metadata.Name, &models.Partner{})
|
||||
entity, err := pg.GetByName(ctx, s.db, partner.Metadata.Name, &models.Partner{})
|
||||
if err != nil {
|
||||
partner.Status = &v3.Status{
|
||||
ConditionStatus: v3.ConditionStatus_StatusFailed,
|
||||
@@ -278,7 +275,7 @@ func (s *partnerService) Update(ctx context.Context, partner *systemv3.Partner)
|
||||
part.ModifiedAt = time.Now()
|
||||
|
||||
//Update the partner details
|
||||
_, err = s.dao.Update(ctx, part.ID, part)
|
||||
_, err = pg.Update(ctx, s.db, part.ID, part)
|
||||
if err != nil {
|
||||
partner.Status = &v3.Status{
|
||||
ConditionStatus: v3.ConditionStatus_StatusFailed,
|
||||
@@ -301,7 +298,7 @@ func (s *partnerService) Update(ctx context.Context, partner *systemv3.Partner)
|
||||
}
|
||||
|
||||
func (s *partnerService) Delete(ctx context.Context, partner *systemv3.Partner) (*systemv3.Partner, error) {
|
||||
entity, err := s.dao.GetByName(ctx, partner.Metadata.Name, &models.Partner{})
|
||||
entity, err := pg.GetByName(ctx, s.db, partner.Metadata.Name, &models.Partner{})
|
||||
if err != nil {
|
||||
partner.Status = &v3.Status{
|
||||
ConditionType: "Delete",
|
||||
@@ -314,7 +311,7 @@ func (s *partnerService) Delete(ctx context.Context, partner *systemv3.Partner)
|
||||
|
||||
if part, ok := entity.(*models.Partner); ok {
|
||||
part.Trash = true
|
||||
_, err := s.dao.Update(ctx, part.ID, part)
|
||||
_, err := pg.Update(ctx, s.db, part.ID, part)
|
||||
if err != nil {
|
||||
partner.Status = &v3.Status{
|
||||
ConditionType: "Delete",
|
||||
@@ -338,7 +335,3 @@ func (s *partnerService) Delete(ctx context.Context, partner *systemv3.Partner)
|
||||
return partner, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *partnerService) Close() error {
|
||||
return s.dao.Close()
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ func TestCreatePartner(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewPartnerService(db)
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
|
||||
@@ -61,7 +60,6 @@ func TestCreatePartnerDuplicate(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
gs := NewPartnerService(db)
|
||||
defer gs.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
|
||||
@@ -84,7 +82,6 @@ func TestPartnerDelete(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewPartnerService(db)
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
|
||||
@@ -108,7 +105,6 @@ func TestPartnerDeleteNonExist(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
gs := NewPartnerService(db)
|
||||
defer gs.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
|
||||
@@ -129,7 +125,6 @@ func TestPartnerGetByName(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewPartnerService(db)
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
|
||||
@@ -150,7 +145,6 @@ func TestPartnerGetById(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewPartnerService(db)
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
|
||||
@@ -172,7 +166,6 @@ func TestPartnerUpdate(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewPartnerService(db)
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ const (
|
||||
|
||||
// ProjectService is the interface for project operations
|
||||
type ProjectService interface {
|
||||
Close() error
|
||||
// create project
|
||||
Create(ctx context.Context, project *systemv3.Project) (*systemv3.Project, error)
|
||||
// get project by id
|
||||
@@ -39,14 +38,12 @@ type ProjectService interface {
|
||||
|
||||
// projectService implements ProjectService
|
||||
type projectService struct {
|
||||
dao pg.EntityDAO
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
// NewProjectService return new project service
|
||||
func NewProjectService(db *bun.DB) ProjectService {
|
||||
return &projectService{
|
||||
dao: pg.NewEntityDAO(db),
|
||||
}
|
||||
return &projectService{db}
|
||||
}
|
||||
|
||||
func (s *projectService) Create(ctx context.Context, project *systemv3.Project) (*systemv3.Project, error) {
|
||||
@@ -56,7 +53,7 @@ func (s *projectService) Create(ctx context.Context, project *systemv3.Project)
|
||||
}
|
||||
|
||||
var org models.Organization
|
||||
_, err := s.dao.GetByName(ctx, project.Metadata.Organization, &org)
|
||||
_, err := pg.GetByName(ctx, s.db, project.Metadata.Organization, &org)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -72,7 +69,7 @@ func (s *projectService) Create(ctx context.Context, project *systemv3.Project)
|
||||
PartnerId: org.PartnerId,
|
||||
Default: project.GetSpec().GetDefault(),
|
||||
}
|
||||
entity, err := s.dao.Create(ctx, &proj)
|
||||
entity, err := pg.Create(ctx, s.db, &proj)
|
||||
if err != nil {
|
||||
project.Status = &v3.Status{
|
||||
ConditionType: "Create",
|
||||
@@ -121,7 +118,7 @@ func (s *projectService) GetByID(ctx context.Context, id string) (*systemv3.Proj
|
||||
}
|
||||
return project, err
|
||||
}
|
||||
entity, err := s.dao.GetByID(ctx, uid, &models.Project{})
|
||||
entity, err := pg.GetByID(ctx, s.db, uid, &models.Project{})
|
||||
if err != nil {
|
||||
project.Status = &v3.Status{
|
||||
ConditionType: "Describe",
|
||||
@@ -167,7 +164,7 @@ func (s *projectService) GetByName(ctx context.Context, name string) (*systemv3.
|
||||
},
|
||||
}
|
||||
|
||||
entity, err := s.dao.GetByName(ctx, name, &models.Project{})
|
||||
entity, err := pg.GetByName(ctx, s.db, name, &models.Project{})
|
||||
if err != nil {
|
||||
project.Status = &v3.Status{
|
||||
ConditionType: "Describe",
|
||||
@@ -181,13 +178,13 @@ func (s *projectService) GetByName(ctx context.Context, name string) (*systemv3.
|
||||
if proj, ok := entity.(*models.Project); ok {
|
||||
|
||||
var org models.Organization
|
||||
_, err := s.dao.GetByID(ctx, proj.OrganizationId, &org)
|
||||
_, err := pg.GetByID(ctx, s.db, proj.OrganizationId, &org)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var partner models.Partner
|
||||
_, err = s.dao.GetByID(ctx, proj.PartnerId, &partner)
|
||||
_, err = pg.GetByID(ctx, s.db, proj.PartnerId, &partner)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -216,7 +213,7 @@ func (s *projectService) GetByName(ctx context.Context, name string) (*systemv3.
|
||||
|
||||
func (s *projectService) Update(ctx context.Context, project *systemv3.Project) (*systemv3.Project, error) {
|
||||
|
||||
entity, err := s.dao.GetByName(ctx, project.Metadata.Name, &models.Project{})
|
||||
entity, err := pg.GetByName(ctx, s.db, project.Metadata.Name, &models.Project{})
|
||||
if err != nil {
|
||||
project.Status = &v3.Status{
|
||||
ConditionType: "Update",
|
||||
@@ -233,7 +230,7 @@ func (s *projectService) Update(ctx context.Context, project *systemv3.Project)
|
||||
proj.Default = project.Spec.Default
|
||||
proj.ModifiedAt = time.Now()
|
||||
|
||||
_, err = s.dao.Update(ctx, proj.ID, proj)
|
||||
_, err = pg.Update(ctx, s.db, proj.ID, proj)
|
||||
if err != nil {
|
||||
project.Status = &v3.Status{
|
||||
ConditionType: "Update",
|
||||
@@ -259,7 +256,7 @@ func (s *projectService) Update(ctx context.Context, project *systemv3.Project)
|
||||
}
|
||||
|
||||
func (s *projectService) Delete(ctx context.Context, project *systemv3.Project) (*systemv3.Project, error) {
|
||||
entity, err := s.dao.GetByName(ctx, project.Metadata.Name, &models.Project{})
|
||||
entity, err := pg.GetByName(ctx, s.db, project.Metadata.Name, &models.Project{})
|
||||
if err != nil {
|
||||
project.Status = &v3.Status{
|
||||
ConditionType: "Delete",
|
||||
@@ -271,7 +268,7 @@ func (s *projectService) Delete(ctx context.Context, project *systemv3.Project)
|
||||
}
|
||||
if proj, ok := entity.(*models.Project); ok {
|
||||
proj.Trash = true
|
||||
_, err := s.dao.Update(ctx, proj.ID, proj)
|
||||
_, err := pg.Update(ctx, s.db, proj.ID, proj)
|
||||
if err != nil {
|
||||
project.Status = &v3.Status{
|
||||
ConditionType: "Delete",
|
||||
@@ -306,17 +303,17 @@ func (s *projectService) List(ctx context.Context, project *systemv3.Project) (*
|
||||
}
|
||||
if len(project.Metadata.Organization) > 0 {
|
||||
var org models.Organization
|
||||
_, err := s.dao.GetByName(ctx, project.Metadata.Organization, &org)
|
||||
_, err := pg.GetByName(ctx, s.db, project.Metadata.Organization, &org)
|
||||
if err != nil {
|
||||
return projectList, err
|
||||
}
|
||||
var part models.Partner
|
||||
_, err = s.dao.GetByName(ctx, project.Metadata.Partner, &part)
|
||||
_, err = pg.GetByName(ctx, s.db, project.Metadata.Partner, &part)
|
||||
if err != nil {
|
||||
return projectList, err
|
||||
}
|
||||
var projs []models.Project
|
||||
entities, err := s.dao.List(ctx, uuid.NullUUID{UUID: part.ID, Valid: true}, uuid.NullUUID{UUID: org.ID, Valid: true}, &projs)
|
||||
entities, err := pg.List(ctx, s.db, uuid.NullUUID{UUID: part.ID, Valid: true}, uuid.NullUUID{UUID: org.ID, Valid: true}, &projs)
|
||||
if err != nil {
|
||||
return projectList, err
|
||||
}
|
||||
@@ -353,7 +350,3 @@ func (s *projectService) List(ctx context.Context, project *systemv3.Project) (*
|
||||
}
|
||||
return projectList, nil
|
||||
}
|
||||
|
||||
func (s *projectService) Close() error {
|
||||
return s.dao.Close()
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ func TestCreateProject(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewProjectService(db)
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
ouuid := uuid.New().String()
|
||||
@@ -49,7 +48,6 @@ func TestCreateProjectDuplicate(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
gs := NewProjectService(db)
|
||||
defer gs.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
|
||||
@@ -72,7 +70,6 @@ func TestProjectDelete(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewProjectService(db)
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
|
||||
@@ -96,7 +93,6 @@ func TestProjectDeleteNonExist(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewProjectService(db)
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
|
||||
@@ -117,7 +113,6 @@ func TestProjectGetByName(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewProjectService(db)
|
||||
defer ps.Close()
|
||||
|
||||
partuuid := uuid.New().String()
|
||||
ouuid := uuid.New().String()
|
||||
@@ -146,7 +141,6 @@ func TestProjectGetById(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewProjectService(db)
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
|
||||
@@ -168,7 +162,6 @@ func TestProjectUpdate(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
ps := NewProjectService(db)
|
||||
defer ps.Close()
|
||||
|
||||
puuid := uuid.New().String()
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/RafaySystems/rcloud-base/internal/dao"
|
||||
"github.com/RafaySystems/rcloud-base/internal/models"
|
||||
"github.com/RafaySystems/rcloud-base/internal/persistence/provider/pg"
|
||||
"github.com/RafaySystems/rcloud-base/internal/utils"
|
||||
authzv1 "github.com/RafaySystems/rcloud-base/proto/types/authz"
|
||||
v3 "github.com/RafaySystems/rcloud-base/proto/types/commonpb/v3"
|
||||
rolev3 "github.com/RafaySystems/rcloud-base/proto/types/rolepb/v3"
|
||||
@@ -25,7 +24,6 @@ const (
|
||||
|
||||
// RoleService is the interface for role operations
|
||||
type RoleService interface {
|
||||
Close() error
|
||||
// create role
|
||||
Create(context.Context, *rolev3.Role) (*rolev3.Role, error)
|
||||
// get role by id
|
||||
@@ -42,30 +40,23 @@ type RoleService interface {
|
||||
|
||||
// roleService implements RoleService
|
||||
type roleService struct {
|
||||
dao pg.EntityDAO
|
||||
rdao dao.RoleDAO
|
||||
l utils.Lookup
|
||||
azc AuthzService
|
||||
db *bun.DB
|
||||
azc AuthzService
|
||||
}
|
||||
|
||||
// NewRoleService return new role service
|
||||
func NewRoleService(db *bun.DB, azc AuthzService) RoleService {
|
||||
return &roleService{
|
||||
dao: pg.NewEntityDAO(db),
|
||||
rdao: dao.NewRoleDAO(db),
|
||||
l: utils.NewLookup(db),
|
||||
azc: azc,
|
||||
}
|
||||
return &roleService{db: db, azc: azc}
|
||||
}
|
||||
|
||||
func (s *roleService) getPartnerOrganization(ctx context.Context, role *rolev3.Role) (uuid.UUID, uuid.UUID, error) {
|
||||
partner := role.GetMetadata().GetPartner()
|
||||
org := role.GetMetadata().GetOrganization()
|
||||
partnerId, err := s.l.GetPartnerId(ctx, partner)
|
||||
partnerId, err := pg.GetPartnerId(ctx, s.db, partner)
|
||||
if err != nil {
|
||||
return uuid.Nil, uuid.Nil, err
|
||||
}
|
||||
organizationId, err := s.l.GetOrganizationId(ctx, org)
|
||||
organizationId, err := pg.GetOrganizationId(ctx, s.db, org)
|
||||
if err != nil {
|
||||
return partnerId, uuid.Nil, err
|
||||
}
|
||||
@@ -74,7 +65,7 @@ func (s *roleService) getPartnerOrganization(ctx context.Context, role *rolev3.R
|
||||
}
|
||||
|
||||
func (s *roleService) deleteRolePermissionMapping(ctx context.Context, rleId uuid.UUID, role *rolev3.Role) (*rolev3.Role, error) {
|
||||
err := s.dao.DeleteX(ctx, "resource_role_id", rleId, &models.ResourceRolePermission{})
|
||||
err := pg.DeleteX(ctx, s.db, "resource_role_id", rleId, &models.ResourceRolePermission{})
|
||||
if err != nil {
|
||||
return &rolev3.Role{}, err
|
||||
}
|
||||
@@ -96,7 +87,7 @@ func (s *roleService) createRolePermissionMapping(ctx context.Context, role *rol
|
||||
|
||||
var items []models.ResourceRolePermission
|
||||
for _, p := range perms {
|
||||
entity, err := s.dao.GetIdByName(ctx, p, &models.ResourcePermission{})
|
||||
entity, err := pg.GetIdByName(ctx, s.db, p, &models.ResourcePermission{})
|
||||
if err != nil {
|
||||
return role, fmt.Errorf("unable to find role permission '%v'", p)
|
||||
}
|
||||
@@ -110,7 +101,7 @@ func (s *roleService) createRolePermissionMapping(ctx context.Context, role *rol
|
||||
}
|
||||
}
|
||||
if len(items) > 0 {
|
||||
_, err := s.dao.Create(ctx, &items)
|
||||
_, err := pg.Create(ctx, s.db, &items)
|
||||
if err != nil {
|
||||
return role, err
|
||||
}
|
||||
@@ -134,7 +125,7 @@ func (s *roleService) Create(ctx context.Context, role *rolev3.Role) (*rolev3.Ro
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get partner and org id")
|
||||
}
|
||||
r, _ := s.dao.GetIdByNamePartnerOrg(ctx, role.GetMetadata().GetName(), uuid.NullUUID{UUID: partnerId, Valid: true}, uuid.NullUUID{UUID: organizationId, Valid: true}, &models.Role{})
|
||||
r, _ := pg.GetIdByNamePartnerOrg(ctx, s.db, role.GetMetadata().GetName(), uuid.NullUUID{UUID: partnerId, Valid: true}, uuid.NullUUID{UUID: organizationId, Valid: true}, &models.Role{})
|
||||
if r != nil {
|
||||
return nil, fmt.Errorf("role '%v' already exists", role.GetMetadata().GetName())
|
||||
}
|
||||
@@ -159,7 +150,7 @@ func (s *roleService) Create(ctx context.Context, role *rolev3.Role) (*rolev3.Ro
|
||||
IsGlobal: role.GetSpec().GetIsGlobal(),
|
||||
Scope: strings.ToLower(scope),
|
||||
}
|
||||
entity, err := s.dao.Create(ctx, &rle)
|
||||
entity, err := pg.Create(ctx, s.db, &rle)
|
||||
if err != nil {
|
||||
return &rolev3.Role{}, err
|
||||
}
|
||||
@@ -184,7 +175,7 @@ func (s *roleService) GetByID(ctx context.Context, role *rolev3.Role) (*rolev3.R
|
||||
if err != nil {
|
||||
return &rolev3.Role{}, err
|
||||
}
|
||||
entity, err := s.dao.GetByID(ctx, uid, &models.Role{})
|
||||
entity, err := pg.GetByID(ctx, s.db, uid, &models.Role{})
|
||||
if err != nil {
|
||||
return &rolev3.Role{}, err
|
||||
}
|
||||
@@ -206,7 +197,7 @@ func (s *roleService) GetByName(ctx context.Context, role *rolev3.Role) (*rolev3
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get partner and org id")
|
||||
}
|
||||
entity, err := s.dao.GetByNamePartnerOrg(ctx, name, uuid.NullUUID{UUID: partnerId, Valid: true}, uuid.NullUUID{UUID: organizationId, Valid: true}, &models.Role{})
|
||||
entity, err := pg.GetByNamePartnerOrg(ctx, s.db, name, uuid.NullUUID{UUID: partnerId, Valid: true}, uuid.NullUUID{UUID: organizationId, Valid: true}, &models.Role{})
|
||||
if err != nil {
|
||||
return &rolev3.Role{}, err
|
||||
}
|
||||
@@ -230,7 +221,7 @@ func (s *roleService) Update(ctx context.Context, role *rolev3.Role) (*rolev3.Ro
|
||||
}
|
||||
|
||||
name := role.GetMetadata().GetName()
|
||||
entity, err := s.dao.GetByNamePartnerOrg(ctx, name, uuid.NullUUID{UUID: partnerId, Valid: true}, uuid.NullUUID{UUID: organizationId, Valid: true}, &models.Role{})
|
||||
entity, err := pg.GetByNamePartnerOrg(ctx, s.db, name, uuid.NullUUID{UUID: partnerId, Valid: true}, uuid.NullUUID{UUID: organizationId, Valid: true}, &models.Role{})
|
||||
if err != nil {
|
||||
return role, fmt.Errorf("unable to find role '%v'", name)
|
||||
}
|
||||
@@ -243,7 +234,7 @@ func (s *roleService) Update(ctx context.Context, role *rolev3.Role) (*rolev3.Ro
|
||||
rle.Scope = role.Spec.Scope
|
||||
rle.ModifiedAt = time.Now()
|
||||
|
||||
_, err = s.dao.Update(ctx, rle.ID, rle)
|
||||
_, err = pg.Update(ctx, s.db, rle.ID, rle)
|
||||
if err != nil {
|
||||
return &rolev3.Role{}, err
|
||||
}
|
||||
@@ -277,7 +268,7 @@ func (s *roleService) Delete(ctx context.Context, role *rolev3.Role) (*rolev3.Ro
|
||||
return &rolev3.Role{}, fmt.Errorf("unable to get partner and org id; %v", err)
|
||||
}
|
||||
|
||||
entity, err := s.dao.GetByNamePartnerOrg(ctx, name, uuid.NullUUID{UUID: partnerId, Valid: true}, uuid.NullUUID{UUID: organizationId, Valid: true}, &models.Role{})
|
||||
entity, err := pg.GetByNamePartnerOrg(ctx, s.db, name, uuid.NullUUID{UUID: partnerId, Valid: true}, uuid.NullUUID{UUID: organizationId, Valid: true}, &models.Role{})
|
||||
if err != nil {
|
||||
return &rolev3.Role{}, err
|
||||
}
|
||||
@@ -288,7 +279,7 @@ func (s *roleService) Delete(ctx context.Context, role *rolev3.Role) (*rolev3.Ro
|
||||
return &rolev3.Role{}, err
|
||||
}
|
||||
|
||||
err = s.dao.Delete(ctx, rle.ID, rle)
|
||||
err = pg.Delete(ctx, s.db, rle.ID, rle)
|
||||
if err != nil {
|
||||
return &rolev3.Role{}, err
|
||||
}
|
||||
@@ -312,7 +303,7 @@ func (s *roleService) toV3Role(ctx context.Context, role *rolev3.Role, rle *mode
|
||||
Labels: labels,
|
||||
ModifiedAt: timestamppb.New(rle.ModifiedAt),
|
||||
}
|
||||
entities, err := s.rdao.GetRolePermissions(ctx, rle.ID)
|
||||
entities, err := dao.GetRolePermissions(ctx, s.db, rle.ID)
|
||||
if err != nil {
|
||||
return role, err
|
||||
}
|
||||
@@ -339,16 +330,16 @@ func (s *roleService) List(ctx context.Context, role *rolev3.Role) (*rolev3.Role
|
||||
},
|
||||
}
|
||||
if len(role.Metadata.Organization) > 0 {
|
||||
orgId, err := s.l.GetOrganizationId(ctx, role.Metadata.Organization)
|
||||
orgId, err := pg.GetOrganizationId(ctx, s.db, role.Metadata.Organization)
|
||||
if err != nil {
|
||||
return roleList, err
|
||||
}
|
||||
partId, err := s.l.GetPartnerId(ctx, role.Metadata.Partner)
|
||||
partId, err := pg.GetPartnerId(ctx, s.db, role.Metadata.Partner)
|
||||
if err != nil {
|
||||
return roleList, err
|
||||
}
|
||||
var rles []models.Role
|
||||
entities, err := s.dao.List(ctx, uuid.NullUUID{UUID: partId, Valid: true}, uuid.NullUUID{UUID: orgId, Valid: true}, &rles)
|
||||
entities, err := pg.List(ctx, s.db, uuid.NullUUID{UUID: partId, Valid: true}, uuid.NullUUID{UUID: orgId, Valid: true}, &rles)
|
||||
if err != nil {
|
||||
return roleList, err
|
||||
}
|
||||
@@ -374,7 +365,3 @@ func (s *roleService) List(ctx context.Context, role *rolev3.Role) (*rolev3.Role
|
||||
}
|
||||
return roleList, nil
|
||||
}
|
||||
|
||||
func (s *roleService) Close() error {
|
||||
return s.dao.Close()
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ func TestCreateRole(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
rs := NewRoleService(db, &mazc)
|
||||
defer rs.Close()
|
||||
|
||||
ruuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -86,7 +85,6 @@ func TestCreateRoleWithPermissions(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
rs := NewRoleService(db, &mazc)
|
||||
defer rs.Close()
|
||||
|
||||
ruuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -123,7 +121,6 @@ func TestCreateRoleDuplicate(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
rs := NewRoleService(db, &mazc)
|
||||
defer rs.Close()
|
||||
|
||||
ruuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -155,7 +152,6 @@ func TestUpdateRole(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
rs := NewRoleService(db, &mazc)
|
||||
defer rs.Close()
|
||||
|
||||
ruuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -195,7 +191,6 @@ func TestRoleDelete(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
rs := NewRoleService(db, &mazc)
|
||||
defer rs.Close()
|
||||
|
||||
ruuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -227,7 +222,6 @@ func TestRoleDeleteNonExist(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
rs := NewRoleService(db, &mazc)
|
||||
defer rs.Close()
|
||||
|
||||
ruuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -252,7 +246,6 @@ func TestRoleGetByName(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
rs := NewRoleService(db, &mazc)
|
||||
defer rs.Close()
|
||||
|
||||
ruuid := uuid.New().String()
|
||||
rruuid := uuid.New().String()
|
||||
@@ -284,7 +277,6 @@ func TestRoleGetById(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
rs := NewRoleService(db, &mazc)
|
||||
defer rs.Close()
|
||||
|
||||
ruuid := uuid.New().String()
|
||||
rruuid := uuid.New().String()
|
||||
@@ -312,7 +304,6 @@ func TestRoleList(t *testing.T) {
|
||||
|
||||
mazc := mockAuthzClient{}
|
||||
rs := NewRoleService(db, &mazc)
|
||||
defer rs.Close()
|
||||
|
||||
ruuid1 := uuid.New().String()
|
||||
ruuid2 := uuid.New().String()
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
|
||||
"github.com/RafaySystems/rcloud-base/internal/models"
|
||||
"github.com/RafaySystems/rcloud-base/internal/persistence/provider/pg"
|
||||
"github.com/RafaySystems/rcloud-base/internal/utils"
|
||||
v3 "github.com/RafaySystems/rcloud-base/proto/types/commonpb/v3"
|
||||
rolev3 "github.com/RafaySystems/rcloud-base/proto/types/rolepb/v3"
|
||||
"github.com/google/uuid"
|
||||
@@ -19,7 +18,6 @@ const (
|
||||
|
||||
// RolepermissionService is the interface for rolepermission operations
|
||||
type RolepermissionService interface {
|
||||
Close() error
|
||||
// get rolepermission by name
|
||||
GetByName(context.Context, *rolev3.RolePermission) (*rolev3.RolePermission, error)
|
||||
// list rolepermissions
|
||||
@@ -28,16 +26,12 @@ type RolepermissionService interface {
|
||||
|
||||
// rolepermissionService implements RolepermissionService
|
||||
type rolepermissionService struct {
|
||||
dao pg.EntityDAO
|
||||
l utils.Lookup
|
||||
db *bun.DB
|
||||
}
|
||||
|
||||
// NewRolepermissionService return new rolepermission service
|
||||
func NewRolepermissionService(db *bun.DB) RolepermissionService {
|
||||
return &rolepermissionService{
|
||||
dao: pg.NewEntityDAO(db),
|
||||
l: utils.NewLookup(db),
|
||||
}
|
||||
return &rolepermissionService{db: db}
|
||||
}
|
||||
|
||||
func (s *rolepermissionService) toV3Rolepermission(rolepermission *rolev3.RolePermission, rlp *models.ResourcePermission) *rolev3.RolePermission {
|
||||
@@ -53,11 +47,11 @@ func (s *rolepermissionService) toV3Rolepermission(rolepermission *rolev3.RolePe
|
||||
func (s *rolepermissionService) getPartnerOrganization(ctx context.Context, rolepermission *rolev3.RolePermission) (uuid.UUID, uuid.UUID, error) {
|
||||
partner := rolepermission.GetMetadata().GetPartner()
|
||||
org := rolepermission.GetMetadata().GetOrganization()
|
||||
partnerId, err := s.l.GetPartnerId(ctx, partner)
|
||||
partnerId, err := pg.GetPartnerId(ctx, s.db, partner)
|
||||
if err != nil {
|
||||
return uuid.Nil, uuid.Nil, err
|
||||
}
|
||||
organizationId, err := s.l.GetOrganizationId(ctx, org)
|
||||
organizationId, err := pg.GetOrganizationId(ctx, s.db, org)
|
||||
if err != nil {
|
||||
return partnerId, uuid.Nil, err
|
||||
}
|
||||
@@ -67,7 +61,7 @@ func (s *rolepermissionService) getPartnerOrganization(ctx context.Context, role
|
||||
|
||||
func (s *rolepermissionService) GetByName(ctx context.Context, rolepermission *rolev3.RolePermission) (*rolev3.RolePermission, error) {
|
||||
name := rolepermission.GetMetadata().GetName()
|
||||
entity, err := s.dao.GetByName(ctx, name, &models.ResourcePermission{})
|
||||
entity, err := pg.GetByName(ctx, s.db, name, &models.ResourcePermission{})
|
||||
if err != nil {
|
||||
return rolepermission, err
|
||||
}
|
||||
@@ -91,7 +85,7 @@ func (s *rolepermissionService) List(ctx context.Context, rolepermission *rolev3
|
||||
},
|
||||
}
|
||||
var rles []models.ResourcePermission
|
||||
entities, err := s.dao.List(ctx, uuid.NullUUID{UUID: uuid.Nil, Valid: false}, uuid.NullUUID{UUID: uuid.Nil, Valid: false}, &rles)
|
||||
entities, err := pg.List(ctx, s.db, uuid.NullUUID{UUID: uuid.Nil, Valid: false}, uuid.NullUUID{UUID: uuid.Nil, Valid: false}, &rles)
|
||||
if err != nil {
|
||||
return rolepermissionList, err
|
||||
}
|
||||
@@ -111,7 +105,3 @@ func (s *rolepermissionService) List(ctx context.Context, rolepermission *rolev3
|
||||
|
||||
return rolepermissionList, nil
|
||||
}
|
||||
|
||||
func (s *rolepermissionService) Close() error {
|
||||
return s.dao.Close()
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ func TestRolePermissionList(t *testing.T) {
|
||||
defer db.Close()
|
||||
|
||||
rs := NewRolepermissionService(db)
|
||||
defer rs.Close()
|
||||
|
||||
ruuid1 := uuid.New().String()
|
||||
ruuid2 := uuid.New().String()
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"github.com/RafaySystems/rcloud-base/internal/models"
|
||||
providers "github.com/RafaySystems/rcloud-base/internal/persistence/provider/kratos"
|
||||
"github.com/RafaySystems/rcloud-base/internal/persistence/provider/pg"
|
||||
"github.com/RafaySystems/rcloud-base/internal/utils"
|
||||
"github.com/RafaySystems/rcloud-base/pkg/common"
|
||||
userrpcv3 "github.com/RafaySystems/rcloud-base/proto/rpc/user"
|
||||
authzv1 "github.com/RafaySystems/rcloud-base/proto/types/authz"
|
||||
@@ -29,7 +28,6 @@ const (
|
||||
|
||||
// GroupService is the interface for group operations
|
||||
type UserService interface {
|
||||
Close() error
|
||||
// create user
|
||||
Create(context.Context, *userv3.User) (*userv3.User, error)
|
||||
// get user by id
|
||||
@@ -47,14 +45,11 @@ type UserService interface {
|
||||
}
|
||||
|
||||
type userService struct {
|
||||
ap providers.AuthProvider
|
||||
dao pg.EntityDAO
|
||||
udao dao.UserDAO
|
||||
l utils.Lookup
|
||||
azc AuthzService
|
||||
pdao dao.PermissionDao
|
||||
ks ApiKeyService
|
||||
cc common.CliConfigDownloadData
|
||||
ap providers.AuthProvider
|
||||
db *bun.DB
|
||||
azc AuthzService
|
||||
ks ApiKeyService
|
||||
cc common.CliConfigDownloadData
|
||||
}
|
||||
|
||||
type userTraits struct {
|
||||
@@ -72,8 +67,7 @@ type parsedIds struct {
|
||||
}
|
||||
|
||||
func NewUserService(ap providers.AuthProvider, db *bun.DB, azc AuthzService, kss ApiKeyService, cfg common.CliConfigDownloadData) UserService {
|
||||
edao := pg.NewEntityDAO(db)
|
||||
return &userService{ap: ap, dao: edao, udao: dao.NewUserDAO(db), l: utils.NewLookup(db), azc: azc, pdao: dao.NewPermissionDao(edao), ks: kss, cc: cfg}
|
||||
return &userService{ap: ap, db: db, azc: azc, ks: kss, cc: cfg}
|
||||
}
|
||||
|
||||
func getUserTraits(traits map[string]interface{}) userTraits {
|
||||
@@ -114,7 +108,7 @@ func (s *userService) createUserRoleRelations(ctx context.Context, user *userv3.
|
||||
var ps []*authzv1.Policy
|
||||
for _, pnr := range projectNamespaceRoles {
|
||||
role := pnr.GetRole()
|
||||
entity, err := s.dao.GetIdByName(ctx, role, &models.Role{})
|
||||
entity, err := pg.GetIdByName(ctx, s.db, role, &models.Role{})
|
||||
if err != nil {
|
||||
return user, fmt.Errorf("unable to find role '%v'", role)
|
||||
}
|
||||
@@ -131,7 +125,7 @@ func (s *userService) createUserRoleRelations(ctx context.Context, user *userv3.
|
||||
|
||||
switch {
|
||||
case pnr.Namespace != nil:
|
||||
projectId, err := s.l.GetProjectId(ctx, project)
|
||||
projectId, err := pg.GetProjectId(ctx, s.db, project)
|
||||
if err != nil {
|
||||
return user, fmt.Errorf("unable to find project '%v'", project)
|
||||
}
|
||||
@@ -158,7 +152,7 @@ func (s *userService) createUserRoleRelations(ctx context.Context, user *userv3.
|
||||
Act: "*",
|
||||
})
|
||||
case project != "":
|
||||
projectId, err := s.l.GetProjectId(ctx, project)
|
||||
projectId, err := pg.GetProjectId(ctx, s.db, project)
|
||||
if err != nil {
|
||||
return user, fmt.Errorf("unable to find project '%v'", project)
|
||||
}
|
||||
@@ -209,19 +203,19 @@ func (s *userService) createUserRoleRelations(ctx context.Context, user *userv3.
|
||||
}
|
||||
}
|
||||
if len(panrs) > 0 {
|
||||
_, err := s.dao.Create(ctx, &panrs)
|
||||
_, err := pg.Create(ctx, s.db, &panrs)
|
||||
if err != nil {
|
||||
return &userv3.User{}, err
|
||||
}
|
||||
}
|
||||
if len(pars) > 0 {
|
||||
_, err := s.dao.Create(ctx, &pars)
|
||||
_, err := pg.Create(ctx, s.db, &pars)
|
||||
if err != nil {
|
||||
return &userv3.User{}, err
|
||||
}
|
||||
}
|
||||
if len(ars) > 0 {
|
||||
_, err := s.dao.Create(ctx, &ars)
|
||||
_, err := pg.Create(ctx, s.db, &ars)
|
||||
if err != nil {
|
||||
return &userv3.User{}, err
|
||||
}
|
||||
@@ -241,11 +235,11 @@ func (s *userService) createUserRoleRelations(ctx context.Context, user *userv3.
|
||||
func (s *userService) getPartnerOrganization(ctx context.Context, user *userv3.User) (uuid.UUID, uuid.UUID, error) {
|
||||
partner := user.GetMetadata().GetPartner()
|
||||
org := user.GetMetadata().GetOrganization()
|
||||
partnerId, err := s.l.GetPartnerId(ctx, partner)
|
||||
partnerId, err := pg.GetPartnerId(ctx, s.db, partner)
|
||||
if err != nil {
|
||||
return uuid.Nil, uuid.Nil, err
|
||||
}
|
||||
organizationId, err := s.l.GetOrganizationId(ctx, org)
|
||||
organizationId, err := pg.GetOrganizationId(ctx, s.db, org)
|
||||
if err != nil {
|
||||
return partnerId, uuid.Nil, err
|
||||
}
|
||||
@@ -288,7 +282,7 @@ func (s *userService) Create(ctx context.Context, user *userv3.User) (*userv3.Us
|
||||
|
||||
func (s *userService) identitiesModelToUser(ctx context.Context, user *userv3.User, usr *models.KratosIdentities) (*userv3.User, error) {
|
||||
traits := getUserTraits(usr.Traits)
|
||||
groups, err := s.udao.GetGroups(ctx, usr.ID)
|
||||
groups, err := dao.GetGroups(ctx, s.db, usr.ID)
|
||||
if err != nil {
|
||||
return &userv3.User{}, err
|
||||
}
|
||||
@@ -299,7 +293,7 @@ func (s *userService) identitiesModelToUser(ctx context.Context, user *userv3.Us
|
||||
|
||||
labels := make(map[string]string)
|
||||
|
||||
roles, err := s.udao.GetRoles(ctx, usr.ID)
|
||||
roles, err := dao.GetUserRoles(ctx, s.db, usr.ID)
|
||||
if err != nil {
|
||||
return &userv3.User{}, err
|
||||
}
|
||||
@@ -328,7 +322,7 @@ func (s *userService) GetByID(ctx context.Context, user *userv3.User) (*userv3.U
|
||||
if err != nil {
|
||||
return &userv3.User{}, err
|
||||
}
|
||||
entity, err := s.dao.GetByID(ctx, uid, &models.KratosIdentities{})
|
||||
entity, err := pg.GetByID(ctx, s.db, uid, &models.KratosIdentities{})
|
||||
if err != nil {
|
||||
return &userv3.User{}, err
|
||||
}
|
||||
@@ -347,7 +341,7 @@ func (s *userService) GetByID(ctx context.Context, user *userv3.User) (*userv3.U
|
||||
|
||||
func (s *userService) GetByName(ctx context.Context, user *userv3.User) (*userv3.User, error) {
|
||||
name := user.GetMetadata().GetName()
|
||||
entity, err := s.dao.GetByTraits(ctx, name, &models.KratosIdentities{})
|
||||
entity, err := pg.GetByTraits(ctx, s.db, name, &models.KratosIdentities{})
|
||||
if err != nil {
|
||||
return &userv3.User{}, err
|
||||
}
|
||||
@@ -365,15 +359,15 @@ func (s *userService) GetByName(ctx context.Context, user *userv3.User) (*userv3
|
||||
}
|
||||
|
||||
func (s *userService) deleteUserRoleRelations(ctx context.Context, userId uuid.UUID, user *userv3.User) error {
|
||||
err := s.dao.DeleteX(ctx, "account_id", userId, &models.AccountResourcerole{})
|
||||
err := pg.DeleteX(ctx, s.db, "account_id", userId, &models.AccountResourcerole{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = s.dao.DeleteX(ctx, "account_id", userId, &models.ProjectAccountResourcerole{})
|
||||
err = pg.DeleteX(ctx, s.db, "account_id", userId, &models.ProjectAccountResourcerole{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = s.dao.DeleteX(ctx, "account_id", userId, &models.ProjectAccountNamespaceRole{})
|
||||
err = pg.DeleteX(ctx, s.db, "account_id", userId, &models.ProjectAccountNamespaceRole{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -388,7 +382,7 @@ func (s *userService) deleteUserRoleRelations(ctx context.Context, userId uuid.U
|
||||
|
||||
func (s *userService) Update(ctx context.Context, user *userv3.User) (*userv3.User, error) {
|
||||
name := user.GetMetadata().GetName()
|
||||
entity, err := s.dao.GetIdByTraits(ctx, name, &models.KratosIdentities{})
|
||||
entity, err := pg.GetIdByTraits(ctx, s.db, name, &models.KratosIdentities{})
|
||||
if err != nil {
|
||||
return &userv3.User{}, fmt.Errorf("no user found with name '%v'", name)
|
||||
}
|
||||
@@ -426,7 +420,7 @@ func (s *userService) Update(ctx context.Context, user *userv3.User) (*userv3.Us
|
||||
|
||||
func (s *userService) Delete(ctx context.Context, user *userv3.User) (*userrpcv3.DeleteUserResponse, error) {
|
||||
name := user.GetMetadata().GetName()
|
||||
entity, err := s.dao.GetIdByTraits(ctx, name, &models.KratosIdentities{})
|
||||
entity, err := pg.GetIdByTraits(ctx, s.db, name, &models.KratosIdentities{})
|
||||
if err != nil {
|
||||
return &userrpcv3.DeleteUserResponse{}, fmt.Errorf("no user founnd with username '%v'", name)
|
||||
}
|
||||
@@ -442,7 +436,7 @@ func (s *userService) Delete(ctx context.Context, user *userv3.User) (*userrpcv3
|
||||
return &userrpcv3.DeleteUserResponse{}, err
|
||||
}
|
||||
|
||||
err = s.dao.DeleteX(ctx, "account_id", usr.ID, &models.GroupAccount{})
|
||||
err = pg.DeleteX(ctx, s.db, "account_id", usr.ID, &models.GroupAccount{})
|
||||
if err != nil {
|
||||
return &userrpcv3.DeleteUserResponse{}, fmt.Errorf("unable to delete user; %v", err)
|
||||
}
|
||||
@@ -463,7 +457,7 @@ func (s *userService) List(ctx context.Context, _ *userv3.User) (*userv3.UserLis
|
||||
},
|
||||
}
|
||||
var accs []models.KratosIdentities
|
||||
entities, err := s.dao.ListAll(ctx, &accs)
|
||||
entities, err := pg.ListAll(ctx, s.db, &accs)
|
||||
if err != nil {
|
||||
return userList, err
|
||||
}
|
||||
@@ -489,25 +483,25 @@ func (s *userService) List(ctx context.Context, _ *userv3.User) (*userv3.UserLis
|
||||
|
||||
func (s *userService) RetrieveCliConfig(ctx context.Context, req *userrpcv3.ApiKeyRequest) (*common.CliConfigDownloadData, error) {
|
||||
// get the default project associated to this account
|
||||
ap, err := s.pdao.GetDefaultAccountProject(ctx, uuid.MustParse(req.Id))
|
||||
ap, err := dao.GetDefaultAccountProject(ctx, s.db, uuid.MustParse(req.Id))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// fetch the metadata information required to populate cli config
|
||||
var proj models.Project
|
||||
_, err = s.dao.GetByID(ctx, ap.ProjecttId, &proj)
|
||||
_, err = pg.GetByID(ctx, s.db, ap.ProjecttId, &proj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var org models.Organization
|
||||
_, err = s.dao.GetByID(ctx, ap.OrganizationId, &org)
|
||||
_, err = pg.GetByID(ctx, s.db, ap.OrganizationId, &org)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var part models.Partner
|
||||
_, err = s.dao.GetByID(ctx, ap.PartnerId, &part)
|
||||
_, err = pg.GetByID(ctx, s.db, ap.PartnerId, &part)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -539,7 +533,3 @@ func (s *userService) RetrieveCliConfig(ctx context.Context, req *userrpcv3.ApiK
|
||||
return cliConfig, nil
|
||||
|
||||
}
|
||||
|
||||
func (s *userService) Close() error {
|
||||
return s.dao.Close()
|
||||
}
|
||||
|
||||
@@ -61,7 +61,6 @@ func TestCreateUser(t *testing.T) {
|
||||
ap := &mockAuthProvider{}
|
||||
mazc := mockAuthzClient{}
|
||||
us := NewUserService(ap, db, &mazc, nil, common.CliConfigDownloadData{})
|
||||
defer us.Close()
|
||||
|
||||
uuuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -115,7 +114,6 @@ func TestCreateUserWithRole(t *testing.T) {
|
||||
ap := &mockAuthProvider{}
|
||||
mazc := mockAuthzClient{}
|
||||
us := NewUserService(ap, db, &mazc, nil, common.CliConfigDownloadData{})
|
||||
defer us.Close()
|
||||
|
||||
uuuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -168,7 +166,6 @@ func TestUpdateUser(t *testing.T) {
|
||||
ap := &mockAuthProvider{}
|
||||
mazc := mockAuthzClient{}
|
||||
us := NewUserService(ap, db, &mazc, nil, common.CliConfigDownloadData{})
|
||||
defer us.Close()
|
||||
|
||||
uuuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -222,7 +219,6 @@ func TestUserGetByName(t *testing.T) {
|
||||
ap := &mockAuthProvider{}
|
||||
mazc := mockAuthzClient{}
|
||||
us := NewUserService(ap, db, &mazc, nil, common.CliConfigDownloadData{})
|
||||
defer us.Close()
|
||||
|
||||
uuuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -273,7 +269,6 @@ func TestUserGetById(t *testing.T) {
|
||||
ap := &mockAuthProvider{}
|
||||
mazc := mockAuthzClient{}
|
||||
us := NewUserService(ap, db, &mazc, nil, common.CliConfigDownloadData{})
|
||||
defer us.Close()
|
||||
|
||||
uuuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
@@ -322,7 +317,6 @@ func TestUserList(t *testing.T) {
|
||||
ap := &mockAuthProvider{}
|
||||
mazc := mockAuthzClient{}
|
||||
us := NewUserService(ap, db, &mazc, nil, common.CliConfigDownloadData{})
|
||||
defer us.Close()
|
||||
|
||||
uuuid1 := uuid.New().String()
|
||||
uuuid2 := uuid.New().String()
|
||||
@@ -391,7 +385,6 @@ func TestUserDelete(t *testing.T) {
|
||||
ap := &mockAuthProvider{}
|
||||
mazc := mockAuthzClient{}
|
||||
us := NewUserService(ap, db, &mazc, nil, common.CliConfigDownloadData{})
|
||||
defer us.Close()
|
||||
|
||||
uuuid := uuid.New().String()
|
||||
puuid := uuid.New().String()
|
||||
|
||||
Reference in New Issue
Block a user