Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
Update iam.go
Browse files Browse the repository at this point in the history
  • Loading branch information
ramizpolic committed Jul 26, 2023
1 parent 1d9a4b5 commit 59df583
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions backend/pkg/iam/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"github.com/deepmap/oapi-codegen/pkg/middleware"
"github.com/getkin/kin-openapi/openapi3filter"
"github.com/labstack/echo/v4"
"github.com/openclarity/vmclarity/api/models"
"net/http"
)
Expand Down Expand Up @@ -64,13 +65,8 @@ func OapiAuthenticatorForProvider(m Provider) openapi3filter.AuthenticationFunc

// GetRequiredRolesFromContext returns a list of roles from context required to
// perform a request.
func GetRequiredRolesFromContext(ctx context.Context) []string {
eCtx := middleware.GetEchoContext(ctx)
if eCtx == nil {
return nil
}

ctxData := eCtx.Get(models.IamPolicyScopes)
func GetRequiredRolesFromContext(ctx echo.Context) []string {
ctxData := ctx.Get(models.IamPolicyScopes)
if ctxData == nil {
return nil
}
Expand All @@ -80,13 +76,8 @@ func GetRequiredRolesFromContext(ctx context.Context) []string {
}

// GetUserFromContext returns User from context or throws an error.
func GetUserFromContext(ctx context.Context) (*User, error) {
eCtx := middleware.GetEchoContext(ctx)
if eCtx == nil {
return nil, fmt.Errorf("could not get context")
}

ctxData := eCtx.Get(userCtxKey)
func GetUserFromContext(ctx echo.Context) (*User, error) {
ctxData := ctx.Get(userCtxKey)
if ctxData == nil {
return nil, fmt.Errorf("no user data found in context")
}
Expand Down

0 comments on commit 59df583

Please sign in to comment.