Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: Make default project names more readable #1101

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/controlplane/handlers_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (s *Server) CreateOrganization(ctx context.Context,

if in.CreateDefaultRecords {
// we need to create the default records for the organization
defaultProject, defaultRoles, err := CreateDefaultRecordsForOrg(ctx, qtx, org)
defaultProject, defaultRoles, err := CreateDefaultRecordsForOrg(ctx, qtx, org, org.Name+"-project")
if err != nil {
return nil, err
}
Expand All @@ -99,7 +99,7 @@ func (s *Server) CreateOrganization(ctx context.Context,

// CreateDefaultRecordsForOrg creates the default records, such as projects, roles and provider for the organization
func CreateDefaultRecordsForOrg(ctx context.Context, qtx db.Querier,
org db.Project) (*pb.ProjectRecord, []*pb.RoleRecord, error) {
org db.Project, projectName string) (*pb.ProjectRecord, []*pb.RoleRecord, error) {
projectmeta := &ProjectMeta{
IsProtected: true,
Description: fmt.Sprintf("Default admin project for %s", org.Name),
Expand All @@ -116,7 +116,7 @@ func CreateDefaultRecordsForOrg(ctx context.Context, qtx db.Querier,
UUID: org.ID,
Valid: true,
},
Name: fmt.Sprintf("%s-admin", org.Name),
Name: projectName,
Metadata: jsonmeta,
})
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions internal/controlplane/handlers_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,20 @@ func (s *Server) CreateUser(ctx context.Context,
return nil, status.Errorf(codes.Internal, "failed to marshal org metadata: %s", err)
}

baseName := subject
if token.PreferredUsername() != "" {
baseName = token.PreferredUsername()
}

// otherwise self-enroll user, by creating a new org and project and making the user an admin of those
organization, err := qtx.CreateOrganization(ctx, db.CreateOrganizationParams{
Name: subject + "-org",
Name: baseName + "-org",
Metadata: marshaled,
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to create organization: %s", err)
}
orgProject, orgRoles, err := CreateDefaultRecordsForOrg(ctx, qtx, organization)
orgProject, orgRoles, err := CreateDefaultRecordsForOrg(ctx, qtx, organization, baseName)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to create default organization records: %s", err)
}
Expand Down