diff --git a/README.md b/README.md index 8fe3b06..64bfe7b 100644 --- a/README.md +++ b/README.md @@ -37,5 +37,9 @@ the acquisition workflow. It accepts authenticated download references over standard input, rejects path traversal, and verifies byte sizes before files enter PrivateStash. It never prints download credentials. +For non-interactive orchestration it also accepts one UTF-8 JSON request as a +Base64 parameter. This prevents shell metacharacters in signed references from +being interpreted as commands. + No project license has been selected yet. Until that decision is recorded, the contents are not offered under an open-source license. diff --git a/scripts/materialize_private_drive_files.ps1 b/scripts/materialize_private_drive_files.ps1 index 5532772..a8af832 100644 --- a/scripts/materialize_private_drive_files.ps1 +++ b/scripts/materialize_private_drive_files.ps1 @@ -1,22 +1,20 @@ [CmdletBinding()] param( [Parameter(Mandatory = $true)] - [string]$Root + [string]$Root, + + [Parameter(Mandatory = $false)] + [string]$RequestBase64 ) $ErrorActionPreference = 'Stop' $rootPath = (Resolve-Path -LiteralPath $Root).Path $rootPrefix = $rootPath.TrimEnd([IO.Path]::DirectorySeparatorChar) + [IO.Path]::DirectorySeparatorChar -while (($line = [Console]::In.ReadLine()) -ne $null) { - if ($line -eq '__END__') { - break - } - if ([string]::IsNullOrWhiteSpace($line)) { - continue - } +function Receive-Artifact { + param([Parameter(Mandatory = $true)]$Item) - $item = $line | ConvertFrom-Json + $item = $Item if (-not $item.relative_path -or -not $item.download_url) { throw 'Each input line must contain relative_path and download_url.' } @@ -45,3 +43,19 @@ while (($line = [Console]::In.ReadLine()) -ne $null) { Write-Output ("OK`t{0}`t{1}" -f $actualSize, $item.relative_path) } + +if ($RequestBase64) { + $json = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($RequestBase64)) + Receive-Artifact -Item ($json | ConvertFrom-Json) + exit 0 +} + +while (($line = [Console]::In.ReadLine()) -ne $null) { + if ($line -eq '__END__') { + break + } + if ([string]::IsNullOrWhiteSpace($line)) { + continue + } + Receive-Artifact -Item ($line | ConvertFrom-Json) +}