feat: add registry:auth-status to read back login state

There was no way to ask whether Dokku was already logged in to a registry with a given credential, so tooling converging a declared state onto a server had to re-run `registry:login` on every pass purely to discover that nothing needed to change. The new `registry:auth-status` command compares a supplied credential against the stored one and reports the result through its exit code alone, distinguishing a server with no credential from one whose credential differs, and from one whose secret a docker credential helper or an identity token puts out of reach. An `auth-servers` triad on `registry:report` exposes which servers have credentials without emitting any part of one.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-09-19 19:19:57 -04:00
1 parent 2e3d144aca
commit 624eea1959
11 files changed
+877 -12

No files matched your search

@@ -18,6 +18,7 @@ Manage registry settings for an app
Additional commands:`
helpContent = `
registry:auth-status [--password-stdin] <app>|--global <server> [<username> [<password>]], Reports whether the stored registry credential matches the requested state (exit 0 if matches)
registry:login [--global|--password-stdin] [<app>] <server> <username> [<password>], Login to a docker registry
registry:logout [--global] [<app>] <server>, Logout from a docker registry
registry:report [<app>] [<flag>], Displays a registry report for one or more apps
@@ -1,7 +1,9 @@
package main
import (
"errors"
"fmt"
"io"
"os"
"strings"
@@ -18,6 +20,40 @@ func main() {
var err error
switch subcommand {
case "auth-status":
// the result of this command is its exit code, so parse errors must not
// be left to pflag: ExitOnError exits 2 on an unknown flag, which this
// command defines as a differing credential, and 0 on --help
args := flag.NewFlagSet("registry:auth-status", flag.ContinueOnError)
args.SetOutput(io.Discard)
passwordStdin := args.Bool("password-stdin", false, "--password-stdin: read password from stdin")
global := args.Bool("global", false, "--global: check the global registry credentials")
if parseErr := args.Parse(os.Args[2:]); parseErr != nil {
message := parseErr.Error()
if errors.Is(parseErr, flag.ErrHelp) {
message = "Usage: dokku registry:auth-status [--password-stdin] <app>|--global <server> [<username> [<password>]]"
}
common.LogFailWithError(registry.InvalidAuthStatusArguments(message))
}
var appName, server, username, password string
offset := 0
if !*global {
appName = args.Arg(0)
offset = 1
if appName == "" {
common.LogFailWithError(registry.InvalidAuthStatusArguments("Please specify an app or the --global flag"))
}
}
server = args.Arg(offset)
username = args.Arg(offset + 1)
if !*passwordStdin {
password = args.Arg(offset + 2)
}
err = registry.CommandAuthStatus(appName, server, username, password, *passwordStdin)
case "login":
args := flag.NewFlagSet("registry:login", flag.ExitOnError)
passwordStdin := args.Bool("password-stdin", false, "--password-stdin: read password from stdin")