Documentation
¶
Overview ¶
Package api_token contains the use cases that implement the multi API token CRUD endpoints (list, create, get, delete). Authorization is enforced inside each use case so the HTTP controller stays thin.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthService ¶
type AuthService interface {
LoadAPIToken(ctx context.Context, token *entities.APIToken) error
RevokeAPIToken(secret string)
}
AuthService provides the auth-side operations the use cases need: loading a newly created token so it authenticates immediately, and revoking a deleted token's secret from the in-memory auth map.
type CreateAPITokenInput ¶
type CreateAPITokenInput struct {
// Caller is the authenticated user creating the token.
Caller *entities.User
// Name is the human-readable token name (optional but recommended).
Name string
// Scope is "user" or "team".
Scope string
// TeamID is required when Scope == "team".
TeamID string
// Permissions is the requested permission set; each must be granted by
// the caller (no broader than caller).
Permissions []entities.Permission
// ExpiresAt is the optional expiration time.
ExpiresAt *time.Time
}
CreateAPITokenInput is the request to create a new token.
type CreateAPITokenOutput ¶
CreateAPITokenOutput is the result of a successful creation. It includes the plaintext secret, which is returned exactly once to the caller.
type CreateAPITokenUseCase ¶
type CreateAPITokenUseCase struct {
// contains filtered or unexported fields
}
CreateAPITokenUseCase creates new named API tokens.
func NewCreateAPITokenUseCase ¶
func NewCreateAPITokenUseCase(repo repositories.APITokenRepository, authService AuthService) *CreateAPITokenUseCase
NewCreateAPITokenUseCase constructs a CreateAPITokenUseCase.
func (*CreateAPITokenUseCase) Execute ¶
func (uc *CreateAPITokenUseCase) Execute(ctx context.Context, in *CreateAPITokenInput) (*CreateAPITokenOutput, error)
Execute creates the token.
type DeleteAPITokenInput ¶
DeleteAPITokenInput is the request to delete a token.
type DeleteAPITokenUseCase ¶
type DeleteAPITokenUseCase struct {
// contains filtered or unexported fields
}
DeleteAPITokenUseCase deletes tokens with creator-or-admin authorization for team tokens and owner-only authorization for personal tokens. It is idempotent: deleting a non-existent or not-authorized token returns nil so the HTTP layer can answer 204 without leaking cross-scope existence.
func NewDeleteAPITokenUseCase ¶
func NewDeleteAPITokenUseCase(repo repositories.APITokenRepository, authService AuthService) *DeleteAPITokenUseCase
NewDeleteAPITokenUseCase constructs a DeleteAPITokenUseCase.
func (*DeleteAPITokenUseCase) Execute ¶
func (uc *DeleteAPITokenUseCase) Execute(ctx context.Context, in *DeleteAPITokenInput) error
Execute deletes the token.
type GetAPITokenInput ¶
GetAPITokenInput is the request to get a single token's metadata.
type GetAPITokenOutput ¶
GetAPITokenOutput is the get result.
type GetAPITokenUseCase ¶
type GetAPITokenUseCase struct {
// contains filtered or unexported fields
}
GetAPITokenUseCase fetches a single token's metadata.
func NewGetAPITokenUseCase ¶
func NewGetAPITokenUseCase(repo repositories.APITokenRepository) *GetAPITokenUseCase
NewGetAPITokenUseCase constructs a GetAPITokenUseCase.
func (*GetAPITokenUseCase) Execute ¶
func (uc *GetAPITokenUseCase) Execute(ctx context.Context, in *GetAPITokenInput) (*GetAPITokenOutput, error)
Execute fetches the token. It returns entities.ErrAPITokenNotFound both when the token does not exist and when the caller is not authorized to see it, so the HTTP layer can return a uniform 404 without leaking cross-scope existence.
type ListAPITokenInput ¶
type ListAPITokenInput struct {
Caller *entities.User
Scope string // "" | "user" | "team"
TeamID string
}
ListAPITokenInput is the request to list tokens.
type ListAPITokenOutput ¶
ListAPITokenOutput is the list result (tokens without secrets are produced by the controller; the entities here still carry secrets and must not be serialized directly).
type ListAPITokenUseCase ¶
type ListAPITokenUseCase struct {
// contains filtered or unexported fields
}
ListAPITokenUseCase lists API tokens the caller is allowed to see.
func NewListAPITokenUseCase ¶
func NewListAPITokenUseCase(repo repositories.APITokenRepository) *ListAPITokenUseCase
NewListAPITokenUseCase constructs a ListAPITokenUseCase.
func (*ListAPITokenUseCase) Execute ¶
func (uc *ListAPITokenUseCase) Execute(ctx context.Context, in *ListAPITokenInput) (*ListAPITokenOutput, error)
Execute lists the tokens.