Skip to content

Commit 70e4c58

Browse files
committed
refactor(dashboard-api): rename userprofile package to identity
The package is the identity-provider boundary, not just profile lookup — call sites now read identity.Provider ("identity provider"). Fields follow: userProfiles/profiles -> idp. The generated /admin/user-profiles API surface is unchanged. Rename-only; no behavior change.
1 parent 7a6e42e commit 70e4c58

20 files changed

Lines changed: 120 additions & 118 deletions

packages/dashboard-api/internal/handlers/admin_auth_provider_profiles.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"go.uber.org/zap"
99

1010
"github.com/e2b-dev/infra/packages/dashboard-api/internal/api"
11-
"github.com/e2b-dev/infra/packages/dashboard-api/internal/userprofile"
11+
"github.com/e2b-dev/infra/packages/dashboard-api/internal/identity"
1212
"github.com/e2b-dev/infra/packages/shared/pkg/ginutils"
1313
"github.com/e2b-dev/infra/packages/shared/pkg/logger"
1414
)
@@ -41,7 +41,7 @@ func (s *APIStore) PostAdminUserProfilesResolve(c *gin.Context) {
4141
seen[userID] = struct{}{}
4242
}
4343

44-
profiles, err := s.userProfiles.GetProfilesByUserID(ctx, body.UserIds)
44+
profiles, err := s.idp.GetProfilesByUserID(ctx, body.UserIds)
4545
if err != nil {
4646
logger.L().Error(ctx, "failed to resolve auth provider profiles", zap.Error(err))
4747
s.sendAPIStoreError(c, http.StatusInternalServerError, "Failed to resolve auth provider profiles")
@@ -64,7 +64,7 @@ func (s *APIStore) PostAdminUserProfilesByEmail(c *gin.Context) {
6464
return
6565
}
6666

67-
profiles, err := s.userProfiles.FindProfilesByEmail(ctx, string(body.Email))
67+
profiles, err := s.idp.FindProfilesByEmail(ctx, string(body.Email))
6868
if err != nil {
6969
logger.L().Error(ctx, "failed to look up auth provider profiles by email", zap.Error(err))
7070
s.sendAPIStoreError(c, http.StatusInternalServerError, "Failed to look up auth provider profiles")
@@ -79,7 +79,7 @@ func (s *APIStore) PostAdminUserProfilesByEmail(c *gin.Context) {
7979

8080
func (s *APIStore) GetAdminUserProfilesUserId(c *gin.Context, userId api.UserId) {
8181
ctx := c.Request.Context()
82-
profiles, err := s.userProfiles.GetProfilesByUserID(ctx, []uuid.UUID{userId})
82+
profiles, err := s.idp.GetProfilesByUserID(ctx, []uuid.UUID{userId})
8383
if err != nil {
8484
logger.L().Error(ctx, "failed to resolve auth provider profile", zap.Error(err))
8585
s.sendAPIStoreError(c, http.StatusInternalServerError, "Failed to resolve auth provider profile")
@@ -92,7 +92,7 @@ func (s *APIStore) GetAdminUserProfilesUserId(c *gin.Context, userId api.UserId)
9292
})
9393
}
9494

95-
func apiProfilesFromMap(userIDs []uuid.UUID, profiles map[uuid.UUID]userprofile.Profile) []api.AdminAuthProviderProfile {
95+
func apiProfilesFromMap(userIDs []uuid.UUID, profiles map[uuid.UUID]identity.Profile) []api.AdminAuthProviderProfile {
9696
result := make([]api.AdminAuthProviderProfile, 0, len(profiles))
9797
seen := make(map[uuid.UUID]struct{}, len(userIDs))
9898

@@ -113,7 +113,7 @@ func apiProfilesFromMap(userIDs []uuid.UUID, profiles map[uuid.UUID]userprofile.
113113
return result
114114
}
115115

116-
func apiProfilesFromProfiles(profiles []userprofile.Profile) []api.AdminAuthProviderProfile {
116+
func apiProfilesFromProfiles(profiles []identity.Profile) []api.AdminAuthProviderProfile {
117117
result := make([]api.AdminAuthProviderProfile, 0, len(profiles))
118118

119119
for _, profile := range profiles {
@@ -123,7 +123,7 @@ func apiProfilesFromProfiles(profiles []userprofile.Profile) []api.AdminAuthProv
123123
return result
124124
}
125125

126-
func apiProfileFromProfile(profile userprofile.Profile) api.AdminAuthProviderProfile {
126+
func apiProfileFromProfile(profile identity.Profile) api.AdminAuthProviderProfile {
127127
var email *string
128128
if profile.Email != "" {
129129
email = new(profile.Email)

packages/dashboard-api/internal/handlers/admin_users_delete.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"go.uber.org/zap"
1212

1313
"github.com/e2b-dev/infra/packages/dashboard-api/internal/api"
14-
"github.com/e2b-dev/infra/packages/dashboard-api/internal/userprofile"
14+
"github.com/e2b-dev/infra/packages/dashboard-api/internal/identity"
1515
"github.com/e2b-dev/infra/packages/db/pkg/dberrors"
1616
"github.com/e2b-dev/infra/packages/shared/pkg/logger"
1717
)
@@ -22,9 +22,9 @@ func (s *APIStore) DeleteAdminUsersUserId(c *gin.Context, userId api.UserId) {
2222
ctx := c.Request.Context()
2323

2424
// Resolve the external identity references while user_identities still exists.
25-
handle, err := s.userProfiles.PrepareDeleteUser(ctx, userId)
25+
handle, err := s.idp.PrepareDeleteUser(ctx, userId)
2626
if err != nil {
27-
if errors.Is(err, userprofile.ErrUserNotFound) {
27+
if errors.Is(err, identity.ErrUserNotFound) {
2828
s.sendAPIStoreError(c, http.StatusNotFound, fmt.Sprintf("User %s not found or has no identity provider record", userId))
2929

3030
return

packages/dashboard-api/internal/handlers/sso_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ import (
1717
"github.com/e2b-dev/infra/packages/db/pkg/testutils"
1818
)
1919

20-
// ssoUserProfiles is a Provider whose organization lookups are configurable, so
20+
// ssoIdentityProvider is a Provider whose organization lookups are configurable, so
2121
// tests can simulate identities that belong to an Ory organization.
22-
type ssoUserProfiles struct {
23-
handlerTestUserProfiles
22+
type ssoIdentityProvider struct {
23+
handlerTestIdentityProvider
2424

2525
orgByUser map[uuid.UUID]uuid.UUID
2626
}
2727

28-
func (p ssoUserProfiles) GetUserOrganizationID(_ context.Context, userID uuid.UUID) (uuid.UUID, error) {
28+
func (p ssoIdentityProvider) GetUserOrganizationID(_ context.Context, userID uuid.UUID) (uuid.UUID, error) {
2929
return p.orgByUser[userID], nil
3030
}
3131

@@ -49,8 +49,8 @@ func TestPostTeamsTeamIDMembers_RejectsInviteOutsideSSOOrg(t *testing.T) {
4949

5050
// invitee belongs to no org (orgByUser empty) → outside the team's org.
5151
store := &APIStore{
52-
userProfiles: ssoUserProfiles{},
53-
provisioning: provisioning.New(nil, ssoUserProfiles{}, nil, ""),
52+
idp: ssoIdentityProvider{},
53+
provisioning: provisioning.New(nil, ssoIdentityProvider{}, nil, ""),
5454
}
5555
store.PostTeamsTeamIDMembers(ginCtx, teamID)
5656

@@ -80,12 +80,12 @@ func TestPostTeamsTeamIDMembers_AllowsInviteFromSSOOrg(t *testing.T) {
8080
ginCtx.Request.Header.Set("Content-Type", "application/json")
8181

8282
// invitee belongs to the same org as the team → allowed.
83-
profiles := ssoUserProfiles{orgByUser: map[uuid.UUID]uuid.UUID{inviteeID: orgID}}
83+
profiles := ssoIdentityProvider{orgByUser: map[uuid.UUID]uuid.UUID{inviteeID: orgID}}
8484
store := &APIStore{
8585
db: testDB.SqlcClient,
8686
authDB: testDB.AuthDB,
8787
authService: noopAuthService{},
88-
userProfiles: profiles,
88+
idp: profiles,
8989
provisioning: provisioning.New(testDB.AuthDB, profiles, nil, ""),
9090
}
9191
store.PostTeamsTeamIDMembers(ginCtx, teamID)

packages/dashboard-api/internal/handlers/store.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
clickhouse "github.com/e2b-dev/infra/packages/clickhouse/pkg"
1313
"github.com/e2b-dev/infra/packages/dashboard-api/internal/api"
1414
"github.com/e2b-dev/infra/packages/dashboard-api/internal/cfg"
15+
"github.com/e2b-dev/infra/packages/dashboard-api/internal/identity"
1516
"github.com/e2b-dev/infra/packages/dashboard-api/internal/provisioning"
1617
internalteamprovision "github.com/e2b-dev/infra/packages/dashboard-api/internal/teamprovision"
17-
"github.com/e2b-dev/infra/packages/dashboard-api/internal/userprofile"
1818
sqlcdb "github.com/e2b-dev/infra/packages/db/client"
1919
authdb "github.com/e2b-dev/infra/packages/db/pkg/auth"
2020
"github.com/e2b-dev/infra/packages/shared/pkg/apierrors"
@@ -28,7 +28,7 @@ type APIStore struct {
2828
authDB *authdb.Client
2929
clickhouse clickhouse.Clickhouse
3030
authService sharedauth.Service
31-
userProfiles userprofile.Provider
31+
idp identity.Provider
3232
provisioning *provisioning.Service
3333
}
3434

@@ -39,16 +39,16 @@ func NewAPIStore(
3939
ch clickhouse.Clickhouse,
4040
authService sharedauth.Service,
4141
teamProvisionSink internalteamprovision.TeamProvisionSink,
42-
userProfiles userprofile.Provider,
42+
idp identity.Provider,
4343
) *APIStore {
4444
return &APIStore{
4545
config: config,
4646
db: db,
4747
authDB: authDB,
4848
clickhouse: ch,
4949
authService: authService,
50-
userProfiles: userProfiles,
51-
provisioning: provisioning.New(authDB, userProfiles, teamProvisionSink, config.OryIssuerURL),
50+
idp: idp,
51+
provisioning: provisioning.New(authDB, idp, teamProvisionSink, config.OryIssuerURL),
5252
}
5353
}
5454

packages/dashboard-api/internal/handlers/team_handlers_test.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import (
1515

1616
"github.com/e2b-dev/infra/packages/auth/pkg/auth"
1717
authtypes "github.com/e2b-dev/infra/packages/auth/pkg/types"
18+
"github.com/e2b-dev/infra/packages/dashboard-api/internal/identity"
1819
"github.com/e2b-dev/infra/packages/dashboard-api/internal/provisioning"
1920
internalteamprovision "github.com/e2b-dev/infra/packages/dashboard-api/internal/teamprovision"
20-
"github.com/e2b-dev/infra/packages/dashboard-api/internal/userprofile"
2121
authqueries "github.com/e2b-dev/infra/packages/db/pkg/auth/queries"
2222
"github.com/e2b-dev/infra/packages/db/pkg/testutils"
2323
"github.com/e2b-dev/infra/packages/db/queries"
@@ -125,9 +125,9 @@ func TestPostTeamsTeamIDMembers_DuplicateMemberReturnsBadRequest(t *testing.T) {
125125
})
126126

127127
store := &APIStore{
128-
db: testDB.SqlcClient,
129-
authDB: testDB.AuthDB,
130-
userProfiles: newHandlerTestUserProfiles(),
128+
db: testDB.SqlcClient,
129+
authDB: testDB.AuthDB,
130+
idp: newHandlerTestIdentityProvider(),
131131
}
132132
store.PostTeamsTeamIDMembers(ginCtx, teamID)
133133

@@ -163,10 +163,10 @@ func TestPostTeamsTeamIDMembers_CreatesPublicUserAnchorForInvitee(t *testing.T)
163163
})
164164

165165
store := &APIStore{
166-
db: testDB.SqlcClient,
167-
authDB: testDB.AuthDB,
168-
authService: noopAuthService{},
169-
userProfiles: newHandlerTestUserProfiles(),
166+
db: testDB.SqlcClient,
167+
authDB: testDB.AuthDB,
168+
authService: noopAuthService{},
169+
idp: newHandlerTestIdentityProvider(),
170170
}
171171
store.PostTeamsTeamIDMembers(ginCtx, teamID)
172172

@@ -355,19 +355,19 @@ func handlerTestUserEmail(userID uuid.UUID) string {
355355
return "user-" + userID.String() + "@example.com"
356356
}
357357

358-
type handlerTestUserProfiles struct{}
358+
type handlerTestIdentityProvider struct{}
359359

360-
func newHandlerTestUserProfiles() userprofile.Provider {
361-
return handlerTestUserProfiles{}
360+
func newHandlerTestIdentityProvider() identity.Provider {
361+
return handlerTestIdentityProvider{}
362362
}
363363

364-
func (handlerTestUserProfiles) GetProfilesByUserID(_ context.Context, userIDs []uuid.UUID) (map[uuid.UUID]userprofile.Profile, error) {
365-
profiles := make(map[uuid.UUID]userprofile.Profile, len(userIDs))
364+
func (handlerTestIdentityProvider) GetProfilesByUserID(_ context.Context, userIDs []uuid.UUID) (map[uuid.UUID]identity.Profile, error) {
365+
profiles := make(map[uuid.UUID]identity.Profile, len(userIDs))
366366
for _, userID := range userIDs {
367367
if userID == uuid.Nil {
368368
continue
369369
}
370-
profiles[userID] = userprofile.Profile{
370+
profiles[userID] = identity.Profile{
371371
UserID: userID,
372372
Email: handlerTestUserEmail(userID),
373373
}
@@ -376,36 +376,36 @@ func (handlerTestUserProfiles) GetProfilesByUserID(_ context.Context, userIDs []
376376
return profiles, nil
377377
}
378378

379-
func (handlerTestUserProfiles) FindProfilesByEmail(_ context.Context, email string) ([]userprofile.Profile, error) {
379+
func (handlerTestIdentityProvider) FindProfilesByEmail(_ context.Context, email string) ([]identity.Profile, error) {
380380
userIDText := strings.TrimSuffix(strings.TrimPrefix(email, "user-"), "@example.com")
381381
userID, _ := uuid.Parse(userIDText)
382382
if userID == uuid.Nil {
383-
return []userprofile.Profile{}, nil
383+
return []identity.Profile{}, nil
384384
}
385385

386-
return []userprofile.Profile{{
386+
return []identity.Profile{{
387387
UserID: userID,
388388
Email: email,
389389
}}, nil
390390
}
391391

392-
func (handlerTestUserProfiles) GetTeamCreatorContext(context.Context, uuid.UUID) (*teamprovision.CreatorContextV1, error) {
392+
func (handlerTestIdentityProvider) GetTeamCreatorContext(context.Context, uuid.UUID) (*teamprovision.CreatorContextV1, error) {
393393
return nil, nil
394394
}
395395

396-
func (handlerTestUserProfiles) GetIdentityOrganizationID(context.Context, string) (uuid.UUID, error) {
396+
func (handlerTestIdentityProvider) GetIdentityOrganizationID(context.Context, string) (uuid.UUID, error) {
397397
return uuid.Nil, nil
398398
}
399399

400-
func (handlerTestUserProfiles) GetUserOrganizationID(context.Context, uuid.UUID) (uuid.UUID, error) {
400+
func (handlerTestIdentityProvider) GetUserOrganizationID(context.Context, uuid.UUID) (uuid.UUID, error) {
401401
return uuid.Nil, nil
402402
}
403403

404-
func (handlerTestUserProfiles) SetIdentityExternalID(context.Context, string, uuid.UUID) error {
404+
func (handlerTestIdentityProvider) SetIdentityExternalID(context.Context, string, uuid.UUID) error {
405405
return nil
406406
}
407407

408-
func (handlerTestUserProfiles) PrepareDeleteUser(context.Context, uuid.UUID) (userprofile.DeleteUserHandle, error) {
408+
func (handlerTestIdentityProvider) PrepareDeleteUser(context.Context, uuid.UUID) (identity.DeleteUserHandle, error) {
409409
return nil, nil
410410
}
411411

@@ -483,7 +483,7 @@ func TestPostTeams_LocalPolicyDeniedReturnsBadRequestWithoutCreatingTeam(t *test
483483
store := &APIStore{
484484
db: testDB.SqlcClient,
485485
authDB: testDB.AuthDB,
486-
provisioning: provisioning.New(testDB.AuthDB, newHandlerTestUserProfiles(), sink, ""),
486+
provisioning: provisioning.New(testDB.AuthDB, newHandlerTestIdentityProvider(), sink, ""),
487487
}
488488
store.PostTeams(ginCtx)
489489

@@ -521,7 +521,7 @@ func TestPostTeams_InvalidNameReturnsBadRequest(t *testing.T) {
521521
store := &APIStore{
522522
db: testDB.SqlcClient,
523523
authDB: testDB.AuthDB,
524-
provisioning: provisioning.New(testDB.AuthDB, newHandlerTestUserProfiles(), sink, ""),
524+
provisioning: provisioning.New(testDB.AuthDB, newHandlerTestIdentityProvider(), sink, ""),
525525
}
526526
store.PostTeams(ginCtx)
527527

@@ -551,7 +551,7 @@ func TestPostTeams_InvalidRequestBodyReturnsBadRequest(t *testing.T) {
551551
store := &APIStore{
552552
db: testDB.SqlcClient,
553553
authDB: testDB.AuthDB,
554-
provisioning: provisioning.New(testDB.AuthDB, newHandlerTestUserProfiles(), sink, ""),
554+
provisioning: provisioning.New(testDB.AuthDB, newHandlerTestIdentityProvider(), sink, ""),
555555
}
556556
store.PostTeams(ginCtx)
557557

@@ -583,7 +583,7 @@ func TestPostTeams_TrimsNameBeforeCreate(t *testing.T) {
583583
store := &APIStore{
584584
db: testDB.SqlcClient,
585585
authDB: testDB.AuthDB,
586-
provisioning: provisioning.New(testDB.AuthDB, newHandlerTestUserProfiles(), sink, ""),
586+
provisioning: provisioning.New(testDB.AuthDB, newHandlerTestIdentityProvider(), sink, ""),
587587
}
588588
store.PostTeams(ginCtx)
589589

@@ -634,7 +634,7 @@ func TestPostTeams_ProvisioningFailureRollsBackCreatedTeam(t *testing.T) {
634634
store := &APIStore{
635635
db: testDB.SqlcClient,
636636
authDB: testDB.AuthDB,
637-
provisioning: provisioning.New(testDB.AuthDB, newHandlerTestUserProfiles(), sink, ""),
637+
provisioning: provisioning.New(testDB.AuthDB, newHandlerTestIdentityProvider(), sink, ""),
638638
}
639639
store.PostTeams(ginCtx)
640640

@@ -692,7 +692,7 @@ func TestPostTeams_ProvisioningFailurePreservesProvisionErrorStatus(t *testing.T
692692
store := &APIStore{
693693
db: testDB.SqlcClient,
694694
authDB: testDB.AuthDB,
695-
provisioning: provisioning.New(testDB.AuthDB, newHandlerTestUserProfiles(), sink, ""),
695+
provisioning: provisioning.New(testDB.AuthDB, newHandlerTestIdentityProvider(), sink, ""),
696696
}
697697
store.PostTeams(ginCtx)
698698

packages/dashboard-api/internal/handlers/team_members.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (s *APIStore) GetTeamsTeamIDMembers(c *gin.Context, teamID api.TeamID) {
4040
userIDs = append(userIDs, row.UserID)
4141
}
4242

43-
profiles, err := s.userProfiles.GetProfilesByUserID(ctx, userIDs)
43+
profiles, err := s.idp.GetProfilesByUserID(ctx, userIDs)
4444
if err != nil {
4545
logger.L().Error(ctx, "failed to get member profiles", zap.Error(err), logger.WithTeamID(authTeamID.String()))
4646
s.sendAPIStoreError(c, http.StatusInternalServerError, "Failed to get team member profiles")
@@ -106,7 +106,7 @@ func (s *APIStore) PostTeamsTeamIDMembers(c *gin.Context, teamID api.TeamID) {
106106
return
107107
}
108108

109-
profiles, err := s.userProfiles.FindProfilesByEmail(ctx, string(body.Email))
109+
profiles, err := s.idp.FindProfilesByEmail(ctx, string(body.Email))
110110
if err != nil {
111111
logger.L().Error(ctx, "failed to look up user by email", zap.Error(err))
112112
s.sendAPIStoreError(c, http.StatusInternalServerError, "Failed to look up user")

packages/dashboard-api/internal/userprofile/creator_context.go renamed to packages/dashboard-api/internal/identity/creator_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package userprofile
1+
package identity
22

33
import (
44
"strings"

packages/dashboard-api/internal/userprofile/ory.go renamed to packages/dashboard-api/internal/identity/ory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package userprofile
1+
package identity
22

33
import (
44
"context"

packages/dashboard-api/internal/userprofile/ory_test.go renamed to packages/dashboard-api/internal/identity/ory_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package userprofile
1+
package identity
22

33
import (
44
"context"

packages/dashboard-api/internal/userprofile/provider.go renamed to packages/dashboard-api/internal/identity/provider.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
package userprofile
1+
// Package identity abstracts the external identity provider (Ory): profile
2+
// lookup, organization membership, and identity lifecycle.
3+
package identity
24

35
import (
46
"context"

0 commit comments

Comments
 (0)