8
8
"encoding/json"
9
9
"errors"
10
10
"fmt"
11
- "io"
12
11
"net/url"
13
12
"os"
14
13
"sync"
@@ -137,26 +136,14 @@ func (c *credentialsCache) Get(hostname, configKey string) (string, string, erro
137
136
return user , password , nil
138
137
}
139
138
140
- // configFileKey returns a key to use for caching credentials based on
139
+ // configKey returns a key to use for caching credentials based on
141
140
// the contents of the currently active config.
142
- func configFileKey () (string , error ) {
143
- configPath , err := dockercfg .ConfigPath ()
141
+ func configKey (cfg dockercfg.Config ) (string , error ) {
142
+ h := md5 .New ()
143
+ err := json .NewEncoder (h ).Encode (cfg )
144
144
if err != nil {
145
145
return "" , err
146
146
}
147
-
148
- f , err := os .Open (configPath )
149
- if err != nil {
150
- return "" , fmt .Errorf ("open config file: %w" , err )
151
- }
152
-
153
- defer f .Close ()
154
-
155
- h := md5 .New ()
156
- if _ , err := io .Copy (h , f ); err != nil {
157
- return "" , fmt .Errorf ("copying config file: %w" , err )
158
- }
159
-
160
147
return hex .EncodeToString (h .Sum (nil )), nil
161
148
}
162
149
@@ -165,10 +152,11 @@ func configFileKey() (string, error) {
165
152
func getDockerAuthConfigs () (map [string ]registry.AuthConfig , error ) {
166
153
cfg , err := getDockerConfig ()
167
154
if err != nil {
168
- return nil , err
155
+ // accept no configured registries since all might be accessible anonymously
156
+ return map [string ]registry.AuthConfig {}, nil
169
157
}
170
158
171
- configKey , err := configFileKey ( )
159
+ key , err := configKey ( cfg )
172
160
if err != nil {
173
161
return nil , err
174
162
}
@@ -195,7 +183,7 @@ func getDockerAuthConfigs() (map[string]registry.AuthConfig, error) {
195
183
switch {
196
184
case ac .Username == "" && ac .Password == "" :
197
185
// Look up credentials from the credential store.
198
- u , p , err := creds .Get (k , configKey )
186
+ u , p , err := creds .Get (k , key )
199
187
if err != nil {
200
188
results <- authConfigResult {err : err }
201
189
return
@@ -218,12 +206,11 @@ func getDockerAuthConfigs() (map[string]registry.AuthConfig, error) {
218
206
go func (k string ) {
219
207
defer wg .Done ()
220
208
221
- u , p , err := creds .Get (k , configKey )
209
+ u , p , err := creds .Get (k , key )
222
210
if err != nil {
223
211
results <- authConfigResult {err : err }
224
212
return
225
213
}
226
-
227
214
results <- authConfigResult {
228
215
key : k ,
229
216
cfg : registry.AuthConfig {
0 commit comments