api_token

package
v1.538.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 8 Imported by: 0

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

type CreateAPITokenOutput struct {
	Token *entities.APIToken
}

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

Execute creates the token.

type DeleteAPITokenInput

type DeleteAPITokenInput struct {
	Caller  *entities.User
	TokenID string
}

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

Execute deletes the token.

type GetAPITokenInput

type GetAPITokenInput struct {
	Caller  *entities.User
	TokenID string
}

GetAPITokenInput is the request to get a single token's metadata.

type GetAPITokenOutput

type GetAPITokenOutput struct {
	Token *entities.APIToken
}

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

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

type ListAPITokenOutput struct {
	Tokens []*entities.APIToken
}

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

Execute lists the tokens.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL