dockercredhelper

package
v1.113.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package dockercredhelper wires glab into Docker as a credential helper: it installs the docker-credential-glab shim that Docker executes, and points Docker's config.json at that shim for a set of registry domains.

Index

Constants

View Source
const (
	// FullName is the shim's file name, and is what Docker looks for in the
	// user's PATH.
	FullName = "docker-credential-glab"
	// ShortName is the short name of the credential helper, and is what a
	// Docker config's credHelpers object lists for a registry.
	ShortName = "glab"
)

Variables

This section is empty.

Functions

func ConfigDir

func ConfigDir() (string, error)

ConfigDir resolves the directory Docker reads config.json from, mirroring dockerconfig.Dir(): $DOCKER_CONFIG when set, otherwise ~/.docker. Honoring $DOCKER_CONFIG matters because writing to the wrong directory fails silently: the command reports success, but Docker reads a config.json with no credHelpers entry for the registry.

This is not dockerconfig.Dir() itself, because that function memoizes its result in a process-wide sync.Once the first time it's called: the first caller in the process would lock in a directory that later callers (for example, tests overriding $HOME) can't change.

func Install

func Install() (string, error)

Install writes the shim next to the glab binary found on PATH and returns its path. It is idempotent: re-running it overwrites the script and forces the mode, so a shim left by an older glab is brought up to date.

Types

type ConflictError

type ConflictError struct {
	// Helpers maps a domain to the credential helper already configured for it.
	Helpers map[string]string
	// ConfigPath is the config.json holding those entries.
	ConfigPath string
}

ConflictError reports domains that a different credential helper already claims. Register returns it having written nothing.

func (*ConflictError) Error

func (e *ConflictError) Error() string

type Registration

type Registration struct {
	Domain string
	// ShadowedLogin is true when Docker's config.json already held a
	// credential for Domain, which `docker login` writes. Docker consults
	// credHelpers ahead of that entry, so the stored credential is now unused
	// and the caller should say so.
	ShadowedLogin bool
}

Registration reports the outcome of pointing Docker at glab for one domain.

func Register

func Register(dir string, domains ...string) ([]Registration, error)

Register points Docker at the glab credential helper for each of domains, by writing credHelpers in dir's config.json. Callers resolve dir via ConfigDir unless they have a reason to use a different directory.

Every domain is checked before anything is written, and a domain already claimed by a different helper fails the whole call with a *ConflictError. Docker resolves credHelpers ahead of every other credential source and credHelpers holds one helper per domain, so overwriting an entry silently takes a registry away from whichever tool owns it — ecr-login, gcloud, a per-registry osxkeychain — and Save discards the old value irrecoverably.

Jump to

Keyboard shortcuts

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