Files
archie/internal/domain/source/path.go
T
sam 6adbdc55a9 feat(eda): sources own signing, with UUIDv7 paths and approved unsigned option
A source is the capture endpoint: a UUIDv7 path by default or a unique
URL-safe custom path, signed by default with an Archie-generated secret
(encrypted via the bindings cipher), or unsigned after an approval.
Intake verifies X-Hub-Signature-256/X-Signature-256 against the source
secret before redaction; an unauthenticated event on a signed source is
captured but never dispatched, an event on an approved unsigned source
dispatches and is marked unsigned. The binding secret is retired; migration
0006 derives sources from existing binding and capture source strings,
moving each binding's secret onto its source. SourceStore crosses the
State Store gRPC contract. The dashboard gains a sources panel and flags
unsigned in the capture inspector, binding list and task timeline.
2026-09-24 14:26:21 +10:00

51 lines
1.2 KiB
Go

package source
import (
"crypto/rand"
"encoding/hex"
"fmt"
"github.com/google/uuid"
)
// NewPath returns a fresh UUIDv7 path: time-ordered, unguessable, and never
// colliding with another source.
func NewPath() (string, error) {
id, err := uuid.NewV7()
if err != nil {
return "", fmt.Errorf("source: generate path: %w", err)
}
return id.String(), nil
}
// NewSecret returns a fresh 32-byte HMAC secret, hex encoded.
func NewSecret() (string, error) {
var b [MinSecretLen / 2]byte
if _, err := rand.Read(b[:]); err != nil {
return "", fmt.Errorf("source: generate secret: %w", err)
}
return hex.EncodeToString(b[:]), nil
}
// ValidatePath checks a custom path is URL-safe: RFC 3986 unreserved
// characters only, so it needs no escaping, and never a dot segment.
func ValidatePath(path string) error {
if path == "" || len(path) > MaxPathLen || path == "." || path == ".." {
return ErrInvalidPath
}
for i := range len(path) {
if !unreserved(path[i]) {
return ErrInvalidPath
}
}
return nil
}
func unreserved(c byte) bool {
switch {
case 'a' <= c && c <= 'z', 'A' <= c && c <= 'Z', '0' <= c && c <= '9':
return true
}
return c == '-' || c == '.' || c == '_' || c == '~'
}