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)
| 7 | // - "docker.io/myorg/agent:v1" -> "docker.io_myorg_agent_v1.yaml" |
| 8 | // - "localhost:5000/test" -> "localhost_5000_test.yaml" |
| 9 | func 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 | } |
no outgoing calls