From 76aa4a1d06148b28f5220c3e04c0d3fcca867482 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Jun 2025 17:20:35 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20-PassThru?= =?UTF-8?q?=20parameter=20to=20Set-Context=20and=20Set-ContextVault=20func?= =?UTF-8?q?tions=20for=20pipeline=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/public/Set-Context.ps1 | 12 +++++++++--- src/functions/public/Vault/Set-ContextVault.ps1 | 10 ++++++++-- tests/ContextVaults.Tests.ps1 | 6 +++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/functions/public/Set-Context.ps1 b/src/functions/public/Set-Context.ps1 index 41a09944..e9c72537 100644 --- a/src/functions/public/Set-Context.ps1 +++ b/src/functions/public/Set-Context.ps1 @@ -67,7 +67,11 @@ function Set-Context { # The name of the vault to store the context in. [Parameter(Mandatory)] [ArgumentCompleter({ Complete-ContextVaultName @args })] - [string] $Vault + [string] $Vault, + + # Pass the context through the pipeline. + [Parameter()] + [switch] $PassThru ) begin { @@ -76,7 +80,7 @@ function Set-Context { } process { - $vaultObject = Set-ContextVault -Name $Vault + $vaultObject = Set-ContextVault -Name $Vault -PassThru $vaultObject | Format-List | Out-String -Stream | ForEach-Object { Write-Verbose "[$stackPath] $_" } if ($context -is [System.Collections.IDictionary]) { @@ -119,7 +123,9 @@ function Set-Context { Set-Content -Path $contextPath -Value $content } - Get-Context -ID $ID -Vault $Vault + if ($PassThru) { + Get-Context -ID $ID -Vault $Vault + } } end { diff --git a/src/functions/public/Vault/Set-ContextVault.ps1 b/src/functions/public/Vault/Set-ContextVault.ps1 index 59e6e18f..1e74cc06 100644 --- a/src/functions/public/Vault/Set-ContextVault.ps1 +++ b/src/functions/public/Vault/Set-ContextVault.ps1 @@ -25,7 +25,11 @@ function Set-ContextVault { # The name of the vault to create or update. [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)] [ArgumentCompleter({ Complete-ContextVaultName @args })] - [string[]] $Name + [string[]] $Name, + + # Pass the context through the pipeline. + [Parameter()] + [switch] $PassThru ) begin { @@ -52,7 +56,9 @@ function Set-ContextVault { } } - [ContextVault]::new($vaultName, $vaultPath) + if ($PassThru) { + [ContextVault]::new($vaultName, $vaultPath) + } } } diff --git a/tests/ContextVaults.Tests.ps1 b/tests/ContextVaults.Tests.ps1 index fa1e0fd4..d2c4794b 100644 --- a/tests/ContextVaults.Tests.ps1 +++ b/tests/ContextVaults.Tests.ps1 @@ -38,7 +38,7 @@ Describe 'ContextVault' { } It 'Should create a new vault with a single name parameter' { - $result = Set-ContextVault -Name 'test-vault1' + $result = Set-ContextVault -Name 'test-vault1' -PassThru $result | Should -Not -BeNullOrEmpty $result | Should -BeOfType [ContextVault] $result.Name | Should -Be 'test-vault1' @@ -46,7 +46,7 @@ Describe 'ContextVault' { } It 'Should create multiple vaults from array parameter' { - $results = Set-ContextVault -Name 'test-vault2', 'test-vault3' + $results = Set-ContextVault -Name 'test-vault2', 'test-vault3' -PassThru $results | Should -HaveCount 2 $results | ForEach-Object { $_ | Should -BeOfType [ContextVault] } $results[0].Name | Should -Be 'test-vault2' @@ -54,7 +54,7 @@ Describe 'ContextVault' { } It 'Should accept pipeline input for vault creation' { - $results = 'test-pipeline1', 'test-pipeline2' | Set-ContextVault + $results = 'test-pipeline1', 'test-pipeline2' | Set-ContextVault -PassThru $results | Should -HaveCount 2 $results | ForEach-Object { $_ | Should -BeOfType [ContextVault] } $results.Name | Should -Contain 'test-pipeline1' From e3190b90d3f829b025bb5740b54511417e984aed Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Jun 2025 17:24:43 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Enable=20-PassThr?= =?UTF-8?q?u=20parameter=20for=20Set-ContextVault=20in=20pipeline=20operat?= =?UTF-8?q?ions=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/ContextVaults.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ContextVaults.Tests.ps1 b/tests/ContextVaults.Tests.ps1 index d2c4794b..c192febf 100644 --- a/tests/ContextVaults.Tests.ps1 +++ b/tests/ContextVaults.Tests.ps1 @@ -208,7 +208,7 @@ Describe 'ContextVault' { It 'Should support pipeline operations with variables' { $testVaults = @('pipeline-var1', 'pipeline-var2') - $results = $testVaults | Set-ContextVault + $results = $testVaults | Set-ContextVault -PassThru $results | Should -HaveCount 2 $getResults = Get-ContextVault -Name $testVaults From 87979157a7f4aa92431d08363faa6bc981c6c558 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 8 Jun 2025 17:30:18 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20-PassThru?= =?UTF-8?q?=20parameter=20to=20Get-ContextVaultKeyPair,=20Rename-Context,?= =?UTF-8?q?=20and=20Reset-ContextVault=20functions=20for=20pipeline=20supp?= =?UTF-8?q?ort?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions/private/Get-ContextVaultKeyPair.ps1 | 2 +- src/functions/public/Rename-Context.ps1 | 8 ++++++-- src/functions/public/Vault/Reset-ContextVault.ps1 | 8 ++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/functions/private/Get-ContextVaultKeyPair.ps1 b/src/functions/private/Get-ContextVaultKeyPair.ps1 index e3820415..9a5df636 100644 --- a/src/functions/private/Get-ContextVaultKeyPair.ps1 +++ b/src/functions/private/Get-ContextVaultKeyPair.ps1 @@ -32,7 +32,7 @@ } process { - $vaultObject = Set-ContextVault -Name $Vault + $vaultObject = Set-ContextVault -Name $Vault -PassThru $shardPath = Join-Path -Path $vaultObject.Path -ChildPath $script:Config.ShardFileName $fileShard = Get-Content -Path $shardPath $machineShard = [System.Environment]::MachineName diff --git a/src/functions/public/Rename-Context.ps1 b/src/functions/public/Rename-Context.ps1 index 87fdb1ac..abb77a85 100644 --- a/src/functions/public/Rename-Context.ps1 +++ b/src/functions/public/Rename-Context.ps1 @@ -61,7 +61,11 @@ # The name of the vault containing the context. [Parameter()] [ArgumentCompleter({ Complete-ContextVaultName @args })] - [string] $Vault + [string] $Vault, + + # Pass the context through the pipeline. + [Parameter()] + [switch] $PassThru ) begin { @@ -81,7 +85,7 @@ } if ($PSCmdlet.ShouldProcess("Renaming context '$ID' to '$NewID' in vault '$Vault'")) { - $context | Set-Context -ID $NewID -Vault $Vault + $context | Set-Context -ID $NewID -Vault $Vault -PassThru:$PassThru Remove-Context -ID $ID -Vault $Vault } } diff --git a/src/functions/public/Vault/Reset-ContextVault.ps1 b/src/functions/public/Vault/Reset-ContextVault.ps1 index dc4b6c81..f7f49618 100644 --- a/src/functions/public/Vault/Reset-ContextVault.ps1 +++ b/src/functions/public/Vault/Reset-ContextVault.ps1 @@ -29,7 +29,11 @@ # The vault object to reset. [Parameter(Mandatory, ValueFromPipeline, ParameterSetName = 'As ContextVault')] - [ContextVault[]] $InputObject + [ContextVault[]] $InputObject, + + # Pass the context through the pipeline. + [Parameter()] + [switch] $PassThru ) begin { @@ -45,7 +49,7 @@ Write-Verbose "Resetting ContextVault [$($vault.Name)] at path [$($vault.Path)]" if ($PSCmdlet.ShouldProcess("ContextVault: [$($vault.Name)]", 'Reset')) { Remove-ContextVault -Name $($vault.Name) -Confirm:$false - Set-ContextVault -Name $($vault.Name) + Set-ContextVault -Name $($vault.Name) -PassThru:$PassThru Write-Verbose "ContextVault [$($vault.Name)] reset successfully." } }