| 1 |
package alltransports |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"strings" |
| 6 |
|
| 7 |
"go.podman.io/image/v5/transports" |
| 8 |
"go.podman.io/image/v5/types" |
| 9 |
|
| 10 |
// Register all known transports. |
| 11 |
// NOTE: Make sure docs/containers-transports.5.md and docs/containers-policy.json.5.md are updated when adding or updating |
| 12 |
// a transport. |
| 13 |
_ "go.podman.io/image/v5/directory" |
| 14 |
_ "go.podman.io/image/v5/docker" |
| 15 |
_ "go.podman.io/image/v5/docker/archive" |
| 16 |
_ "go.podman.io/image/v5/oci/archive" |
| 17 |
_ "go.podman.io/image/v5/oci/layout" |
| 18 |
_ "go.podman.io/image/v5/openshift" |
| 19 |
_ "go.podman.io/image/v5/sif" |
| 20 |
_ "go.podman.io/image/v5/tarball" |
| 21 |
// The docker-daemon transport is registeredy by docker_daemon*.go |
| 22 |
// The storage transport is registered by storage*.go |
| 23 |
) |
| 24 |
|
| 25 |
func init() { |
| 26 |
transports.Register(transports.NewStubTransport("ostree")) // This transport was completely removed. |
| 27 |
} |
| 28 |
|
| 29 |
// ParseImageName converts a URL-like image name to a types.ImageReference. |
| 30 |
func ParseImageName(imgName string) (types.ImageReference, error) { |
| 31 |
// Keep this in sync with TransportFromImageName! |
| 32 |
transportName, withinTransport, valid := strings.Cut(imgName, ":") |
| 33 |
if !valid { |
| 34 |
return nil, fmt.Errorf(`Invalid image name %q, expected colon-separated transport:reference`, imgName) |
| 35 |
} |
| 36 |
transport := transports.Get(transportName) |
| 37 |
if transport == nil { |
| 38 |
return nil, fmt.Errorf(`Invalid image name %q, unknown transport %q`, imgName, transportName) |
| 39 |
} |
| 40 |
return transport.ParseReference(withinTransport) |
| 41 |
} |
| 42 |
|
| 43 |
// TransportFromImageName converts an URL-like name to a types.ImageTransport or nil when |
| 44 |
// the transport is unknown or when the input is invalid. |
| 45 |
func TransportFromImageName(imageName string) types.ImageTransport { |
| 46 |
// Keep this in sync with ParseImageName! |
| 47 |
transportName, _, valid := strings.Cut(imageName, ":") |
| 48 |
if valid { |
| 49 |
return transports.Get(transportName) |
| 50 |
} |
| 51 |
return nil |
| 52 |
} |