//go:build linux package provisioner import ( "amadan.net/oficina/home/internal/operator" "github.com/go-json-experiment/json" ) type schemaTargetV2 struct { InstallationTarget SchemaProfile string `json:"schema_profile"` SchemaManifestDigest string `json:"schema_manifest_digest"` } type schemaPlanV2 struct { Version int `json:"version"` Installation string `json:"installation"` BaselineOperation string `json:"baseline_operation"` Credential schemaTargetV2 `json:"credential"` Directory schemaTargetV2 `json:"directory"` } // This decoder does not enroll, sign or persist a plan. The v1 journal refuses it. func decodeSchemaPlanV2(raw []byte) (schemaPlanV2, error) { var p schemaPlanV2 if len(raw) == 0 || len(raw) > 64<<10 || json.Unmarshal(raw, &p, json.RejectUnknownMembers(true)) != nil || p.Version != 2 { return schemaPlanV2{}, ErrRefused } old := InstallationPlan{1, p.Installation, p.BaselineOperation, p.Credential.InstallationTarget, p.Directory.InstallationTarget} if !old.valid() || !operator.CanonicalToken(p.Installation) || p.Credential.SchemaProfile != "credential-current-v1" || (p.Directory.SchemaProfile != "directory-current-v1" && p.Directory.SchemaProfile != "directory-historical-empty-v1") || !validHex(p.Credential.SchemaManifestDigest, 64) || !validHex(p.Directory.SchemaManifestDigest, 64) { return schemaPlanV2{}, ErrRefused } return p, nil }