Documentation ¶
Index ¶
- Constants
- type Generator
- type MockService
- func (_m *MockService) CreateToken(ctx context.Context, tokenRequest NewTokenRequest) (newToken NewToken, err error)
- func (_m *MockService) DeleteToken(ctx context.Context, id string) (_result_0 error)
- func (_m *MockService) GetToken(ctx context.Context, id string) (token Token, err error)
- func (_m *MockService) ListTokens(ctx context.Context) (tokens []Token, err error)
- type NewToken
- type NewTokenRequest
- type NotFoundError
- type Service
- type Store
- type Token
- type UserExtractor
Constants ¶
const ( // UserTokenType is the token type used for API sessions UserTokenType = "user" // VirtualUserTokenType is the token type used for API sessions by external services // Used by PKE at the moment // Legacy token type (used by CICD build hook originally) VirtualUserTokenType = "hook" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Generator ¶
type Generator interface { // GenerateToken generates a token. GenerateToken(sub string, expiresAt time.Time, tokenType string, value string) (string, string, error) }
Generator generates a token.
type MockService ¶
MockService is an autogenerated mock for the Service type.
func (*MockService) CreateToken ¶
func (_m *MockService) CreateToken(ctx context.Context, tokenRequest NewTokenRequest) (newToken NewToken, err error)
CreateToken provides a mock function.
func (*MockService) DeleteToken ¶
func (_m *MockService) DeleteToken(ctx context.Context, id string) (_result_0 error)
DeleteToken provides a mock function.
func (*MockService) ListTokens ¶
func (_m *MockService) ListTokens(ctx context.Context) (tokens []Token, err error)
ListTokens provides a mock function.
type NewTokenRequest ¶
type NewTokenRequest struct { Name string `json:"name,omitempty"` VirtualUser string `json:"virtualUser,omitempty"` ExpiresAt *time.Time `json:"expiresAt,omitempty"` }
NewTokenRequest contains necessary information for generating a new token.
type NotFoundError ¶
type NotFoundError struct {
ID string
}
NotFoundError is returned if a token cannot be found.
func (NotFoundError) Details ¶
func (e NotFoundError) Details() []interface{}
Details returns error details.
func (NotFoundError) Error ¶
func (NotFoundError) Error() string
Error implements the error interface.
func (NotFoundError) NotFound ¶
func (NotFoundError) NotFound() bool
NotFound tells a client that this error is related to a resource being not found. Can be used to translate the error to eg. status code.
func (NotFoundError) ServiceError ¶
func (NotFoundError) ServiceError() bool
ServiceError tells the transport layer whether this error should be translated into the transport format or an internal error should be returned instead.
type Service ¶
type Service interface { // CreateToken creates a new access token. It returns the generated token value. CreateToken(ctx context.Context, tokenRequest NewTokenRequest) (newToken NewToken, err error) // ListTokens lists access tokens for a user. ListTokens(ctx context.Context) (tokens []Token, err error) // GetToken returns a single access tokens for a user. GetToken(ctx context.Context, id string) (token Token, err error) // DeleteToken deletes a single access token for a user. DeleteToken(ctx context.Context, id string) error }
Service provides access to personal access tokens.
func NewService ¶
func NewService( userExtractor UserExtractor, store Store, generator Generator, ) Service
NewService returns a new Service.
type Store ¶
type Store interface { // Store stores a token in the persistent secret store. Store(ctx context.Context, userID string, tokenID string, name string, expiresAt *time.Time) error // List lists the tokens in the store. List(ctx context.Context, userID string) ([]Token, error) // Lookup finds a user token. Lookup(ctx context.Context, userID string, tokenID string) (Token, error) // Revoke revokes an access token. Revoke(ctx context.Context, userID string, tokenID string) error }
Store persists access tokens in a secret store.
type Token ¶
type Token struct { ID string `json:"id"` Name string `json:"name"` ExpiresAt *time.Time `json:"expiresAt,omitempty"` CreatedAt time.Time `json:"createdAt,omitempty"` }
Token represents an access token.
type UserExtractor ¶
type UserExtractor interface { // GetUserID returns the ID of the currently authenticated user. // If a user cannot be found in the context, it returns false as the second return value. GetUserID(ctx context.Context) (uint, bool) // GetUserLogin returns the login name of the currently authenticated user. // If a user cannot be found in the context, it returns false as the second return value. GetUserLogin(ctx context.Context) (string, bool) }
UserExtractor extracts user information from the context.