GetResolver prepares the resolver from the environment and options
(ctx context.Context, cliContext *cli.Context)
| 56 | |
| 57 | // GetResolver prepares the resolver from the environment and options |
| 58 | func GetResolver(ctx context.Context, cliContext *cli.Context) (remotes.Resolver, error) { |
| 59 | username := cliContext.String("user") |
| 60 | var secret string |
| 61 | if i := strings.IndexByte(username, ':'); i > 0 { |
| 62 | secret = username[i+1:] |
| 63 | username = username[0:i] |
| 64 | } |
| 65 | options := docker.ResolverOptions{ |
| 66 | Tracker: PushTracker, |
| 67 | } |
| 68 | if username != "" { |
| 69 | if secret == "" { |
| 70 | fmt.Printf("Password: ") |
| 71 | |
| 72 | var err error |
| 73 | secret, err = passwordPrompt() |
| 74 | if err != nil { |
| 75 | return nil, err |
| 76 | } |
| 77 | |
| 78 | fmt.Print("\n") |
| 79 | } |
| 80 | } else if rt := cliContext.String("refresh"); rt != "" { |
| 81 | secret = rt |
| 82 | } |
| 83 | |
| 84 | hostOptions := config.HostOptions{} |
| 85 | hostOptions.Credentials = func(host string) (string, string, error) { |
| 86 | // If host doesn't match... |
| 87 | // Only one host |
| 88 | return username, secret, nil |
| 89 | } |
| 90 | if cliContext.Bool("plain-http") { |
| 91 | hostOptions.DefaultScheme = "http" |
| 92 | } |
| 93 | defaultTLS, err := resolverDefaultTLS(cliContext) |
| 94 | if err != nil { |
| 95 | return nil, err |
| 96 | } |
| 97 | hostOptions.DefaultTLS = defaultTLS |
| 98 | if hostDir := cliContext.String("hosts-dir"); hostDir != "" { |
| 99 | hostOptions.HostDir = config.HostDirFromRoot(hostDir) |
| 100 | } |
| 101 | |
| 102 | if cliContext.Bool("http-dump") { |
| 103 | hostOptions.UpdateClient = func(client *http.Client) error { |
| 104 | httpdbg.DumpRequests(ctx, client, nil) |
| 105 | return nil |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | options.Hosts = config.ConfigureHosts(ctx, hostOptions) |
| 110 | |
| 111 | return docker.NewResolver(options), nil |
| 112 | } |
| 113 | |
| 114 | func resolverDefaultTLS(cliContext *cli.Context) (*tls.Config, error) { |
| 115 | tlsConfig := &tls.Config{} |
no test coverage detected
searching dependent graphs…