Files
story/cmd/recovery-conformance/main.go
T

48 lines
1.6 KiB
Go

package main
import (
"encoding/json"
"flag"
"fmt"
"os"
"path/filepath"
"strings"
"time"
"data-terminal-cloud/internal/recoveryconformance"
)
func main() {
capturePath := flag.String("capture", "", "production-recovery-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: recovery-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 recovery capture:", err)
os.Exit(2)
}
capture, err := recoveryconformance.ParseCapture(content)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(2)
}
report := recoveryconformance.Evaluate(capture, *candidateVersion, *buildDigest, time.Now().UTC())
report.InputSHA256["recovery_capture"] = recoveryconformance.SHA256(content)
encoded, _ := json.MarshalIndent(report, "", " ")
encoded = append(encoded, '\n')
if err = os.WriteFile(*outputPath, encoded, 0o600); err != nil {
fmt.Fprintln(os.Stderr, "write recovery report:", err)
os.Exit(2)
}
fmt.Printf("production recovery conformance %s: %s\n", report.Result, *outputPath)
if report.Result != "PASS" {
os.Exit(1)
}
}