|
8 | 8 | "path/filepath"
|
9 | 9 | "strings"
|
10 | 10 |
|
| 11 | + "github.com/docker/distribution/reference" |
11 | 12 | dockertypes "github.com/docker/docker/api/types"
|
12 | 13 | docker "github.com/fsouza/go-dockerclient"
|
13 | 14 | "k8s.io/klog"
|
@@ -87,7 +88,58 @@ func main() {
|
87 | 88 | options.TransientMounts = mounts
|
88 | 89 |
|
89 | 90 | options.Out, options.ErrOut = os.Stdout, os.Stderr
|
| 91 | + authConfigurations, err := docker.NewAuthConfigurationsFromDockerCfg() |
| 92 | + if err != nil { |
| 93 | + log.Fatalf("reading authentication configurations: %v", err) |
| 94 | + } |
| 95 | + if authConfigurations == nil { |
| 96 | + klog.V(4).Infof("No authentication secrets found") |
| 97 | + } |
| 98 | + |
90 | 99 | options.AuthFn = func(name string) ([]dockertypes.AuthConfig, bool) {
|
| 100 | + if authConfigurations != nil { |
| 101 | + if authConfig, ok := authConfigurations.Configs[name]; ok { |
| 102 | + klog.V(4).Infof("Found authentication secret for registry %q", name) |
| 103 | + return []dockertypes.AuthConfig{{ |
| 104 | + Username: authConfig.Username, |
| 105 | + Password: authConfig.Password, |
| 106 | + Email: authConfig.Email, |
| 107 | + ServerAddress: authConfig.ServerAddress, |
| 108 | + }}, true |
| 109 | + } |
| 110 | + if named, err := reference.ParseNormalizedNamed(name); err == nil { |
| 111 | + domain := reference.Domain(named) |
| 112 | + if authConfig, ok := authConfigurations.Configs[domain]; ok { |
| 113 | + klog.V(4).Infof("Found authentication secret for registry %q", domain) |
| 114 | + return []dockertypes.AuthConfig{{ |
| 115 | + Username: authConfig.Username, |
| 116 | + Password: authConfig.Password, |
| 117 | + Email: authConfig.Email, |
| 118 | + ServerAddress: authConfig.ServerAddress, |
| 119 | + }}, true |
| 120 | + } |
| 121 | + if domain == "docker.io" || strings.HasSuffix(domain, ".docker.io") { |
| 122 | + var auths []dockertypes.AuthConfig |
| 123 | + for _, aka := range []string{"docker.io", "index.docker.io", "https://index.docker.io/v1/"} { |
| 124 | + if aka == domain { |
| 125 | + continue |
| 126 | + } |
| 127 | + if authConfig, ok := authConfigurations.Configs[aka]; ok { |
| 128 | + klog.V(4).Infof("Found authentication secret for registry %q", aka) |
| 129 | + auths = append(auths, dockertypes.AuthConfig{ |
| 130 | + Username: authConfig.Username, |
| 131 | + Password: authConfig.Password, |
| 132 | + Email: authConfig.Email, |
| 133 | + ServerAddress: authConfig.ServerAddress, |
| 134 | + }) |
| 135 | + } |
| 136 | + } |
| 137 | + if len(auths) > 0 { |
| 138 | + return auths, true |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + } |
91 | 143 | return nil, false
|
92 | 144 | }
|
93 | 145 | options.LogFn = func(format string, args ...interface{}) {
|
|
0 commit comments