@@ -13,6 +13,7 @@ import (
13
13
"github.com/google/go-containerregistry/pkg/name"
14
14
v1 "github.com/google/go-containerregistry/pkg/v1"
15
15
"github.com/google/go-containerregistry/pkg/v1/remote"
16
+ "github.com/sirupsen/logrus"
16
17
)
17
18
18
19
type DockerConfig struct {
@@ -25,7 +26,12 @@ type RegistryAuth struct {
25
26
Token string `json:"auth"`
26
27
}
27
28
28
- func NewFromRemote (ctx context.Context , imageName string , option types.ImageOptions ) (ImageWithIndex , error ) {
29
+ func NewFromRemote (
30
+ ctx context.Context ,
31
+ log logrus.FieldLogger ,
32
+ imageName string ,
33
+ option types.ImageOptions ,
34
+ ) (ImageWithIndex , error ) {
29
35
var nameOpts []name.Option
30
36
if option .RegistryOptions .Insecure {
31
37
nameOpts = append (nameOpts , name .Insecure )
@@ -35,14 +41,20 @@ func NewFromRemote(ctx context.Context, imageName string, option types.ImageOpti
35
41
return nil , fmt .Errorf ("failed to parse the image name: %w" , err )
36
42
}
37
43
38
- img , err := tryRemote (ctx , imageName , ref , option )
44
+ img , err := tryRemote (ctx , log , imageName , ref , option )
39
45
if err != nil {
40
46
return nil , err
41
47
}
42
48
return img , nil
43
49
}
44
50
45
- func tryRemote (ctx context.Context , imageName string , ref name.Reference , option types.ImageOptions ) (ImageWithIndex , error ) {
51
+ func tryRemote (
52
+ ctx context.Context ,
53
+ log logrus.FieldLogger ,
54
+ imageName string ,
55
+ ref name.Reference ,
56
+ option types.ImageOptions ,
57
+ ) (ImageWithIndex , error ) {
46
58
remoteOpts := []remote.Option {
47
59
remote .WithContext (ctx ),
48
60
}
@@ -55,20 +67,26 @@ func tryRemote(ctx context.Context, imageName string, ref name.Reference, option
55
67
56
68
// Username/Password based auth.
57
69
if len (option .RegistryOptions .Credentials ) > 0 {
70
+ log .Info ("using basic authentication to pull an image" )
58
71
for _ , cred := range option .RegistryOptions .Credentials {
59
72
remoteOpts = append (remoteOpts , remote .WithAuth (& authn.Basic {
60
73
Username : cred .Username ,
61
74
Password : cred .Password ,
62
75
}))
63
76
}
64
77
} else {
78
+ log .Info ("using other authentication to pull an image" )
65
79
domain := ref .Context ().RegistryStr ()
66
80
auth := registry .GetToken (ctx , domain , option .RegistryOptions )
67
81
if auth .Username != "" && auth .Password != "" {
82
+ log .Info ("using cloud provider registry token to pull an image" )
68
83
remoteOpts = append (remoteOpts , remote .WithAuth (& auth ))
69
84
} else if option .RegistryOptions .RegistryToken != "" {
85
+ log .Info ("using bearer token to pull an image" )
70
86
bearer := authn.Bearer {Token : option .RegistryOptions .RegistryToken }
71
87
remoteOpts = append (remoteOpts , remote .WithAuth (& bearer ))
88
+ } else {
89
+ log .Info ("not using authentication to pull an image after all" )
72
90
}
73
91
}
74
92
0 commit comments