MCPcopy Create free account
hub / github.com/containers/image / newDockerClient

Function newDockerClient

docker/docker_client.go:225–274  ·  view source on GitHub ↗

newDockerClient returns a new dockerClient instance for the given registry and reference. The reference is used to query the registry configuration and can either be a registry (e.g, "registry.com[:5000]"), a repository (e.g., "registry.com[:5000][/some/namespace]/repo"). Please note that newDocker

(sys *types.SystemContext, registry, reference string)

Source from the content-addressed store, hash-verified

223// (e.g., username and password); those must be set by callers if necessary.
224// The caller must call .Close() on the returned client when done.
225func newDockerClient(sys *types.SystemContext, registry, reference string) (*dockerClient, error) {
226 hostName := registry
227 if registry == dockerHostname {
228 registry = dockerRegistry
229 }
230 tlsClientConfig := &tls.Config{
231 CipherSuites: tlsconfig.DefaultServerAcceptedCiphers,
232 }
233
234 // It is undefined whether the host[:port] string for dockerHostname should be dockerHostname or dockerRegistry,
235 // because docker/docker does not read the certs.d subdirectory at all in that case. We use the user-visible
236 // dockerHostname here, because it is more symmetrical to read the configuration in that case as well, and because
237 // generally the UI hides the existence of the different dockerRegistry. But note that this behavior is
238 // undocumented and may change if docker/docker changes.
239 certDir, err := dockerCertDir(sys, hostName)
240 if err != nil {
241 return nil, err
242 }
243 if err := tlsclientconfig.SetupCertificates(certDir, tlsClientConfig); err != nil {
244 return nil, err
245 }
246
247 // Check if TLS verification shall be skipped (default=false) which can
248 // be specified in the sysregistriesv2 configuration.
249 skipVerify := false
250 reg, err := sysregistriesv2.FindRegistry(sys, reference)
251 if err != nil {
252 return nil, fmt.Errorf("loading registries: %w", err)
253 }
254 if reg != nil {
255 if reg.Blocked {
256 return nil, fmt.Errorf("registry %s is blocked in %s or %s", reg.Prefix, sysregistriesv2.ConfigPath(sys), sysregistriesv2.ConfigDirPath(sys))
257 }
258 skipVerify = reg.Insecure
259 }
260 tlsClientConfig.InsecureSkipVerify = skipVerify
261
262 userAgent := useragent.DefaultUserAgent
263 if sys != nil && sys.DockerRegistryUserAgent != "" {
264 userAgent = sys.DockerRegistryUserAgent
265 }
266
267 return &dockerClient{
268 sys: sys,
269 registry: registry,
270 userAgent: userAgent,
271 tlsClientConfig: tlsClientConfig,
272 reportedWarnings: set.New[string](),
273 }, nil
274}
275
276// CheckAuth validates the credentials by attempting to log into the registry
277// returns an error if an error occurred while making the http request or the status code received was 401

Callers 3

newDockerClientFromRefFunction · 0.70
CheckAuthFunction · 0.70
SearchRegistryFunction · 0.70

Calls 5

SetupCertificatesFunction · 0.92
FindRegistryFunction · 0.92
ConfigPathFunction · 0.92
ConfigDirPathFunction · 0.92
dockerCertDirFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…