Register IdpService in main.go and minor changes in Idp model

This commit is contained in:
Akshay Gaikwad
2022-01-18 18:07:17 +05:30
parent d794603d7f
commit c1ba133383
3 changed files with 30 additions and 23 deletions

View File

@@ -61,6 +61,7 @@ var (
us service.UserService
gs service.GroupService
rs service.RoleService
is service.IdpService
dev bool
_log = logv2.GetLogger()
authPool authv3.AuthPool
@@ -122,6 +123,7 @@ func setup() {
us = service.NewUserService(kc, db)
gs = service.NewGroupService(db)
rs = service.NewRoleService(db)
is = service.NewIdpService(db)
_log.Infow("usermgmt setup complete")
}
@@ -155,6 +157,7 @@ func runAPI(wg *sync.WaitGroup, ctx context.Context) {
pbrpcv3.RegisterUserHandlerFromEndpoint,
pbrpcv3.RegisterGroupHandlerFromEndpoint,
pbrpcv3.RegisterRoleHandlerFromEndpoint,
pbrpcv3.RegisterIdpHandlerFromEndpoint,
)
if err != nil {
_log.Fatalw("unable to create gateway", "error", err)
@@ -188,6 +191,7 @@ func runRPC(wg *sync.WaitGroup, ctx context.Context) {
userServer := server.NewUserServer(us)
groupServer := server.NewGroupServer(gs)
roleServer := server.NewRoleServer(rs)
idpServer := server.NewIdpServer(is)
l, err := net.Listen("tcp", fmt.Sprintf(":%d", rpcPort))
if err != nil {
@@ -224,6 +228,7 @@ func runRPC(wg *sync.WaitGroup, ctx context.Context) {
rpcv3.RegisterUserServer(s, userServer)
rpcv3.RegisterGroupServer(s, groupServer)
rpcv3.RegisterRoleServer(s, roleServer)
rpcv3.RegisterIdpServer(s, idpServer)
_log.Infow("starting rpc server", "port", rpcPort)
err = s.Serve(l)

View File

@@ -16,19 +16,19 @@ type Idp struct {
CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp"`
ModifiedAt time.Time `bun:"modified_at,notnull,default:current_timestamp"`
IdpName string `bun:"idp_name,notnull"`
Domain string `bun:"domain,notnull,unique"`
AcsURL string `bun:"acs_url,notnull,unique"`
OrganizationId string `bun:"organization_id,type:uuid"`
PartnerId string `bun:"partner_id,type:uuid"`
SsoURL string `bun:"sso_url"`
IdpCert string `bun:"idp_cert"`
SpCert string `bun:"sp_cert"`
SpKey string `bun:"sp_key"`
MetadataURL string `bun:"metadata_url"`
MetadataFilename string `bun:"metadata_filename"`
Metadata []byte `bun:"metadata"`
GroupAttributeName string `bun:"group_attribute_name"`
SaeEnabled bool `bun:"is_sae_enabled"`
Trash bool `bun:"trash,default:false"`
IdpName string `bun:"idp_name,notnull"`
Domain string `bun:"domain,notnull,unique"`
AcsURL string `bun:"acs_url,notnull,unique"`
OrganizationId uuid.UUID `bun:"organization_id,type:uuid"`
PartnerId uuid.UUID `bun:"partner_id,type:uuid"`
SsoURL string `bun:"sso_url"`
IdpCert string `bun:"idp_cert"`
SpCert string `bun:"sp_cert"`
SpKey string `bun:"sp_key"`
MetadataURL string `bun:"metadata_url"`
MetadataFilename string `bun:"metadata_filename"`
Metadata []byte `bun:"metadata"`
GroupAttributeName string `bun:"group_attribute_name"`
SaeEnabled bool `bun:"is_sae_enabled"`
Trash bool `bun:"trash,default:false"`
}

View File

@@ -129,6 +129,8 @@ func (s *idpService) CreateIdp(ctx context.Context, idp *userv3.NewIdp) (*userv3
AcsURL: acsURL,
GroupAttributeName: idp.GetGroupAttributeName(),
SaeEnabled: idp.GetIsSaeEnabled(),
CreatedAt: time.Now(),
ModifiedAt: time.Now(),
}
if entity.SaeEnabled {
spcert, spkey, err := generateSpCert(base.Host)
@@ -156,8 +158,8 @@ func (s *idpService) CreateIdp(ctx context.Context, idp *userv3.NewIdp) (*userv3
MetadataFilename: entity.MetadataFilename,
IsSaeEnabled: entity.SaeEnabled,
GroupAttributeName: entity.GroupAttributeName,
OrganizationId: entity.OrganizationId,
PartnerId: entity.PartnerId,
OrganizationId: entity.OrganizationId.String(),
PartnerId: entity.PartnerId.String(),
CreatedAt: entity.CreatedAt.Format(TimeLayout),
ModifiedAt: entity.ModifiedAt.Format(TimeLayout),
}
@@ -209,8 +211,8 @@ func (s *idpService) UpdateIdp(ctx context.Context, new *userv3.UpdateIdp) (*use
MetadataFilename: entity.MetadataFilename,
IsSaeEnabled: entity.SaeEnabled,
GroupAttributeName: entity.GroupAttributeName,
OrganizationId: entity.OrganizationId,
PartnerId: entity.PartnerId,
OrganizationId: entity.OrganizationId.String(),
PartnerId: entity.PartnerId.String(),
CreatedAt: entity.CreatedAt.Format(TimeLayout),
ModifiedAt: entity.ModifiedAt.Format(TimeLayout),
}
@@ -243,10 +245,10 @@ func (s *idpService) GetSpConfigById(ctx context.Context, idpID *userv3.IdpID) (
}
func (s *idpService) ListIdps(ctx context.Context, req *userv3.ListIdpsRequest) (*userv3.ListIdpsResponse, error) {
entities := []*models.Idp{}
var entities []models.Idp
var orgID uuid.NullUUID
var parID uuid.NullUUID
s.dao.List(ctx, parID, orgID, entities)
s.dao.List(ctx, parID, orgID, &entities)
// Get idps only till limit
var result []*userv3.Idp
@@ -264,8 +266,8 @@ func (s *idpService) ListIdps(ctx context.Context, req *userv3.ListIdpsRequest)
MetadataFilename: entity.MetadataFilename,
IsSaeEnabled: entity.SaeEnabled,
GroupAttributeName: entity.GroupAttributeName,
OrganizationId: entity.OrganizationId,
PartnerId: entity.PartnerId,
OrganizationId: entity.OrganizationId.String(),
PartnerId: entity.PartnerId.String(),
CreatedAt: entity.CreatedAt.Format(TimeLayout),
ModifiedAt: entity.ModifiedAt.Format(TimeLayout),
}