get.porter.sh/porter@v1.3.0/pkg/porter/pull.go (about)

     1  package porter
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"get.porter.sh/porter/pkg/cache"
     8  	"get.porter.sh/porter/pkg/cnab"
     9  )
    10  
    11  type BundlePullOptions struct {
    12  	Reference        string
    13  	_ref             *cnab.OCIReference
    14  	InsecureRegistry bool
    15  	Force            bool
    16  }
    17  
    18  func (b *BundlePullOptions) Validate() error {
    19  	return b.validateReference()
    20  }
    21  
    22  func (b *BundlePullOptions) GetReference() cnab.OCIReference {
    23  	if b._ref == nil {
    24  		ref, err := cnab.ParseOCIReference(b.Reference)
    25  		if err != nil {
    26  			panic(err)
    27  		}
    28  		b._ref = &ref
    29  	}
    30  	return *b._ref
    31  }
    32  
    33  func (b *BundlePullOptions) validateReference() error {
    34  	ref, err := cnab.ParseOCIReference(b.Reference)
    35  	if err != nil {
    36  		return fmt.Errorf("invalid value for --reference, specified value should be of the form REGISTRY/bundle:tag: %w", err)
    37  	}
    38  	b._ref = &ref
    39  	return nil
    40  }
    41  
    42  // PullBundle looks for a given bundle tag in the bundle cache. If it is not found, it is
    43  // pulled and stored in the cache. The path to the cached bundle is returned.
    44  func (p *Porter) PullBundle(ctx context.Context, opts BundlePullOptions) (cache.CachedBundle, error) {
    45  	resolver := BundleResolver{
    46  		Cache:    p.Cache,
    47  		Registry: p.Registry,
    48  	}
    49  	return resolver.Resolve(ctx, opts)
    50  }