feat: implement T01-T04 — Go module, canonical model, LDAP validator, error taxonomy
- T01: Go module (keycape), full directory skeleton, Makefile, CI workflow
- T02: spec/canonical-model.yaml with 6 entities + Go domain types
- T03: spec/ldap-schema.yaml + validator binary with structural/semantic rules
- T04: Error taxonomy — 4 stable error types, JSON format, HTTP helpers
28 tests pass, go vet clean, go build clean.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-13 01:27:54 +01:00
|
|
|
// keycape-to-keycloak migrates a KeyCape canonical snapshot to a Keycloak
|
|
|
|
|
// realm export format. Part of the NetKingdom IAM migration contract.
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2026-03-13 02:13:04 +01:00
|
|
|
"encoding/json"
|
|
|
|
|
"flag"
|
feat: implement T01-T04 — Go module, canonical model, LDAP validator, error taxonomy
- T01: Go module (keycape), full directory skeleton, Makefile, CI workflow
- T02: spec/canonical-model.yaml with 6 entities + Go domain types
- T03: spec/ldap-schema.yaml + validator binary with structural/semantic rules
- T04: Error taxonomy — 4 stable error types, JSON format, HTTP helpers
28 tests pass, go vet clean, go build clean.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-13 01:27:54 +01:00
|
|
|
"fmt"
|
|
|
|
|
"os"
|
2026-03-13 02:13:04 +01:00
|
|
|
|
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
|
|
|
|
|
|
"keycape/internal/migration/lldapexport"
|
|
|
|
|
"keycape/internal/migration/tokeycloak"
|
|
|
|
|
"keycape/internal/server/telemetry"
|
feat: implement T01-T04 — Go module, canonical model, LDAP validator, error taxonomy
- T01: Go module (keycape), full directory skeleton, Makefile, CI workflow
- T02: spec/canonical-model.yaml with 6 entities + Go domain types
- T03: spec/ldap-schema.yaml + validator binary with structural/semantic rules
- T04: Error taxonomy — 4 stable error types, JSON format, HTTP helpers
28 tests pass, go vet clean, go build clean.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-13 01:27:54 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
2026-03-13 02:13:04 +01:00
|
|
|
inputFile := flag.String("input", "", "Path to canonical-export.yaml (required)")
|
|
|
|
|
outputFile := flag.String("output", "keycloak-realm.json", "Path to write Keycloak realm import JSON")
|
|
|
|
|
realmName := flag.String("realm", "netkingdom", "Keycloak realm name")
|
|
|
|
|
issuer := flag.String("issuer", "", "OIDC issuer URL")
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
|
|
if *inputFile == "" {
|
|
|
|
|
fmt.Fprintln(os.Stderr, "keycape-to-keycloak: -input is required")
|
|
|
|
|
flag.Usage()
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data, err := os.ReadFile(*inputFile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Fprintf(os.Stderr, "keycape-to-keycloak: read %q: %v\n", *inputFile, err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var export lldapexport.ExportResult
|
|
|
|
|
if err := yaml.Unmarshal(data, &export); err != nil {
|
|
|
|
|
fmt.Fprintf(os.Stderr, "keycape-to-keycloak: parse YAML: %v\n", err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log := zerolog.New(os.Stderr).With().Timestamp().Logger()
|
|
|
|
|
em := telemetry.NewLogEmitter(log)
|
|
|
|
|
tr := tokeycloak.New(tokeycloak.Config{
|
|
|
|
|
RealmName: *realmName,
|
|
|
|
|
Issuer: *issuer,
|
|
|
|
|
}, em)
|
|
|
|
|
|
|
|
|
|
realm, err := tr.Transform(&export)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Fprintf(os.Stderr, "keycape-to-keycloak: transform: %v\n", err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Print validation report to stderr.
|
|
|
|
|
report := tr.ValidationReport(&export, realm)
|
|
|
|
|
for _, issue := range report {
|
|
|
|
|
fmt.Fprintf(os.Stderr, "WARNING: %s\n", issue)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out, err := json.MarshalIndent(realm, "", " ")
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Fprintf(os.Stderr, "keycape-to-keycloak: marshal JSON: %v\n", err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := os.WriteFile(*outputFile, out, 0o644); err != nil {
|
|
|
|
|
fmt.Fprintf(os.Stderr, "keycape-to-keycloak: write %q: %v\n", *outputFile, err)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Printf("keycape-to-keycloak: wrote %s (%d bytes)\n", *outputFile, len(out))
|
feat: implement T01-T04 — Go module, canonical model, LDAP validator, error taxonomy
- T01: Go module (keycape), full directory skeleton, Makefile, CI workflow
- T02: spec/canonical-model.yaml with 6 entities + Go domain types
- T03: spec/ldap-schema.yaml + validator binary with structural/semantic rules
- T04: Error taxonomy — 4 stable error types, JSON format, HTTP helpers
28 tests pass, go vet clean, go build clean.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-13 01:27:54 +01:00
|
|
|
}
|