package internal import ( "fmt" "os" "path/filepath" "github.com/google/go-containerregistry/pkg/name" "edge-infra.dev/pkg/f8n/warehouse/oci" "edge-infra.dev/pkg/f8n/warehouse/oci/layout" "edge-infra.dev/pkg/f8n/warehouse/oci/remote" ) // ResolveArtifact resolves a string to an artifact. The string may be a path // to a pallet source on disk or a reference to an artifact in the local cache // or remote repository. func ResolveArtifact(p *Packer, s string) (oci.Artifact, error) { // If input is valid path on disk, try to pack it. if _, err := os.Stat(filepath.Join(p.Config.WAREHOUSEPATH, s)); err == nil { return p.Pack(s) } // Try strict validation to catch fully formed remote URLs // TODO: re-evalute pattern for referencing pallets from warehouse vs remote ref, err := name.ParseReference(s, name.StrictValidation) if err == nil { return remote.Get(ref) } // eg shoot:latest, or warehouse.local/shoot:latest tag, err := name.NewTag(s) if err == nil { l, err := layout.New(p.Config.Cache) if err != nil { return nil, err } return l.Get(tag) } return nil, fmt.Errorf("unable to resolve reference %s in local warehouse "+ "or remote registry", s) }