update vendor

Signed-off-by: Roland.Ma <rolandma@yunify.com>
This commit is contained in:
Roland.Ma
2021-08-11 07:10:14 +00:00
parent a18f72b565
commit ea8f47c73a
2901 changed files with 269317 additions and 43103 deletions

24
vendor/github.com/deislabs/oras/pkg/oras/errors.go generated vendored Normal file
View File

@@ -0,0 +1,24 @@
package oras
import (
"errors"
"fmt"
)
// Common errors
var (
ErrResolverUndefined = errors.New("resolver undefined")
ErrEmptyDescriptors = errors.New("empty descriptors")
)
// Path validation related errors
var (
ErrDirtyPath = errors.New("dirty path")
ErrPathNotSlashSeparated = errors.New("path not slash separated")
ErrAbsolutePathDisallowed = errors.New("absolute path disallowed")
ErrPathTraversalDisallowed = errors.New("path traversal disallowed")
)
// ErrStopProcessing is used to stop processing an oras operation.
// This error only makes sense in sequential pulling operation.
var ErrStopProcessing = fmt.Errorf("stop processing")

135
vendor/github.com/deislabs/oras/pkg/oras/pull.go generated vendored Normal file
View File

@@ -0,0 +1,135 @@
package oras
import (
"context"
"sync"
orascontent "github.com/deislabs/oras/pkg/content"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/remotes"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"golang.org/x/sync/semaphore"
)
// Pull pull files from the remote
func Pull(ctx context.Context, resolver remotes.Resolver, ref string, ingester content.Ingester, opts ...PullOpt) (ocispec.Descriptor, []ocispec.Descriptor, error) {
if resolver == nil {
return ocispec.Descriptor{}, nil, ErrResolverUndefined
}
opt := pullOptsDefaults()
for _, o := range opts {
if err := o(opt); err != nil {
return ocispec.Descriptor{}, nil, err
}
}
_, desc, err := resolver.Resolve(ctx, ref)
if err != nil {
return ocispec.Descriptor{}, nil, err
}
fetcher, err := resolver.Fetcher(ctx, ref)
if err != nil {
return ocispec.Descriptor{}, nil, err
}
layers, err := fetchContent(ctx, fetcher, desc, ingester, opt)
if err != nil {
return ocispec.Descriptor{}, nil, err
}
return desc, layers, nil
}
func fetchContent(ctx context.Context, fetcher remotes.Fetcher, desc ocispec.Descriptor, ingester content.Ingester, opts *pullOpts) ([]ocispec.Descriptor, error) {
var descriptors []ocispec.Descriptor
lock := &sync.Mutex{}
picker := images.HandlerFunc(func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
if isAllowedMediaType(desc.MediaType, opts.allowedMediaTypes...) {
if opts.filterName(desc) {
lock.Lock()
defer lock.Unlock()
descriptors = append(descriptors, desc)
}
return nil, nil
}
return nil, nil
})
store := opts.contentProvideIngester
if store == nil {
store = newHybridStoreFromIngester(ingester)
}
handlers := []images.Handler{
filterHandler(opts, opts.allowedMediaTypes...),
}
handlers = append(handlers, opts.baseHandlers...)
handlers = append(handlers,
remotes.FetchHandler(store, fetcher),
picker,
images.ChildrenHandler(store),
)
handlers = append(handlers, opts.callbackHandlers...)
if err := opts.dispatch(ctx, images.Handlers(handlers...), nil, desc); err != nil {
return nil, err
}
return descriptors, nil
}
func filterHandler(opts *pullOpts, allowedMediaTypes ...string) images.HandlerFunc {
return func(ctx context.Context, desc ocispec.Descriptor) ([]ocispec.Descriptor, error) {
switch {
case isAllowedMediaType(desc.MediaType, ocispec.MediaTypeImageManifest, ocispec.MediaTypeImageIndex):
return nil, nil
case isAllowedMediaType(desc.MediaType, allowedMediaTypes...):
if opts.filterName(desc) {
return nil, nil
}
log.G(ctx).Warnf("blob no name: %v", desc.Digest)
default:
log.G(ctx).Warnf("unknown type: %v", desc.MediaType)
}
return nil, images.ErrStopHandler
}
}
func isAllowedMediaType(mediaType string, allowedMediaTypes ...string) bool {
if len(allowedMediaTypes) == 0 {
return true
}
for _, allowedMediaType := range allowedMediaTypes {
if mediaType == allowedMediaType {
return true
}
}
return false
}
// dispatchBFS behaves the same as images.Dispatch() but in sequence with breath-first search.
func dispatchBFS(ctx context.Context, handler images.Handler, weighted *semaphore.Weighted, descs ...ocispec.Descriptor) error {
for i := 0; i < len(descs); i++ {
desc := descs[i]
children, err := handler.Handle(ctx, desc)
if err != nil {
switch err := errors.Cause(err); err {
case images.ErrSkipDesc:
continue // don't traverse the children.
case ErrStopProcessing:
return nil
}
return err
}
descs = append(descs, children...)
}
return nil
}
func filterName(desc ocispec.Descriptor) bool {
name, ok := orascontent.ResolveName(desc)
return ok && len(name) > 0
}

