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:
11 files changed
+877
-12
No files matched your search
@@ -1,6 +1,8 @@
|
||||
package registry
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
@@ -17,6 +19,8 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
|
||||
var flags map[string]common.ReportFunc
|
||||
if appName == "--global" {
|
||||
flags = map[string]common.ReportFunc{
|
||||
"--registry-computed-auth-servers": reportComputedAuthServers,
|
||||
"--registry-global-auth-servers": reportGlobalAuthServers,
|
||||
"--registry-computed-push-on-release": reportComputedPushOnRelease,
|
||||
"--registry-global-push-on-release": reportGlobalPushOnRelease,
|
||||
"--registry-computed-server": reportComputedServer,
|
||||
@@ -28,6 +32,9 @@ func ReportSingleApp(appName string, format string, infoFlag string) error {
|
||||
}
|
||||
} else {
|
||||
flags = map[string]common.ReportFunc{
|
||||
"--registry-auth-servers": reportAuthServers,
|
||||
"--registry-computed-auth-servers": reportComputedAuthServers,
|
||||
"--registry-global-auth-servers": reportGlobalAuthServers,
|
||||
"--registry-computed-image-repo": reportComputedImageRepo,
|
||||
"--registry-image-repo": reportImageRepo,
|
||||
"--registry-computed-push-on-release": reportComputedPushOnRelease,
|
||||
@@ -156,3 +163,36 @@ func reportComputedPushExtraTags(appName string) string {
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
// reportAuthServers lists the servers the app has its own credentials for
|
||||
func reportAuthServers(appName string) string {
|
||||
return authServersFromConfigPath(GetAppRegistryConfigPath(appName))
|
||||
}
|
||||
|
||||
// reportGlobalAuthServers lists the servers the global config has credentials for
|
||||
func reportGlobalAuthServers(appName string) string {
|
||||
return authServersFromConfigPath(GetGlobalRegistryConfigPath())
|
||||
}
|
||||
|
||||
// reportComputedAuthServers lists the servers whose credentials dokku would use
|
||||
// for the app. Docker is pointed at one config directory or the other rather
|
||||
// than a merge of both, so an app with any credential of its own shadows the
|
||||
// global config entirely.
|
||||
func reportComputedAuthServers(appName string) string {
|
||||
return authServersFromConfigPath(filepath.Join(GetComputedAppRegistryConfigDir(appName), "config.json"))
|
||||
}
|
||||
|
||||
// authServersFromConfigPath lists the servers a docker config holds credentials for
|
||||
func authServersFromConfigPath(configPath string) string {
|
||||
contents, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
config, err := parseDockerConfig(contents)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return strings.Join(authServersFromConfig(config), ",")
|
||||
}
|
||||
Reference in new issue
Block a user