package main import ( "encoding/json" "flag" "fmt" "os" "path/filepath" "strings" "time" "data-terminal-cloud/internal/kmsrotationconformance" ) func main() { capturePath := flag.String("capture", "", "kms-rotation-capture-v1 JSON") candidateVersion := flag.String("candidate-version", "", "release candidate version") buildDigest := flag.String("build-digest", "", "sha256 immutable build digest") outputPath := flag.String("output", "", "absolute output report path") flag.Parse() if *capturePath == "" || strings.TrimSpace(*candidateVersion) == "" || strings.TrimSpace(*buildDigest) == "" || !filepath.IsAbs(*outputPath) { fmt.Fprintln(os.Stderr, "usage: kms-rotation-conformance -capture capture.json -candidate-version VERSION -build-digest sha256:... -output ABSOLUTE.json") os.Exit(2) } content, err := os.ReadFile(*capturePath) if err != nil { fmt.Fprintln(os.Stderr, "read KMS rotation capture:", err) os.Exit(2) } capture, err := kmsrotationconformance.ParseCapture(content) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(2) } report := kmsrotationconformance.Evaluate(capture, *candidateVersion, *buildDigest, time.Now().UTC()) report.InputSHA256["rotation_capture"] = kmsrotationconformance.SHA256(content) encoded, _ := json.MarshalIndent(report, "", " ") encoded = append(encoded, '\n') if err = os.WriteFile(*outputPath, encoded, 0o600); err != nil { fmt.Fprintln(os.Stderr, "write KMS rotation report:", err) os.Exit(2) } fmt.Printf("KMS rotation conformance %s: %s\n", report.Result, *outputPath) if report.Result != "PASS" { os.Exit(1) } }