89
vendor/github.com/deislabs/oras/pkg/oras/pull_opts.go generated vendored Normal file
View File

@@ -0,0 +1,89 @@
package oras
import (
"context"
orascontent "github.com/deislabs/oras/pkg/content"
"github.com/containerd/containerd/images"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"golang.org/x/sync/semaphore"
)
type pullOpts struct {
allowedMediaTypes []string
dispatch func(context.Context, images.Handler, *semaphore.Weighted, ...ocispec.Descriptor) error
baseHandlers []images.Handler
callbackHandlers []images.Handler
contentProvideIngester orascontent.ProvideIngester
filterName func(ocispec.Descriptor) bool
}
// PullOpt allows callers to set options on the oras pull
type PullOpt func(o *pullOpts) error
func pullOptsDefaults() *pullOpts {
return &pullOpts{
dispatch: images.Dispatch,
filterName: filterName,
}
}
// WithAllowedMediaType sets the allowed media types
func WithAllowedMediaType(allowedMediaTypes ...string) PullOpt {
return func(o *pullOpts) error {
o.allowedMediaTypes = append(o.allowedMediaTypes, allowedMediaTypes...)
return nil
}
}
// WithAllowedMediaTypes sets the allowed media types
func WithAllowedMediaTypes(allowedMediaTypes []string) PullOpt {
return func(o *pullOpts) error {
o.allowedMediaTypes = append(o.allowedMediaTypes, allowedMediaTypes...)
return nil
}
}
// WithPullByBFS opt to pull in sequence with breath-first search
func WithPullByBFS(o *pullOpts) error {
o.dispatch = dispatchBFS
return nil
}
// WithPullBaseHandler provides base handlers, which will be called before
// any pull specific handlers.
func WithPullBaseHandler(handlers ...images.Handler) PullOpt {
return func(o *pullOpts) error {
o.baseHandlers = append(o.baseHandlers, handlers...)
return nil
}
}
// WithPullCallbackHandler provides callback handlers, which will be called after
// any pull specific handlers.
func WithPullCallbackHandler(handlers ...images.Handler) PullOpt {
return func(o *pullOpts) error {
o.callbackHandlers = append(o.callbackHandlers, handlers...)
return nil
}
}
// WithContentProvideIngester opt to the provided Provider and Ingester
// for file system I/O, including caches.
func WithContentProvideIngester(store orascontent.ProvideIngester) PullOpt {
return func(o *pullOpts) error {
o.contentProvideIngester = store
return nil
}
}
// WithPullEmptyNameAllowed allows pulling blobs with empty name.
func WithPullEmptyNameAllowed() PullOpt {
return func(o *pullOpts) error {
o.filterName = func(ocispec.Descriptor) bool {
return true
}
return nil
}
}

110
vendor/github.com/deislabs/oras/pkg/oras/push.go generated vendored Normal file
View File

