@@ -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,10 +124,13 @@ 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 () {
125
131
return res , nil
132
+ } else {
133
+ log .WithField ("registry" , registry ).Warn ("response was empty for CompositeAuth authenticate" )
126
134
}
127
135
}
128
136
return & Authentication {}, nil
@@ -154,6 +162,13 @@ func (ath *ECRAuthenticator) Authenticate(ctx context.Context, registry string)
154
162
return nil , nil
155
163
}
156
164
165
+ defer func () {
166
+ if err != nil {
167
+ err = fmt .Errorf ("error with ECR authenticate: %w" , err )
168
+ log .WithError (err ).WithField ("registry" , registry ).Error ("failed ECR authenticate" )
169
+ }
170
+ }()
171
+
157
172
ath .ecrAuthLock .Lock ()
158
173
defer ath .ecrAuthLock .Unlock ()
159
174
if time .Since (ath .ecrAuthLastRefreshTime ) > ecrTokenRefreshTime {
@@ -162,7 +177,8 @@ func (ath *ECRAuthenticator) Authenticate(ctx context.Context, registry string)
162
177
return nil , err
163
178
}
164
179
if len (tknout .AuthorizationData ) == 0 {
165
- return nil , fmt .Errorf ("no ECR authorization data received" )
180
+ err = fmt .Errorf ("no ECR authorization data received" )
181
+ return nil , err
166
182
}
167
183
168
184
pwd , err := base64 .StdEncoding .DecodeString (aws .ToString (tknout .AuthorizationData [0 ].AuthorizationToken ))
@@ -172,12 +188,15 @@ func (ath *ECRAuthenticator) Authenticate(ctx context.Context, registry string)
172
188
173
189
ath .ecrAuth = string (pwd )
174
190
ath .ecrAuthLastRefreshTime = time .Now ()
175
- log .Debug ("refreshed ECR token" )
191
+ log .Info ("refreshed ECR token" )
192
+ } else {
193
+ log .Info ("no ECR token refresh necessary" )
176
194
}
177
195
178
196
segs := strings .Split (ath .ecrAuth , ":" )
179
197
if len (segs ) != 2 {
180
- return nil , fmt .Errorf ("cannot understand ECR token. Expected 2 segments, got %d" , len (segs ))
198
+ err = fmt .Errorf ("cannot understand ECR token. Expected 2 segments, got %d" , len (segs ))
199
+ return nil , err
181
200
}
182
201
return & Authentication {
183
202
Username : segs [0 ],
@@ -299,6 +318,7 @@ func (a AllowedAuthFor) GetAuthFor(ctx context.Context, auth RegistryAuthenticat
299
318
300
319
ref , err := reference .ParseNormalizedNamed (refstr )
301
320
if err != nil {
321
+ log .WithError (err ).Errorf ("failed parsing normalized name" )
302
322
return nil , xerrors .Errorf ("cannot parse image ref: %v" , err )
303
323
}
304
324
reg := reference .Domain (ref )
@@ -359,6 +379,8 @@ func (a AllowedAuthFor) additionalAuth(domain string) *Authentication {
359
379
res .Username = segs [0 ]
360
380
res .Password = strings .Join (segs [1 :], ":" )
361
381
}
382
+ } else {
383
+ log .Errorf ("failed getting additional auth" )
362
384
}
363
385
return res
364
386
}
@@ -386,7 +408,7 @@ func (a AllowedAuthFor) GetImageBuildAuthFor(ctx context.Context, auth RegistryA
386
408
for _ , reg := range additionalRegistries {
387
409
ath , err := auth .Authenticate (ctx , reg )
388
410
if err != nil {
389
- log .WithError (err ).WithField ("registry" , reg ).Warn ("cannot get authentication for additioanl registry for image build" )
411
+ log .WithError (err ).WithField ("registry" , reg ).Warn ("cannot get authentication for additional registry for image build" )
390
412
continue
391
413
}
392
414
if ath .Empty () {
0 commit comments