MCPcopy Create free account
hub / github.com/docker/docker-agent / OciRefToFilename

Function OciRefToFilename

pkg/reference/reference.go:9–31  ·  view source on GitHub ↗

OciRefToFilename converts an OCI reference to a safe, consistent filename Examples: - "docker.io/myorg/agent:v1" -> "docker.io_myorg_agent_v1.yaml" - "localhost:5000/test" -> "localhost_5000_test.yaml"

(ociRef string)

Source from the content-addressed store, hash-verified

7// - "docker.io/myorg/agent:v1" -> "docker.io_myorg_agent_v1.yaml"
8// - "localhost:5000/test" -> "localhost_5000_test.yaml"
9func OciRefToFilename(ociRef string) string {
10 // Replace characters that are invalid in filenames with underscores
11 // Keep the structure recognizable but filesystem-safe
12 safe := strings.NewReplacer(
13 "/", "_",
14 ":", "_",
15 "@", "_",
16 "\\", "_",
17 "*", "_",
18 "?", "_",
19 "\"", "_",
20 "<", "_",
21 ">", "_",
22 "|", "_",
23 ).Replace(ociRef)
24
25 // Ensure it has .yaml extension
26 if !strings.HasSuffix(safe, ".yaml") {
27 safe += ".yaml"
28 }
29
30 return safe
31}

Callers 3

TestOciRefToFilenameFunction · 0.92
ResolveSourcesFunction · 0.92
resolveOneFunction · 0.92

Calls

no outgoing calls

Tested by 1

TestOciRefToFilenameFunction · 0.74