@@ -0,0 +1,110 @@
package oras
import (
"context"
"encoding/json"
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/remotes"
artifact "github.com/deislabs/oras/pkg/artifact"
digest "github.com/opencontainers/go-digest"
specs "github.com/opencontainers/image-spec/specs-go"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
// Push pushes files to the remote
func Push(ctx context.Context, resolver remotes.Resolver, ref string, provider content.Provider, descriptors []ocispec.Descriptor, opts ...PushOpt) (ocispec.Descriptor, error) {
if resolver == nil {
return ocispec.Descriptor{}, ErrResolverUndefined
}
if len(descriptors) == 0 {
return ocispec.Descriptor{}, ErrEmptyDescriptors
}
opt := pushOptsDefaults()
for _, o := range opts {
if err := o(opt); err != nil {
return ocispec.Descriptor{}, err
}
}
if opt.validateName != nil {
for _, desc := range descriptors {
if err := opt.validateName(desc); err != nil {
return ocispec.Descriptor{}, err
}
}
}
pusher, err := resolver.Pusher(ctx, ref)
if err != nil {
return ocispec.Descriptor{}, err
}
desc, store, err := pack(provider, descriptors, opt)
if err != nil {
return ocispec.Descriptor{}, err
}
var wrapper func(images.Handler) images.Handler
if len(opt.baseHandlers) > 0 {
wrapper = func(h images.Handler) images.Handler {
return images.Handlers(append(opt.baseHandlers, h)...)
}
}
if err := remotes.PushContent(ctx, pusher, desc, store, nil, wrapper); err != nil {
return ocispec.Descriptor{}, err
}
return desc, nil
}
//func pack(store *hybridStore, descriptors []ocispec.Descriptor, opts *pushOpts) (ocispec.Descriptor, error) {
func pack(provider content.Provider, descriptors []ocispec.Descriptor, opts *pushOpts) (ocispec.Descriptor, content.Store, error) {
store := newHybridStoreFromProvider(provider)
// Config
var config ocispec.Descriptor
if opts.config == nil {
configBytes := []byte("{}")
config = ocispec.Descriptor{
MediaType: artifact.UnknownConfigMediaType,
Digest: digest.FromBytes(configBytes),
Size: int64(len(configBytes)),
}
store.Set(config, configBytes)
} else {
config = *opts.config
}
if opts.configAnnotations != nil {
config.Annotations = opts.configAnnotations
}
if opts.configMediaType != "" {
config.MediaType = opts.configMediaType
}
// Manifest
if opts.manifest != nil {
return *opts.manifest, store, nil
}
manifest := ocispec.Manifest{
Versioned: specs.Versioned{
SchemaVersion: 2, // historical value. does not pertain to OCI or docker version
},
Config: config,
Layers: descriptors,
Annotations: opts.manifestAnnotations,
}
manifestBytes, err := json.Marshal(manifest)
if err != nil {
return ocispec.Descriptor{}, nil, err
}
manifestDescriptor := ocispec.Descriptor{
MediaType: ocispec.MediaTypeImageManifest,
Digest: digest.FromBytes(manifestBytes),
Size: int64(len(manifestBytes)),
}
store.Set(manifestDescriptor, manifestBytes)
return manifestDescriptor, store, nil
}

129
vendor/github.com/deislabs/oras/pkg/oras/push_opts.go generated vendored Normal file
View File

@@ -0,0 +1,129 @@
package oras
import (
"path/filepath"
"strings"
"github.com/containerd/containerd/images"
orascontent "github.com/deislabs/oras/pkg/content"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
)
type pushOpts struct {
config *ocispec.Descriptor
configMediaType string
configAnnotations map[string]string
manifest *ocispec.Descriptor
manifestAnnotations map[string]string
validateName func(desc ocispec.Descriptor) error
baseHandlers []images.Handler
}
func pushOptsDefaults() *pushOpts {
return &pushOpts{
validateName: ValidateNameAsPath,
}
}
// PushOpt allows callers to set options on the oras push
type PushOpt func(o *pushOpts) error
// WithConfig overrides the config - setting this will ignore WithConfigMediaType and WithConfigAnnotations
func WithConfig(config ocispec.Descriptor) PushOpt {
return func(o *pushOpts) error {
o.config = &config
return nil
}
}
// WithConfigMediaType overrides the config media type
func WithConfigMediaType(mediaType string) PushOpt {
return func(o *pushOpts) error {
o.configMediaType = mediaType
return nil
}
}
// WithConfigAnnotations overrides the config annotations
func WithConfigAnnotations(annotations map[string]string) PushOpt {
return func(o *pushOpts) error {
o.configAnnotations = annotations
return nil
}
}
// WithManifest overrides the manifest - setting this will ignore WithManifestConfigAnnotations
func WithManifest(manifest ocispec.Descriptor) PushOpt {
return func(o *pushOpts) error {
o.manifest = &manifest
return nil
}
}
// WithManifestAnnotations overrides the manifest annotations
func WithManifestAnnotations(annotations map[string]string) PushOpt {
return func(o *pushOpts) error {
o.manifestAnnotations = annotations
return nil
}
}
// WithNameValidation validates the image title in the descriptor.
// Pass nil to disable name validation.
func WithNameValidation(validate func(desc ocispec.Descriptor) error) PushOpt {
return func(o *pushOpts) error {
o.validateName = validate
return nil
}
}
// ValidateNameAsPath validates name in the descriptor as file path in order
// to generate good packages intended to be pulled using the FileStore or
// the oras cli.
// For cross-platform considerations, only unix paths are accepted.
func ValidateNameAsPath(desc ocispec.Descriptor) error {
// no empty name
path, ok := orascontent.ResolveName(desc)
if !ok || path == "" {
return orascontent.ErrNoName
}
// path should be clean
if target := filepath.ToSlash(filepath.Clean(path)); target != path {
return errors.Wrap(ErrDirtyPath, path)
}
// path should be slash-separated
if strings.Contains(path, "\\") {
return errors.Wrap(ErrPathNotSlashSeparated, path)
}
// disallow absolute path: covers unix and windows format
if strings.HasPrefix(path, "/") {
return errors.Wrap(ErrAbsolutePathDisallowed, path)
}
if len(path) > 2 {
c := path[0]
if path[1] == ':' && path[2] == '/' && ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') {
return errors.Wrap(ErrAbsolutePathDisallowed, path)
}
}
// disallow path traversal
if strings.HasPrefix(path, "../") || path == ".." {
return errors.Wrap(ErrPathTraversalDisallowed, path)
}
return nil
}
// WithPushBaseHandler provides base handlers, which will be called before
// any push specific handlers.
func WithPushBaseHandler(handlers ...images.Handler) PushOpt {
return func(o *pushOpts) error {
o.baseHandlers = append(o.baseHandlers, handlers...)
return nil
}
}

