Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/functions/private/Get-ContextVaultKeyPair.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/functions/public/Rename-Context.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/functions/public/Set-Context.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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]) {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions src/functions/public/Vault/Reset-ContextVault.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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."
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/functions/public/Vault/Set-ContextVault.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -52,7 +56,9 @@ function Set-ContextVault {
}
}

[ContextVault]::new($vaultName, $vaultPath)
if ($PassThru) {
[ContextVault]::new($vaultName, $vaultPath)
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/ContextVaults.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ 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'
$result.Path | Should -Not -BeNullOrEmpty
}

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'
$results[1].Name | Should -Be 'test-vault3'
}

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'
Expand Down Expand Up @@ -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
Expand Down
Loading