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)
| 94 | // and resolves authentication for Docker Hub, otherwise it resolves authentication |
| 95 | // for the given registry. |
| 96 | func 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 |
| 119 | func splitReposSearchTerm(reposName string) string { |
no test coverage detected
searching dependent graphs…