Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
d-g-town committed May 6, 2024
1 parent e8ff7eb commit 94dad32
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions api/server/handlers/user/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import (
"fmt"
"net/http"
"strconv"
"strings"

"github.com/porter-dev/porter/api/types"

"github.com/porter-dev/porter/internal/models"

Expand Down Expand Up @@ -41,6 +44,13 @@ func (u *MigrateUsersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

r = r.Clone(ctx)

user, _ := r.Context().Value(types.UserScope).(*models.User)
if !strings.HasSuffix(user.Email, "@porter.run") {
err := telemetry.Error(ctx, span, nil, "user is not a porter user")
u.HandleAPIError(w, r, apierrors.NewErrForbidden(err))
return
}

users, err := u.Repo().User().ListUsers()
if err != nil {
err := telemetry.Error(ctx, span, nil, "error listing users")
Expand Down
25 changes: 25 additions & 0 deletions api/server/router/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,5 +472,30 @@ func getUserRoutes(
Router: r,
})

// Get /api/users/migrate -> user.NewMigrateUsersHandler
migrateUsersEndpoint := factory.NewAPIEndpoint(
&types.APIRequestMetadata{
Verb: types.APIVerbGet,
Method: types.HTTPVerbGet,
Path: &types.Path{
Parent: basePath,
RelativePath: "/users/migrate",
},
Scopes: []types.PermissionScope{types.UserScope},
},
)

migrateUsersHandler := user.NewMigrateUsersHandler(
config,
factory.GetDecoderValidator(),
factory.GetResultWriter(),
)

routes = append(routes, &router.Route{
Endpoint: migrateUsersEndpoint,
Handler: migrateUsersHandler,
Router: r,
})

return routes
}

0 comments on commit 94dad32

Please sign in to comment.