mesh/delivery-group group feat/sdk1 rejected: composed together: the checker's verdict at the members' heads (428d048dd50a): unit: git.novox.be/novox/mesh-sdk/…
mesh/delivery closed: a newer head of the same pull request
mesh/check failed: unit: git.novox.be/novox/mesh-sdk/go/process.TestStatePutWritesAKeyWhole: a Put through a short blackout: 0, mesh-mail's state send…
Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
59 lines
2.2 KiB
Go
59 lines
2.2 KiB
Go
package catalogue
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// ArtifactStoreScheme marks a reference to something in the mesh's artifact store, kept without
|
|
// the store's address.
|
|
const ArtifactStoreScheme = ArtifactStoreProvision + "://"
|
|
|
|
// Recorded is a reference as the mesh records it: the artifact store's address, if the builder wrote
|
|
// one, taken off.
|
|
//
|
|
// For a reference the builder announced — one it pushed to the store — which is the only kind
|
|
// this is called on. An image the builder named `<host>/<path>@sha256:…` is kept as its path; an
|
|
// archive it named `http://<host>/v2/<path>/blobs/<digest>` likewise. A reference with no address
|
|
// in it — an image id from a genesis build that had nowhere to publish, a package version — is
|
|
// what it was.
|
|
func Recorded(reference string) string {
|
|
if strings.HasPrefix(reference, ArtifactStoreScheme) {
|
|
return reference
|
|
}
|
|
if rest, isURL := strings.CutPrefix(reference, "http://"); isURL {
|
|
if _, path, ok := strings.Cut(rest, "/v2/"); ok && strings.Contains(path, "/blobs/") {
|
|
return ArtifactStoreScheme + path
|
|
}
|
|
return reference
|
|
}
|
|
host, path, ok := strings.Cut(reference, "/")
|
|
if !ok || !isRegistryHost(host) || !strings.Contains(path, "@sha256:") {
|
|
return reference
|
|
}
|
|
return ArtifactStoreScheme + path
|
|
}
|
|
|
|
// isRegistryHost is the runtime's own rule for reading the first component of a reference as a
|
|
// registry rather than as a namespace: it has a dot or a port in it, or it is localhost.
|
|
func isRegistryHost(component string) bool {
|
|
return component == "localhost" || strings.ContainsAny(component, ".:")
|
|
}
|
|
|
|
// InArtifactStore reports whether a reference is a kept one, and what it names there.
|
|
func InArtifactStore(reference string) (path string, kept bool) {
|
|
return strings.CutPrefix(reference, ArtifactStoreScheme)
|
|
}
|
|
|
|
// Routed is a kept reference as a machine fetches it, through the artifact store at `address`
|
|
// (host:port). A reference that is not a kept one is what it was.
|
|
func Routed(reference, address string) string {
|
|
path, kept := InArtifactStore(reference)
|
|
if !kept {
|
|
return reference
|
|
}
|
|
if strings.Contains(path, "/blobs/") {
|
|
return "http://" + address + "/v2/" + path
|
|
}
|
|
return address + "/" + path
|
|
}
|