@@ -46,6 +46,7 @@ func NewDockerConfigFileAuth(fn string) (*DockerConfigFileAuth, error) {
46
46
res .loadFromFile (fn )
47
47
})
48
48
if err != nil {
49
+ log .WithError (err ).WithField ("path" , fn ).Error ("error watching file" )
49
50
return nil , err
50
51
}
51
52
@@ -64,6 +65,7 @@ func (a *DockerConfigFileAuth) loadFromFile(fn string) (err error) {
64
65
defer func () {
65
66
if err != nil {
66
67
err = fmt .Errorf ("error loading Docker config from %s: %w" , fn , err )
68
+ log .WithError (err ).WithField ("path" , fn ).Error ("failed loading from file" )
67
69
}
68
70
}()
69
71
@@ -75,6 +77,7 @@ func (a *DockerConfigFileAuth) loadFromFile(fn string) (err error) {
75
77
_ , _ = hash .Write (cntnt )
76
78
newHash := fmt .Sprintf ("%x" , hash .Sum (nil ))
77
79
if a .hash == newHash {
80
+ log .Infof ("nothing has changed: %s" , fn )
78
81
return nil
79
82
}
80
83
@@ -91,13 +94,15 @@ func (a *DockerConfigFileAuth) loadFromFile(fn string) (err error) {
91
94
a .C = cfg
92
95
a .hash = newHash
93
96
97
+ log .Infof ("file has changed: %s" , fn )
94
98
return nil
95
99
}
96
100
97
101
// Authenticate attempts to provide an encoded authentication string for Docker registry access
98
102
func (a * DockerConfigFileAuth ) Authenticate (ctx context.Context , registry string ) (auth * Authentication , err error ) {
99
103
ac , err := a .C .GetAuthConfig (registry )
100
104
if err != nil {
105
+ log .WithError (err ).WithField ("registry" , registry ).Error ("failed DockerConfigFileAuth Authenticate" )
101
106
return nil , err
102
107
}
103
108
@@ -119,6 +124,7 @@ func (ca CompositeAuth) Authenticate(ctx context.Context, registry string) (auth
119
124
for _ , ath := range ca {
120
125
res , err := ath .Authenticate (ctx , registry )
121
126
if err != nil {
127
+ log .WithError (err ).WithField ("registry" , registry ).Errorf ("failed CompositeAuth Authenticate" )
122
128
return nil , err
123
129
}
124
130
if ! res .Empty () {
@@ -154,6 +160,13 @@ func (ath *ECRAuthenticator) Authenticate(ctx context.Context, registry string)
154
160
return nil , nil
155
161
}
156
162
163
+ defer func () {
164
+ if err != nil {
165
+ err = fmt .Errorf ("error with ECR authenticate: %w" , err )
166
+ log .WithError (err ).WithField ("registry" , registry ).Error ("failed ECR authenticate" )
167
+ }
168
+ }()
169
+
157
170
ath .ecrAuthLock .Lock ()
158
171
defer ath .ecrAuthLock .Unlock ()
159
172
if time .Since (ath .ecrAuthLastRefreshTime ) > ecrTokenRefreshTime {
@@ -162,7 +175,8 @@ func (ath *ECRAuthenticator) Authenticate(ctx context.Context, registry string)
162
175
return nil , err
163
176
}
164
177
if len (tknout .AuthorizationData ) == 0 {
165
- return nil , fmt .Errorf ("no ECR authorization data received" )
178
+ err = fmt .Errorf ("no ECR authorization data received" )
179
+ return nil , err
166
180
}
167
181
168
182
pwd , err := base64 .StdEncoding .DecodeString (aws .ToString (tknout .AuthorizationData [0 ].AuthorizationToken ))
@@ -172,12 +186,15 @@ func (ath *ECRAuthenticator) Authenticate(ctx context.Context, registry string)
172
186
173
187
ath .ecrAuth = string (pwd )
174
188
ath .ecrAuthLastRefreshTime = time .Now ()
175
- log .Debug ("refreshed ECR token" )
189
+ log .Info ("refreshed ECR token" )
190
+ } else {
191
+ log .Info ("no ECR token refresh necessary" )
176
192
}
177
193
178
194
segs := strings .Split (ath .ecrAuth , ":" )
179
195
if len (segs ) != 2 {
180
- return nil , fmt .Errorf ("cannot understand ECR token. Expected 2 segments, got %d" , len (segs ))
196
+ err = fmt .Errorf ("cannot understand ECR token. Expected 2 segments, got %d" , len (segs ))
197
+ return nil , err
181
198
}
182
199
return & Authentication {
183
200
Username : segs [0 ],
@@ -299,6 +316,7 @@ func (a AllowedAuthFor) GetAuthFor(ctx context.Context, auth RegistryAuthenticat
299
316
300
317
ref , err := reference .ParseNormalizedNamed (refstr )
301
318
if err != nil {
319
+ log .WithError (err ).Errorf ("failed parsing normalized name" )
302
320
return nil , xerrors .Errorf ("cannot parse image ref: %v" , err )
303
321
}
304
322
reg := reference .Domain (ref )
@@ -359,6 +377,8 @@ func (a AllowedAuthFor) additionalAuth(domain string) *Authentication {
359
377
res .Username = segs [0 ]
360
378
res .Password = strings .Join (segs [1 :], ":" )
361
379
}
380
+ } else {
381
+ log .Errorf ("failed getting additional auth" )
362
382
}
363
383
return res
364
384
}
@@ -386,7 +406,7 @@ func (a AllowedAuthFor) GetImageBuildAuthFor(ctx context.Context, auth RegistryA
386
406
for _ , reg := range additionalRegistries {
387
407
ath , err := auth .Authenticate (ctx , reg )
388
408
if err != nil {
389
- log .WithError (err ).WithField ("registry" , reg ).Warn ("cannot get authentication for additioanl registry for image build" )
409
+ log .WithError (err ).WithField ("registry" , reg ).Warn ("cannot get authentication for additional registry for image build" )
390
410
continue
391
411
}
392
412
if ath .Empty () {
0 commit comments