119
vendor/github.com/deislabs/oras/pkg/oras/store.go generated vendored Normal file
View File

@@ -0,0 +1,119 @@
package oras
import (
"context"
"errors"
orascontent "github.com/deislabs/oras/pkg/content"
"github.com/containerd/containerd/content"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
// ensure interface
var (
_ content.Store = &hybridStore{}
)
type hybridStore struct {
cache *orascontent.Memorystore
provider content.Provider
ingester content.Ingester
}
func newHybridStoreFromProvider(provider content.Provider) *hybridStore {
return &hybridStore{
cache: orascontent.NewMemoryStore(),
provider: provider,
}
}
func newHybridStoreFromIngester(ingester content.Ingester) *hybridStore {
return &hybridStore{
cache: orascontent.NewMemoryStore(),
ingester: ingester,
}
}
func (s *hybridStore) Set(desc ocispec.Descriptor, content []byte) {
s.cache.Set(desc, content)
}
// ReaderAt provides contents
func (s *hybridStore) ReaderAt(ctx context.Context, desc ocispec.Descriptor) (content.ReaderAt, error) {
readerAt, err := s.cache.ReaderAt(ctx, desc)
if err == nil {
return readerAt, nil
}
if s.provider != nil {
return s.provider.ReaderAt(ctx, desc)
}
return nil, err
}
// Writer begins or resumes the active writer identified by desc
func (s *hybridStore) Writer(ctx context.Context, opts ...content.WriterOpt) (content.Writer, error) {
var wOpts content.WriterOpts
for _, opt := range opts {
if err := opt(&wOpts); err != nil {
return nil, err
}
}
if isAllowedMediaType(wOpts.Desc.MediaType, ocispec.MediaTypeImageManifest, ocispec.MediaTypeImageIndex) || s.ingester == nil {
return s.cache.Writer(ctx, opts...)
}
return s.ingester.Writer(ctx, opts...)
}
// TODO: implement (needed to create a content.Store)
// TODO: do not return empty content.Info
// Abort completely cancels the ingest operation targeted by ref.
func (s *hybridStore) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) {
return content.Info{}, nil
}
// TODO: implement (needed to create a content.Store)
// Update updates mutable information related to content.
// If one or more fieldpaths are provided, only those
// fields will be updated.
// Mutable fields:
// labels.*
func (s *hybridStore) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) {
return content.Info{}, errors.New("not yet implemented: Update (content.Store interface)")
}
// TODO: implement (needed to create a content.Store)
// Walk will call fn for each item in the content store which
// match the provided filters. If no filters are given all
// items will be walked.
func (s *hybridStore) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error {
return errors.New("not yet implemented: Walk (content.Store interface)")
}
// TODO: implement (needed to create a content.Store)
// Delete removes the content from the store.
func (s *hybridStore) Delete(ctx context.Context, dgst digest.Digest) error {
return errors.New("not yet implemented: Delete (content.Store interface)")
}
// TODO: implement (needed to create a content.Store)
func (s *hybridStore) Status(ctx context.Context, ref string) (content.Status, error) {
// Status returns the status of the provided ref.
return content.Status{}, errors.New("not yet implemented: Status (content.Store interface)")
}
// TODO: implement (needed to create a content.Store)
// ListStatuses returns the status of any active ingestions whose ref match the
// provided regular expression. If empty, all active ingestions will be
// returned.
func (s *hybridStore) ListStatuses(ctx context.Context, filters ...string) ([]content.Status, error) {
return []content.Status{}, errors.New("not yet implemented: ListStatuses (content.Store interface)")
}
// TODO: implement (needed to create a content.Store)
// Abort completely cancels the ingest operation targeted by ref.
func (s *hybridStore) Abort(ctx context.Context, ref string) error {
return errors.New("not yet implemented: Abort (content.Store interface)")
}