Phase 22: Complete release provenance
This commit is contained in:
+21
-20
@@ -56,7 +56,7 @@ def provenance_fingerprint(data):
|
||||
})
|
||||
|
||||
|
||||
def validate_migration_path(value):
|
||||
def validate_migration_path(value, *, modular=False):
|
||||
|
||||
require(
|
||||
isinstance(value, str),
|
||||
@@ -70,7 +70,17 @@ def validate_migration_path(value):
|
||||
and path.as_posix() == value
|
||||
and ".." not in path.parts
|
||||
and len(path.parts) >= 3
|
||||
and path.parts[:2] == ("database", "migrations")
|
||||
and (
|
||||
path.parts[:2] == ("database", "migrations")
|
||||
or (
|
||||
modular and len(path.parts) >= 5 and (
|
||||
(path.parts[0] == "Modules"
|
||||
and path.parts[2:4] == ("Database", "Migrations"))
|
||||
or (path.parts[0] == "modules"
|
||||
and path.parts[2:4] == ("database", "migrations"))
|
||||
)
|
||||
)
|
||||
)
|
||||
and path.suffix == ".php"
|
||||
and all(
|
||||
re.fullmatch(
|
||||
@@ -84,23 +94,14 @@ def validate_migration_path(value):
|
||||
|
||||
def validate_provenance(data):
|
||||
|
||||
require(
|
||||
isinstance(data, dict)
|
||||
and set(data) == {
|
||||
"format_version",
|
||||
"revision",
|
||||
"migrations",
|
||||
"dependencies",
|
||||
"fingerprint",
|
||||
},
|
||||
"Invalid provenance evidence structure",
|
||||
)
|
||||
|
||||
require(
|
||||
type(data["format_version"]) is int
|
||||
and data["format_version"] == 1,
|
||||
"Unsupported provenance format",
|
||||
)
|
||||
fields = {"format_version", "revision", "migrations", "dependencies", "fingerprint"}
|
||||
require(isinstance(data, dict), "Invalid provenance evidence structure")
|
||||
version = data.get("format_version")
|
||||
require(type(version) is int and version in (1, 2), "Unsupported provenance format")
|
||||
if version == 2:
|
||||
fields.add("source_tree")
|
||||
require(valid_hash(data.get("source_tree"), 64), "Invalid source tree checksum")
|
||||
require(set(data) == fields, "Invalid provenance evidence structure")
|
||||
|
||||
require(
|
||||
valid_hash(data["revision"], 40),
|
||||
@@ -120,7 +121,7 @@ def validate_provenance(data):
|
||||
|
||||
for name, digest in data["migrations"].items():
|
||||
|
||||
validate_migration_path(name)
|
||||
validate_migration_path(name, modular=version == 2)
|
||||
|
||||
require(
|
||||
valid_hash(digest, 64),
|
||||
|
||||
Reference in New Issue
Block a user