Documentation
¶
Overview ¶
Package accesstoken holds the project access token workflows behind the volcano access-tokens subcommands.
Index ¶
- Constants
- func ParseExpiry(value string) (*time.Time, error)
- func Scopes() []string
- func ValidateListWindow(page, limit int) error
- func ValidateScope(scope string) error
- func ValidateUsageDays(days int) error
- type Service
- func (s Service) Create(ctx context.Context, input api.AccessTokenCreateInput) (*apiclient.CreatedProjectAccessToken, error)
- func (s Service) Get(ctx context.Context, identifier string) (*apiclient.ProjectAccessToken, error)
- func (s Service) ListPage(ctx context.Context, input api.AccessTokenListInput) (*apiclient.PaginatedProjectAccessTokens, error)
- func (s Service) ProjectUsage(ctx context.Context, days int) ([]apiclient.ProjectAccessTokenUsage, error)
- func (s Service) Revoke(ctx context.Context, token *apiclient.ProjectAccessToken) error
- func (s Service) TokenUsage(ctx context.Context, tokenID uuid.UUID, days int) (*apiclient.ProjectAccessTokenUsage, error)
- func (s Service) Usage(ctx context.Context, token *apiclient.ProjectAccessToken, days int) (*apiclient.ProjectAccessTokenUsage, error)
Constants ¶
const ( ScopeFull = string(apiclient.ProjectAccessTokenScopeFull) ScopeReadOnly = string(apiclient.ProjectAccessTokenScopeReadOnly) )
Scope values a token can be minted with.
const DefaultUsageDays = 30
DefaultUsageDays matches the API default for the usage series.
const MaxListLimit = 100
MaxListLimit matches the API's ceiling on a page size.
const MaxUsageDays = 60
MaxUsageDays matches the API's ceiling, which is also how long per-day counts are retained.
Variables ¶
This section is empty.
Functions ¶
func ParseExpiry ¶
ParseExpiry converts an RFC3339 expiry flag into the API's optional expires_at. An empty value means the token never expires.
func Scopes ¶
func Scopes() []string
Scopes returns the scopes a token can be minted with, for help text and flag validation.
func ValidateListWindow ¶
ValidateListWindow rejects a page or page size outside what the contract allows, so a typo fails naming the flag the user typed rather than as whatever the API makes of it. Same reason as ValidateUsageDays, though unlike --days these values do at least reach the request.
func ValidateScope ¶
ValidateScope rejects a scope the API does not define, so a typo fails before the request instead of as an opaque 400.
func ValidateUsageDays ¶
ValidateUsageDays rejects a window the API does not accept.
The lower bound matters more than the upper one: a non-positive value used to be dropped from the request entirely, so asking for -5 days quietly returned the 30-day default with a success exit code — a plausible answer to a different question.
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service performs authenticated Volcano project access token workflows.
func NewService ¶
func NewService(deps cliruntime.Deps) Service
NewService returns a project access token service.
func (Service) Create ¶
func (s Service) Create(ctx context.Context, input api.AccessTokenCreateInput) (*apiclient.CreatedProjectAccessToken, error)
Create mints one access token in the current project.
func (Service) ListPage ¶
func (s Service) ListPage(ctx context.Context, input api.AccessTokenListInput) (*apiclient.PaginatedProjectAccessTokens, error)
ListPage returns one access token page in the current project.
func (Service) ProjectUsage ¶
func (s Service) ProjectUsage(ctx context.Context, days int) ([]apiclient.ProjectAccessTokenUsage, error)
ProjectUsage returns the daily request counts for every access token in the current project, revoked tokens included.
The API admits a project access token on the usage reads, so this one is not account-scoped: a CI job holding nothing but the pt- token it runs with can still report its own consumption.
func (Service) Revoke ¶
Revoke revokes a token the caller already resolved, so the token that was confirmed is the token that is revoked.
func (Service) TokenUsage ¶
func (s Service) TokenUsage(ctx context.Context, tokenID uuid.UUID, days int) (*apiclient.ProjectAccessTokenUsage, error)
TokenUsage returns the daily request counts for one access token by ID, reading no metadata first.
That is what makes it reachable with a project access token: the API admits one on the usage routes but not on the token records, so the only route to a token's own day-by-day series is to address it by ID. Resolving a name needs the account-only list endpoint, so a CI job reporting its own consumption has to name the ID it was given when the token was minted.
func (Service) Usage ¶
func (s Service) Usage(ctx context.Context, token *apiclient.ProjectAccessToken, days int) (*apiclient.ProjectAccessTokenUsage, error)
Usage returns the daily request counts for a token the caller already resolved.
It takes the token rather than the name the user typed because Get has resolved that by the time usage is wanted: resolving it again costs a second paginated walk, and a transient failure there would report a token that does not exist moments after reading it.