diff --git a/src/functions/public/Context/Get-Context.ps1 b/src/functions/public/Context/Get-Context.ps1 index 8afcc9b..7c065d5 100644 --- a/src/functions/public/Context/Get-Context.ps1 +++ b/src/functions/public/Context/Get-Context.ps1 @@ -30,7 +30,7 @@ filter Get-Context { Get all contexts that match the pattern 'My*' from the vault. #> - [OutputType([hashtable[]])] + [OutputType([hashtable])] [CmdletBinding()] param( # The name of the context to retrieve from the vault. Supports wildcard patterns. @@ -55,11 +55,9 @@ filter Get-Context { $contexts = Get-SecretInfo -Vault $contextVault.Name | Where-Object { $_.Name -like "$Name" } Write-Verbose "Found [$($contexts.Count)] contexts in context vault [$($contextVault.Name)]" - $contextList = @() foreach ($context in $contexts) { - $contextList += Get-Secret -Name $context.Name -Vault $contextVault.Name -AsPlainText:$AsPlainText + Get-Secret -Name $context.Name -Vault $contextVault.Name -AsPlainText:$AsPlainText } - $contextList } Register-ArgumentCompleter -CommandName Get-Context -ParameterName Name -ScriptBlock { diff --git a/src/functions/public/Context/Remove-Context.ps1 b/src/functions/public/Context/Remove-Context.ps1 index 66b12f4..7a70415 100644 --- a/src/functions/public/Context/Remove-Context.ps1 +++ b/src/functions/public/Context/Remove-Context.ps1 @@ -50,8 +50,10 @@ filter Remove-Context { ) $contextVault = Get-ContextVault - - $contexts = Get-Context -Name $Name -AsPlainText + $contexts = [System.Collections.Generic.List[hashtable]]::new() + Get-Context -Name $Name -AsPlainText | ForEach-Object { + $contexts.Add($_) + } Write-Verbose "Removing [$($contexts.count)] contexts from vault [$($contextVault.Name)]" foreach ($context in $contexts) { diff --git a/src/functions/public/ContextSetting/Remove-ContextSetting.ps1 b/src/functions/public/ContextSetting/Remove-ContextSetting.ps1 index dbcf5b3..b52125b 100644 --- a/src/functions/public/ContextSetting/Remove-ContextSetting.ps1 +++ b/src/functions/public/ContextSetting/Remove-ContextSetting.ps1 @@ -53,6 +53,6 @@ filter Remove-ContextSetting { ) if ($PSCmdlet.ShouldProcess('Target', "Remove value [$Name] from context [$($contextObj.Name)]")) { - Set-ContextSetting -Name $Name -Value $null -Context $($Context) + Set-ContextSetting -Name $Name -Value $null -Context $Context } } diff --git a/src/functions/public/ContextSetting/Set-ContextSetting.ps1 b/src/functions/public/ContextSetting/Set-ContextSetting.ps1 index a6f1245..17dd501 100644 --- a/src/functions/public/ContextSetting/Set-ContextSetting.ps1 +++ b/src/functions/public/ContextSetting/Set-ContextSetting.ps1 @@ -56,6 +56,5 @@ function Set-ContextSetting { } Write-Verbose "Updating context [$($contextObj.Name)] in vault [$($contextVault.Name)]" Set-Context -Context $contextObj - } } diff --git a/tests/Context.Tests.ps1 b/tests/Context.Tests.ps1 index 2462153..9d9b81a 100644 --- a/tests/Context.Tests.ps1 +++ b/tests/Context.Tests.ps1 @@ -22,10 +22,13 @@ Describe 'Context' { $Context = @{ Name = 'Test' AccessToken = 'MySecret' | ConvertTo-SecureString -AsPlainText -Force + Expires = '2022-01-01' + Weird = 'true' } { Set-Context -Context $Context } | Should -Not -Throw - $result = Get-Context -Name 'Test' -AsPlainText + $result = @(Get-Context -Name 'Test' -AsPlainText) + $result.Count | Should -Be 1 $result | Should -Not -BeNullOrEmpty $result.AccessToken | Should -Be 'MySecret' }