github.com/demonoid81/containerd@v1.3.4/remotes/resolver.go (about) 1 /* 2 Copyright The containerd Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package remotes 18 19 import ( 20 "context" 21 "io" 22 23 "github.com/containerd/containerd/content" 24 ocispec "github.com/opencontainers/image-spec/specs-go/v1" 25 ) 26 27 // Resolver provides remotes based on a locator. 28 type Resolver interface { 29 // Resolve attempts to resolve the reference into a name and descriptor. 30 // 31 // The argument `ref` should be a scheme-less URI representing the remote. 32 // Structurally, it has a host and path. The "host" can be used to directly 33 // reference a specific host or be matched against a specific handler. 34 // 35 // The returned name should be used to identify the referenced entity. 36 // Dependending on the remote namespace, this may be immutable or mutable. 37 // While the name may differ from ref, it should itself be a valid ref. 38 // 39 // If the resolution fails, an error will be returned. 40 Resolve(ctx context.Context, ref string) (name string, desc ocispec.Descriptor, err error) 41 42 // Fetcher returns a new fetcher for the provided reference. 43 // All content fetched from the returned fetcher will be 44 // from the namespace referred to by ref. 45 Fetcher(ctx context.Context, ref string) (Fetcher, error) 46 47 // Pusher returns a new pusher for the provided reference 48 Pusher(ctx context.Context, ref string) (Pusher, error) 49 } 50 51 // Fetcher fetches content 52 type Fetcher interface { 53 // Fetch the resource identified by the descriptor. 54 Fetch(ctx context.Context, desc ocispec.Descriptor) (io.ReadCloser, error) 55 } 56 57 // Pusher pushes content 58 type Pusher interface { 59 // Push returns a content writer for the given resource identified 60 // by the descriptor. 61 Push(ctx context.Context, d ocispec.Descriptor) (content.Writer, error) 62 } 63 64 // FetcherFunc allows package users to implement a Fetcher with just a 65 // function. 66 type FetcherFunc func(ctx context.Context, desc ocispec.Descriptor) (io.ReadCloser, error) 67 68 // Fetch content 69 func (fn FetcherFunc) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.ReadCloser, error) { 70 return fn(ctx, desc) 71 } 72 73 // PusherFunc allows package users to implement a Pusher with just a 74 // function. 75 type PusherFunc func(ctx context.Context, desc ocispec.Descriptor) (content.Writer, error) 76 77 // Push content 78 func (fn PusherFunc) Push(ctx context.Context, desc ocispec.Descriptor) (content.Writer, error) { 79 return fn(ctx, desc) 80 }