55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
// Code generated by ogen, DO NOT EDIT.
|
|
|
|
package api
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/go-faster/errors"
|
|
)
|
|
|
|
// SecuritySource is provider of security values (tokens, passwords, etc.).
|
|
type SecuritySource interface {
|
|
// BearerAuth provides bearerAuth security value.
|
|
// Shared random service token sent as `Authorization: Bearer <token>`. The service compares it in
|
|
// constant time and never logs it. Rotation replaces the secret on both sides; there are no per-user
|
|
// tokens.
|
|
BearerAuth(ctx context.Context, operationName OperationName) (BearerAuth, error)
|
|
}
|
|
|
|
// operationRolesBearerAuth is a private map storing roles per operation.
|
|
var operationRolesBearerAuth = map[string][]string{
|
|
CreateMLEmbeddingsOperation: []string{},
|
|
}
|
|
|
|
// GetRolesForBearerAuth returns the required roles for the given operation.
|
|
//
|
|
// This is useful for authorization scenarios where you need to know which roles
|
|
// are required for an operation.
|
|
//
|
|
// Example:
|
|
//
|
|
// requiredRoles := GetRolesForBearerAuth(AddPetOperation)
|
|
//
|
|
// Returns nil if the operation has no role requirements or if the operation is unknown.
|
|
func GetRolesForBearerAuth(operation string) []string {
|
|
roles, ok := operationRolesBearerAuth[operation]
|
|
if !ok {
|
|
return nil
|
|
}
|
|
// Return a copy to prevent external modification
|
|
result := make([]string, len(roles))
|
|
copy(result, roles)
|
|
return result
|
|
}
|
|
|
|
func (s *Client) securityBearerAuth(ctx context.Context, operationName OperationName, req *http.Request) error {
|
|
t, err := s.sec.BearerAuth(ctx, operationName)
|
|
if err != nil {
|
|
return errors.Wrap(err, "security source \"BearerAuth\"")
|
|
}
|
|
req.Header.Set("Authorization", "Bearer "+t.Token)
|
|
return nil
|
|
}
|