detectPropertiesHelper performs the work of detectProperties which executes it at most once.
(ctx context.Context)
| 900 | // detectPropertiesHelper performs the work of detectProperties which executes |
| 901 | // it at most once. |
| 902 | func (c *dockerClient) detectPropertiesHelper(ctx context.Context) error { |
| 903 | // We overwrite the TLS clients `InsecureSkipVerify` only if explicitly |
| 904 | // specified by the system context |
| 905 | if c.sys != nil && c.sys.DockerInsecureSkipTLSVerify != types.OptionalBoolUndefined { |
| 906 | c.tlsClientConfig.InsecureSkipVerify = c.sys.DockerInsecureSkipTLSVerify == types.OptionalBoolTrue |
| 907 | } |
| 908 | tr := tlsclientconfig.NewTransport() |
| 909 | tr.TLSClientConfig = c.tlsClientConfig |
| 910 | // if set DockerProxyURL explicitly, use the DockerProxyURL instead of system proxy |
| 911 | if c.sys != nil && c.sys.DockerProxyURL != nil { |
| 912 | tr.Proxy = http.ProxyURL(c.sys.DockerProxyURL) |
| 913 | } |
| 914 | c.client = &http.Client{Transport: tr} |
| 915 | |
| 916 | ping := func(scheme string) error { |
| 917 | pingURL, err := url.Parse(fmt.Sprintf(resolvedPingV2URL, scheme, c.registry)) |
| 918 | if err != nil { |
| 919 | return err |
| 920 | } |
| 921 | resp, err := c.makeRequestToResolvedURL(ctx, http.MethodGet, pingURL, nil, nil, -1, noAuth, nil) |
| 922 | if err != nil { |
| 923 | logrus.Debugf("Ping %s err %s (%#v)", pingURL.Redacted(), err.Error(), err) |
| 924 | return err |
| 925 | } |
| 926 | defer resp.Body.Close() |
| 927 | logrus.Debugf("Ping %s status %d", pingURL.Redacted(), resp.StatusCode) |
| 928 | if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusUnauthorized { |
| 929 | return registryHTTPResponseToError(resp) |
| 930 | } |
| 931 | c.challenges = slices.Collect(iterateAuthHeader(resp.Header)) |
| 932 | c.scheme = scheme |
| 933 | c.supportsSignatures = resp.Header.Get("X-Registry-Supports-Signatures") == "1" |
| 934 | return nil |
| 935 | } |
| 936 | err := ping("https") |
| 937 | if err != nil && c.tlsClientConfig.InsecureSkipVerify { |
| 938 | err = ping("http") |
| 939 | } |
| 940 | if err != nil { |
| 941 | err = fmt.Errorf("pinging container registry %s: %w", c.registry, err) |
| 942 | } |
| 943 | return err |
| 944 | } |
| 945 | |
| 946 | // detectProperties detects various properties of the registry. |
| 947 | // See the dockerClient documentation for members which are affected by this. |
no test coverage detected