|
| 1 | +param( |
| 2 | + [Parameter(Mandatory=$true)] |
| 3 | + [string]$RegistrationPath, |
| 4 | + [Parameter(Mandatory=$true)] |
| 5 | + [string]$CanonicalRoot, |
| 6 | + [string]$AddressingRulesPath, |
| 7 | + [string]$CanonicalMetaOut |
| 8 | +) |
| 9 | + |
| 10 | +if (-not$AddressingRulesPath) { |
| 11 | +$AddressingRulesPath=Join-Path$PSScriptRoot'addressing_rules.json' |
| 12 | +} |
| 13 | + |
| 14 | +$registration=Get-Content-LiteralPath $RegistrationPath-Raw |ConvertFrom-Json |
| 15 | +$rules=Get-Content-LiteralPath $AddressingRulesPath-Raw |ConvertFrom-Json |
| 16 | + |
| 17 | +if (-not$CanonicalMetaOut) { |
| 18 | +$CanonicalMetaOut=Join-Path$CanonicalRoot'canonical_meta.json' |
| 19 | +} |
| 20 | + |
| 21 | +$sha=$registration.source_sha256.ToLowerInvariant() |
| 22 | +$fanout=$sha.Substring(0,2) |
| 23 | +$canonicalDir=Join-Path$CanonicalRoot$fanout |
| 24 | +New-Item-ItemType Directory -Force -Path $canonicalDir|Out-Null |
| 25 | + |
| 26 | +$canonicalPath=Join-Path$canonicalDir ("$sha.txt") |
| 27 | +Copy-Item-LiteralPath $registration.source_path-Destination $canonicalPath-Force |
| 28 | + |
| 29 | +$meta= [ordered]@{ |
| 30 | +source_path=$registration.source_path |
| 31 | +source_sha256=$sha |
| 32 | +canonical_path= (Resolve-Path-LiteralPath $canonicalPath).Path |
| 33 | +canonical_fanout=$fanout |
| 34 | +provenance_parent= (Resolve-Path-LiteralPath $RegistrationPath).Path |
| 35 | +addressing_rule_set=$rules.rule_set_id |
| 36 | +canonicalization_anchor='CANONICALIZATION_READY' |
| 37 | +provenance_anchor='PROVENANCE_CHAIN_READY' |
| 38 | +} |
| 39 | + |
| 40 | +$metaDir=Split-Path-Parent $CanonicalMetaOut |
| 41 | +if ($metaDir) { |
| 42 | +New-Item-ItemType Directory -Force -Path $metaDir|Out-Null |
| 43 | +} |
| 44 | +$meta|ConvertTo-Json-Depth 8|Set-Content-LiteralPath $CanonicalMetaOut-Encoding utf8 |
| 45 | + |
| 46 | +Write-Output"CANONICALIZATION_READY" |
| 47 | +Write-Output"PROVENANCE_CHAIN_READY" |
0 commit comments