Skip to content

Commit

Permalink
add reason support for document download
Browse files Browse the repository at this point in the history
  • Loading branch information
Daryl Newsholme committed Jun 17, 2024
1 parent 5725d43 commit 60389c9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
10 changes: 8 additions & 2 deletions functions/Save-PasswordStateDocument.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@
"folder"
)][string]$resourcetype = "password",
[parameter(ValueFromPipelineByPropertyName, Position = 2)][int32]$DocumentID,
[parameter(ValueFromPipelineByPropertyName, Position = 4)][string]$Path
[parameter(ValueFromPipelineByPropertyName, Position = 4)][string]$Path,
[parameter(ValueFromPipelineByPropertyName, Position = 5)][string]$Reason

)

begin {
$output = @()
}

process {
$headerreason = @{'Reason' = "$Reason" }
try {
$output += Get-PasswordStateResource `
-uri "/api/document/$($resourcetype)/$documentID" `
-extraparams @{"OutFile" = "$Path"} `
-extraparams @{
"OutFile" = "$Path"
"Headers" = $headerreason
} `
-contenttype 'multipart/form-data' `
-ErrorAction stop
}
Expand Down
3 changes: 2 additions & 1 deletion internal/functions/Get-PasswordStateResource.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ function Get-PasswordStateResource {
$params += @{"headers" = $headers }
$skipheaders = $true
}
if ($extraparams -and $null -ne $extraparams -and $skipheaders -ne $true) {
if ($extraparams) {
$extraparams.remove("headers") # headers already added dont try and add them again.
Write-Verbose "[$(Get-Date -format G)] Adding extra parameter $($extraparams.keys) $($extraparams.values)"
$params += $extraparams
}
Expand Down
6 changes: 3 additions & 3 deletions internal/functions/New-PasswordStateResource.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ function New-PasswordStateResource {
$params += @{"headers" = $headers }
$skipheaders = $true
}
if ($extraparams -and $null -ne $extraparams) {
Write-PSFMessage -Level Verbose -Message "Adding extra parameter $($extraparams.keys) $($extraparams.values)"
if ($extraparams) {
$extraparams.remove("headers") # headers already added dont try and add them again.
Write-Verbose "[$(Get-Date -format G)] Adding extra parameter $($extraparams.keys) $($extraparams.values)"
$params += $extraparams
}

if ($headers -and $skipheaders -ne $true) {
Write-PSFMessage -Level Verbose -Message "Adding API Headers only"
$params += @{"headers" = $headers }
Expand Down
3 changes: 2 additions & 1 deletion internal/functions/Remove-PasswordStateResource.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ function Remove-PasswordStateResource {
$params += @{"headers" = $headers }
$skipheaders = $true
}
if ($extraparams -and $null -ne $extraparams -and $skipheaders -ne $true) {
if ($extraparams) {
$extraparams.remove("headers") # headers already added dont try and add them again.
Write-Verbose "[$(Get-Date -format G)] Adding extra parameter $($extraparams.keys) $($extraparams.values)"
$params += $extraparams
}
Expand Down
3 changes: 2 additions & 1 deletion internal/functions/Set-PasswordStateResource.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ function Set-PasswordStateResource {
$params += @{"headers" = $headers }
$skipheaders = $true
}
if ($extraparams -and $null -ne $extraparams -and $skipheaders -ne $true) {
if ($extraparams) {
$extraparams.remove("headers") # headers already added dont try and add them again.
Write-Verbose "[$(Get-Date -format G)] Adding extra parameter $($extraparams.keys) $($extraparams.values)"
$params += $extraparams
}
Expand Down

0 comments on commit 60389c9

Please sign in to comment.