Skip to content

Commit

Permalink
fix(apikeys): add role validation
Browse files Browse the repository at this point in the history
  • Loading branch information
balzdur committed Feb 13, 2024
1 parent dfeecfc commit d5028fb
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions usecases/api_key_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/checkmarble/marble-backend/usecases/analytics"
"github.com/checkmarble/marble-backend/usecases/transaction"
"github.com/google/uuid"
"github.com/pkg/errors"
)

type ApiKeyRepository interface {
Expand Down Expand Up @@ -72,6 +73,10 @@ func (usecase *ApiKeyUseCase) CreateApiKey(ctx context.Context, input models.Cre
return models.CreatedApiKey{}, err
}

if input.Role != models.API_CLIENT {
return models.CreatedApiKey{}, errors.Wrap(models.BadParameterError, fmt.Sprintf("role %s is not supported", input.Role))
}

apiKeyId := uuid.NewString()
key := generateAPiKey()
if err := usecase.apiKeyRepository.CreateApiKey(ctx, tx, models.CreateApiKey{
Expand Down

0 comments on commit d5028fb

Please sign in to comment.