Returns the 'Basic' credential as a header for pulling an image from a registry, if the host of the image's repository exists in the docker config file, or empty if there is none.
| 393 | // from a registry, if the host of the image's repository exists in |
| 394 | // the docker config file, or empty if there is none. |
| 395 | static http::Headers getAuthHeaderBasic( |
| 396 | const URI& uri, |
| 397 | const hashmap<string, spec::Config::Auth>& auths) |
| 398 | { |
| 399 | http::Headers headers; |
| 400 | |
| 401 | // NOTE: The host field of uri can be either domain or IP |
| 402 | // address, which is merged in docker registry puller. |
| 403 | const string registry = uri.has_port() |
| 404 | ? uri.host() + ":" + stringify(uri.port()) |
| 405 | : uri.host(); |
| 406 | |
| 407 | foreachpair (const string& key, const spec::Config::Auth& value, auths) { |
| 408 | // Handle domains including 'docker.io' as a special case, |
| 409 | // because the url is set differently for different version |
| 410 | // of docker default registry, but all of them should depend |
| 411 | // on the same default namespace 'docker.io'. Please see: |
| 412 | // https://github.com/docker/docker/blob/master/registry/config.go#L34 |
| 413 | const bool isDocker = |
| 414 | strings::contains(uri.host(), "docker.io") && |
| 415 | strings::contains(key, "docker.io"); |
| 416 | |
| 417 | // Should not use 'http::URL::parse()' here, since many |
| 418 | // registry domain recorded in docker config file does |
| 419 | // not start with 'https://' or 'http://'. They are pure |
| 420 | // domain only (e.g., 'quay.io', 'localhost:5000'). |
| 421 | // Please see 'ResolveAuthConfig()' in: |
| 422 | // https://github.com/docker/docker/blob/master/registry/auth.go |
| 423 | if (isDocker || (registry == spec::parseAuthUrl(key))) { |
| 424 | if (value.has_auth()) { |
| 425 | headers["Authorization"] = "Basic " + value.auth(); |
| 426 | break; |
| 427 | } |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | return headers; |
| 432 | } |
| 433 | |
| 434 | |
| 435 | static http::Headers getAuthHeaderBearer( |