MCPcopy Create free account
hub / github.com/docker/cli / getAuth

Function getAuth

cli/command/registry/search.go:96–116  ·  view source on GitHub ↗

getAuth will use fetch auth based on the given search-term. If the search does not contain a hostname for the registry, it assumes Docker Hub is used, and resolves authentication for Docker Hub, otherwise it resolves authentication for the given registry.

(dockerCLI command.Cli, reposName string)

Source from the content-addressed store, hash-verified

94// and resolves authentication for Docker Hub, otherwise it resolves authentication
95// for the given registry.
96func getAuth(dockerCLI command.Cli, reposName string) (encodedAuth string, err error) {
97 authCfgKey := splitReposSearchTerm(reposName)
98 if authCfgKey == "docker.io" || authCfgKey == "index.docker.io" {
99 authCfgKey = authConfigKey
100 }
101
102 // Ignoring errors here, which was the existing behavior (likely
103 // "no credentials found"). We'll get an error when search failed,
104 // so fine to ignore in most situations.
105 authConfig, _ := dockerCLI.ConfigFile().GetAuthConfig(authCfgKey)
106 return authconfig.Encode(registrytypes.AuthConfig{
107 Username: authConfig.Username,
108 Password: authConfig.Password,
109 ServerAddress: authConfig.ServerAddress,
110
111 // TODO(thaJeztah): Are these expected to be included?
112 Auth: authConfig.Auth,
113 IdentityToken: authConfig.IdentityToken,
114 RegistryToken: authConfig.RegistryToken,
115 })
116}
117
118// splitReposSearchTerm breaks a search term into an index name and remote name
119func splitReposSearchTerm(reposName string) string {

Callers 1

runSearchFunction · 0.85

Calls 3

splitReposSearchTermFunction · 0.85
GetAuthConfigMethod · 0.80
ConfigFileMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…