(ctx context.Context, desc ocispec.Descriptor)
| 219 | } |
| 220 | |
| 221 | func (r dockerFetcher) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.ReadCloser, error) { |
| 222 | ctx = log.WithLogger(ctx, log.G(ctx).WithField("digest", desc.Digest)) |
| 223 | |
| 224 | hosts := r.filterHosts(HostCapabilityPull) |
| 225 | if len(hosts) == 0 { |
| 226 | return nil, fmt.Errorf("no pull hosts: %w", errdefs.ErrNotFound) |
| 227 | } |
| 228 | |
| 229 | ctx, err := ContextWithRepositoryScope(ctx, r.refspec, false) |
| 230 | if err != nil { |
| 231 | return nil, err |
| 232 | } |
| 233 | |
| 234 | return newHTTPReadSeeker(desc.Size, func(offset int64) (io.ReadCloser, error) { |
| 235 | // firstly try fetch via external urls |
| 236 | for _, us := range desc.URLs { |
| 237 | u, err := url.Parse(us) |
| 238 | if err != nil { |
| 239 | log.G(ctx).WithError(err).Debugf("failed to parse %q", us) |
| 240 | continue |
| 241 | } |
| 242 | if u.Scheme != "http" && u.Scheme != "https" { |
| 243 | log.G(ctx).Debug("non-http(s) alternative url is unsupported") |
| 244 | continue |
| 245 | } |
| 246 | ctx = log.WithLogger(ctx, log.G(ctx).WithField("url", u)) |
| 247 | log.G(ctx).Info("request") |
| 248 | |
| 249 | // Try this first, parse it |
| 250 | host := RegistryHost{ |
| 251 | Client: http.DefaultClient, |
| 252 | Host: u.Host, |
| 253 | Scheme: u.Scheme, |
| 254 | Path: u.Path, |
| 255 | Capabilities: HostCapabilityPull, |
| 256 | } |
| 257 | req := r.request(host, http.MethodGet) |
| 258 | // Strip namespace from base |
| 259 | req.path = u.Path |
| 260 | if u.RawQuery != "" { |
| 261 | req.path = req.path + "?" + u.RawQuery |
| 262 | } |
| 263 | |
| 264 | rc, _, err := r.open(ctx, req, desc.MediaType, offset, false) |
| 265 | if err != nil { |
| 266 | if errdefs.IsNotFound(err) { |
| 267 | continue // try one of the other urls. |
| 268 | } |
| 269 | |
| 270 | return nil, err |
| 271 | } |
| 272 | |
| 273 | return rc, nil |
| 274 | } |
| 275 | |
| 276 | // Try manifests endpoints for manifests types |
| 277 | if images.IsManifestType(desc.MediaType) || images.IsIndexType(desc.MediaType) { |
| 278 |
nothing calls this directly
no test coverage detected