artifactregistry

package
v1.131.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package artifactregistry provides a client for exchanging a GitLab session token for a short-lived GitLab Artifact Registry access token via the POST /api/v4/token_exchange endpoint.

It lives under internal/api rather than beside the command that uses it so that the glab auth docker credential helper can consume it too once it learns about artifact registries: command packages must not import each other.

Index

Constants

View Source
const (
	// MinDuration is the shortest lifetime a caller may request through
	// ExchangeToken: the server's actual floor. These tokens cannot be
	// revoked once minted, and AppSec is pushing for shorter-lived tokens
	// (gitlab#601725, artifact-registry#229), so the CLI does not add a
	// floor of its own above the server's: a caller asking for less
	// exposure should never be blocked from getting it.
	MinDuration = 1 * time.Second
	// MaxDuration is the longest lifetime a caller may request through
	// ExchangeToken. A CLI-side choice, not a server contract; see
	// MinDuration.
	MaxDuration = 12 * time.Hour
	// DefaultDuration is what callers get when they do not choose a
	// duration explicitly, e.g. `glab artifact-registry get-token` with no
	// --duration. A CLI-side choice, independent of MinDuration and of the
	// server's own 5-minute default, which applies only when expires_in is
	// omitted entirely (see ExchangeDefaultToken).
	DefaultDuration = 15 * time.Minute
	// DockerHelperDuration is the token lifetime the Docker credential helper
	// requests for every artifact-registry exchange it makes. Docker invokes
	// the helper with no way to pass a duration, so this is the only lever;
	// it is entirely independent of `get-token`, which always validates and
	// uses its own --duration flag (defaulting to DefaultDuration, not
	// MinDuration). It is deliberately longer than MinDuration: a docker
	// pull/push holds the credential for the whole operation, not just the
	// initial handshake, and a token expiring mid-pull hard-fails it.
	// Changing it changes how long every docker pull/push's token stays valid.
	DockerHelperDuration = time.Hour
)

Variables

This section is empty.

Functions

func ValidateDuration

func ValidateDuration(d time.Duration) error

ValidateDuration reports whether d is within [MinDuration, MaxDuration]. This is an advisory, CLI-side guard so flag parsing fails fast with a clear message; it is not a mirror of server policy, which can change independently (artifact-registry#229) and whose 400 response is always the authoritative answer.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client exchanges a GitLab session token for a short-lived Artifact Registry access token.

func NewClient

func NewClient(gl *gitlab.Client) *Client

NewClient returns a Client that issues token-exchange requests through gl.

func (*Client) ExchangeDefaultToken

func (c *Client) ExchangeDefaultToken(ctx context.Context) (*ExchangeResult, error)

ExchangeDefaultToken exchanges the caller's GitLab credential for a short-lived Artifact Registry access token, omitting expires_in so the server applies its own default lifetime. Callers that only read the token's claims and then discard it, like `status`, want the server default rather than a CLI-chosen duration.

func (*Client) ExchangeToken

func (c *Client) ExchangeToken(ctx context.Context, duration time.Duration) (*ExchangeResult, error)

ExchangeToken exchanges the caller's GitLab credential for a short-lived Artifact Registry access token valid for duration. duration must be within [MinDuration, MaxDuration].

type ExchangeResult

type ExchangeResult = tokenexchange.Result

ExchangeResult is the decoded result of a successful token exchange.

Jump to

Keyboard shortcuts

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