MCPcopy
hub / github.com/containerd/containerd / NewResolver

Function NewResolver

core/remotes/docker/resolver.go:150–206  ·  view source on GitHub ↗

NewResolver returns a new resolver to a Docker registry

(options ResolverOptions)

Source from the content-addressed store, hash-verified

148
149// NewResolver returns a new resolver to a Docker registry
150func NewResolver(options ResolverOptions) remotes.Resolver {
151 if options.Tracker == nil {
152 options.Tracker = NewInMemoryTracker()
153 }
154
155 if options.Headers == nil {
156 options.Headers = make(http.Header)
157 } else {
158 // make a copy of the headers to avoid race due to concurrent map write
159 options.Headers = options.Headers.Clone()
160 }
161
162 resolveHeader := http.Header{}
163 if _, ok := options.Headers["Accept"]; !ok {
164 // set headers for all the types we support for resolution.
165 resolveHeader.Set("Accept", strings.Join([]string{
166 images.MediaTypeDockerSchema2Manifest,
167 images.MediaTypeDockerSchema2ManifestList,
168 ocispec.MediaTypeImageManifest,
169 ocispec.MediaTypeImageIndex, "*/*",
170 }, ", "))
171 } else {
172 resolveHeader["Accept"] = options.Headers["Accept"]
173 delete(options.Headers, "Accept")
174 }
175
176 if options.Hosts == nil {
177 opts := []RegistryOpt{}
178 if options.Host != nil {
179 opts = append(opts, WithHostTranslator(options.Host))
180 }
181
182 if options.Authorizer == nil {
183 options.Authorizer = NewDockerAuthorizer(
184 WithAuthClient(options.Client),
185 WithAuthHeader(options.Headers),
186 WithAuthCreds(options.Credentials))
187 }
188 opts = append(opts, WithAuthorizer(options.Authorizer))
189
190 if options.Client != nil {
191 opts = append(opts, WithClient(options.Client))
192 }
193 if options.PlainHTTP {
194 opts = append(opts, WithPlainHTTP(MatchAllHosts))
195 } else {
196 opts = append(opts, WithPlainHTTP(MatchLocalhost))
197 }
198 options.Hosts = ConfigureDefaultRegistries(opts...)
199 }
200 return &dockerResolver{
201 hosts: options.Hosts,
202 header: options.Headers,
203 resolveHeader: resolveHeader,
204 tracker: options.Tracker,
205 }
206}
207

Callers 15

defaultRemoteContextFunction · 0.92
runBasicTestFunction · 0.92
NewOCIRegistryFunction · 0.92
UnmarshalAnyMethod · 0.92
GetResolverFunction · 0.92
TestBadTokenResolverFunction · 0.85
TestResolveProxyFunction · 0.85
TestResolveProxyFallbackFunction · 0.85
runBasicTestFunction · 0.85

Calls 11

NewInMemoryTrackerFunction · 0.85
WithHostTranslatorFunction · 0.85
NewDockerAuthorizerFunction · 0.85
WithAuthClientFunction · 0.85
WithAuthHeaderFunction · 0.85
WithAuthCredsFunction · 0.85
WithAuthorizerFunction · 0.85
WithClientFunction · 0.85
WithPlainHTTPFunction · 0.85
SetMethod · 0.65

Tested by 12

runBasicTestFunction · 0.74
TestBadTokenResolverFunction · 0.68
TestResolveProxyFunction · 0.68
TestResolveProxyFallbackFunction · 0.68
runBasicTestFunction · 0.68
runNotFoundTestFunction · 0.68
runReferrersTestFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…