...

Source file src/edge-infra.dev/pkg/f8n/warehouse/lift/cmd/internal/artifact.go

Documentation: edge-infra.dev/pkg/f8n/warehouse/lift/cmd/internal

     1  package internal
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  
     8  	"github.com/google/go-containerregistry/pkg/name"
     9  
    10  	"edge-infra.dev/pkg/f8n/warehouse/oci"
    11  	"edge-infra.dev/pkg/f8n/warehouse/oci/layout"
    12  	"edge-infra.dev/pkg/f8n/warehouse/oci/remote"
    13  )
    14  
    15  // ResolveArtifact resolves a string to an artifact. The string may be a path
    16  // to a pallet source on disk or a reference to an artifact in the local cache
    17  // or remote repository.
    18  func ResolveArtifact(p *Packer, s string) (oci.Artifact, error) {
    19  	// If input is valid path on disk, try to pack it.
    20  	if _, err := os.Stat(filepath.Join(p.Config.WAREHOUSEPATH, s)); err == nil {
    21  		return p.Pack(s)
    22  	}
    23  
    24  	// Try strict validation to catch fully formed remote URLs
    25  	// TODO: re-evalute pattern for referencing pallets from warehouse vs remote
    26  	ref, err := name.ParseReference(s, name.StrictValidation)
    27  	if err == nil {
    28  		return remote.Get(ref)
    29  	}
    30  
    31  	// eg shoot:latest, or warehouse.local/shoot:latest
    32  	tag, err := name.NewTag(s)
    33  	if err == nil {
    34  		l, err := layout.New(p.Config.Cache)
    35  		if err != nil {
    36  			return nil, err
    37  		}
    38  		return l.Get(tag)
    39  	}
    40  
    41  	return nil, fmt.Errorf("unable to resolve reference %s in local warehouse "+
    42  		"or remote registry", s)
    43  }
    44  

View as plain text