Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"go.uber.org/zap"

"github.com/e2b-dev/infra/packages/dashboard-api/internal/api"
"github.com/e2b-dev/infra/packages/dashboard-api/internal/userprofile"
"github.com/e2b-dev/infra/packages/dashboard-api/internal/identity"
"github.com/e2b-dev/infra/packages/shared/pkg/ginutils"
"github.com/e2b-dev/infra/packages/shared/pkg/logger"
)
Expand Down Expand Up @@ -41,7 +41,7 @@ func (s *APIStore) PostAdminUserProfilesResolve(c *gin.Context) {
seen[userID] = struct{}{}
}

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

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

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

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

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

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

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

func apiProfileFromProfile(profile userprofile.Profile) api.AdminAuthProviderProfile {
func apiProfileFromProfile(profile identity.Profile) api.AdminAuthProviderProfile {
var email *string
if profile.Email != "" {
email = new(profile.Email)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (s *APIStore) PostAdminTeamsBootstrap(c *gin.Context) {
return
}

team, err := s.bootstrapTeam(ctx, name, email)
team, err := s.provisioning.BootstrapTeam(ctx, name, email)
if err != nil {
s.handleProvisioningError(ctx, c, "provision team", err)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/google/uuid"
"github.com/jackc/pgx/v5"

"github.com/e2b-dev/infra/packages/dashboard-api/internal/provisioning"
internalteamprovision "github.com/e2b-dev/infra/packages/dashboard-api/internal/teamprovision"
"github.com/e2b-dev/infra/packages/db/pkg/testutils"
"github.com/e2b-dev/infra/packages/shared/pkg/teamprovision"
Expand All @@ -33,8 +34,7 @@ func TestPostAdminTeamsBootstrapCreatesTeam(t *testing.T) {
ginCtx.Request.Header.Set("Content-Type", "application/json")

store := &APIStore{
authDB: testDB.AuthDB,
teamProvisionSink: sink,
provisioning: provisioning.New(testDB.AuthDB, nil, sink, nil),
}
store.PostAdminTeamsBootstrap(ginCtx)

Expand Down Expand Up @@ -109,8 +109,7 @@ func TestPostAdminTeamsBootstrapRollsBackOnProvisioningFailure(t *testing.T) {
ginCtx.Request.Header.Set("Content-Type", "application/json")

store := &APIStore{
authDB: testDB.AuthDB,
teamProvisionSink: sink,
provisioning: provisioning.New(testDB.AuthDB, nil, sink, nil),
}
store.PostAdminTeamsBootstrap(ginCtx)

Expand Down Expand Up @@ -149,8 +148,7 @@ func TestPostAdminTeamsBootstrapRejectsMissingFields(t *testing.T) {
ginCtx.Request.Header.Set("Content-Type", "application/json")

store := &APIStore{
authDB: testDB.AuthDB,
teamProvisionSink: &fakeTeamProvisionSink{err: errors.New("should not provision")},
provisioning: provisioning.New(testDB.AuthDB, nil, &fakeTeamProvisionSink{err: errors.New("should not provision")}, nil),
}
store.PostAdminTeamsBootstrap(ginCtx)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/gin-gonic/gin"

"github.com/e2b-dev/infra/packages/dashboard-api/internal/api"
"github.com/e2b-dev/infra/packages/dashboard-api/internal/provisioning"
"github.com/e2b-dev/infra/packages/shared/pkg/ginutils"
"github.com/e2b-dev/infra/packages/shared/pkg/telemetry"
)
Expand All @@ -35,7 +36,7 @@ func (s *APIStore) PostAdminUsersBootstrap(c *gin.Context) {
return
}

team, err := s.bootstrapOIDCUser(ctx, oidcUserBootstrapInput{
team, err := s.provisioning.BootstrapOIDCUser(ctx, provisioning.OIDCUserBootstrapInput{
OIDCIssuer: oidcIssuer,
OIDCUserID: oidcUserID,
OIDCUserEmail: oidcUserEmail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"go.uber.org/zap"

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

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

return
Expand Down
Loading
Loading