BL6 (key codec): the catalog key's codec is meshcatalogkey, so the builder's builds package reaches no bus
meshcatalogclient imports the new package and keeps two one-line wrappers for the callers of the other parts until they move to it. Builds: design 47 G §670, §614 (wiring unchanged) Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
This commit is contained in:
@@ -5,14 +5,11 @@
|
||||
package meshcatalogclient
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
"git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogkey"
|
||||
)
|
||||
|
||||
// SourcePrefix2 opens every source fingerprint of the form.
|
||||
const SourcePrefix2 = "src2:"
|
||||
const SourcePrefix2 = meshcatalogkey.SourcePrefix2
|
||||
|
||||
// Toolchain2 is what an artifact's toolchain enters the fingerprint as (novox/hq ADR 0405 clause 7): the artifact's
|
||||
// language, the installed toolchain's version and the build module's recipe version.
|
||||
@@ -22,20 +19,8 @@ type Toolchain2 struct {
|
||||
Recipe string
|
||||
}
|
||||
|
||||
// KeyPart is a fingerprint as a key part: its 64 hex digits without the prefix, since a bus key may not hold ':'. It
|
||||
// refuses a value that is not `src2:` and 64 lowercase hex digits, a src1 fingerprint included, naming it.
|
||||
func KeyPart(fp string) (string, error) {
|
||||
part, ok := strings.CutPrefix(fp, SourcePrefix2)
|
||||
if !ok || !keys.IsHex64(part) {
|
||||
return "", fmt.Errorf("fingerprint: %q is not a fingerprint of the form, %s and 64 lowercase hex digits", fp, SourcePrefix2)
|
||||
}
|
||||
return part, nil
|
||||
}
|
||||
// KeyPart is meshcatalogkey.KeyPart, the codec of a catalog key's parts (design 47 G §670).
|
||||
func KeyPart(fp string) (string, error) { return meshcatalogkey.KeyPart(fp) }
|
||||
|
||||
// ParseKeyPart is the inverse of KeyPart. It refuses a part that is not 64 lowercase hex digits, naming it.
|
||||
func ParseKeyPart(part string) (string, error) {
|
||||
if !keys.IsHex64(part) {
|
||||
return "", fmt.Errorf("fingerprint: %q is not the key part of a fingerprint, 64 lowercase hex digits", part)
|
||||
}
|
||||
return SourcePrefix2 + part, nil
|
||||
}
|
||||
// ParseKeyPart is meshcatalogkey.ParseKeyPart.
|
||||
func ParseKeyPart(part string) (string, error) { return meshcatalogkey.ParseKeyPart(part) }
|
||||
|
||||
@@ -3,6 +3,7 @@ module git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient
|
||||
go 1.26.0
|
||||
|
||||
require (
|
||||
git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogkey v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-sdk/go v0.0.0-00010101000000-000000000000
|
||||
)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
module git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogkey
|
||||
|
||||
go 1.26.0
|
||||
|
||||
require git.novox.be/novox/mesh-sdk/go v0.0.0-00010101000000-000000000000
|
||||
@@ -0,0 +1,32 @@
|
||||
// Package meshcatalogkey is the codec of a catalog key's parts (design 47 G §670): a fingerprint as the part of a bus
|
||||
// key, and back. It imports neither mesh-sdk's views nor the bus client, so a package that only reads and writes keys
|
||||
// (the builder's builds package) reaches no bus; meshcatalogclient imports it.
|
||||
package meshcatalogkey
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/keys"
|
||||
)
|
||||
|
||||
// SourcePrefix2 is the prefix of a fingerprint of the current form.
|
||||
const SourcePrefix2 = "src2:"
|
||||
|
||||
// KeyPart is a fingerprint as a key part: its 64 hex digits without the prefix, since a bus key may not hold ':'. It
|
||||
// refuses a value that is not `src2:` and 64 lowercase hex digits, a src1 fingerprint included, naming it.
|
||||
func KeyPart(fp string) (string, error) {
|
||||
part, ok := strings.CutPrefix(fp, SourcePrefix2)
|
||||
if !ok || !keys.IsHex64(part) {
|
||||
return "", fmt.Errorf("fingerprint: %q is not a fingerprint of the form, %s and 64 lowercase hex digits", fp, SourcePrefix2)
|
||||
}
|
||||
return part, nil
|
||||
}
|
||||
|
||||
// ParseKeyPart is the inverse of KeyPart. It refuses a part that is not 64 lowercase hex digits, naming it.
|
||||
func ParseKeyPart(part string) (string, error) {
|
||||
if !keys.IsHex64(part) {
|
||||
return "", fmt.Errorf("fingerprint: %q is not the key part of a fingerprint, 64 lowercase hex digits", part)
|
||||
}
|
||||
return SourcePrefix2 + part, nil
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package meshcatalogkey
|
||||
|
||||
import (
|
||||
"go/build"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestKeyPartRoundTripsAndRefusesOthers(t *testing.T) {
|
||||
fp := "src2:" + strings.Repeat("a", 64)
|
||||
part, err := KeyPart(fp)
|
||||
if err != nil || part != strings.Repeat("a", 64) {
|
||||
t.Fatalf("KeyPart = %q, %v", part, err)
|
||||
}
|
||||
if back, err := ParseKeyPart(part); err != nil || back != fp {
|
||||
t.Fatalf("ParseKeyPart = %q, %v", back, err)
|
||||
}
|
||||
for _, bad := range []string{"src1:" + strings.Repeat("a", 64), "src2:abc", strings.Repeat("a", 64)} {
|
||||
if _, err := KeyPart(bad); err == nil {
|
||||
t.Errorf("KeyPart(%q) accepted", bad)
|
||||
}
|
||||
}
|
||||
if _, err := ParseKeyPart("abc"); err == nil {
|
||||
t.Error("ParseKeyPart(abc) accepted")
|
||||
}
|
||||
}
|
||||
|
||||
// Design 47 G §670: the package imports no bus.
|
||||
func TestThePackageImportsNoBus(t *testing.T) {
|
||||
p, err := build.ImportDir(".", 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, i := range p.Imports {
|
||||
if strings.Contains(i, "nats") || strings.Contains(i, "/views") {
|
||||
t.Errorf("meshcatalogkey imports %s", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ go 1.26.0
|
||||
|
||||
require (
|
||||
git.novox.be/novox/mesh-delivery/contracts/go/clients/containerimageregistryclient v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogkey v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-delivery/contracts/go/seats/containerimageregistry v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-delivery/contracts/go/seats/ociartifactregistry v0.0.0-00010101000000-000000000000
|
||||
git.novox.be/novox/mesh-delivery/sdk v0.0.0-00010101000000-000000000000
|
||||
|
||||
Reference in New Issue
Block a user