Skip to content

Commit 92d203b

Browse files
Ensure we are passing lists (#41)
## Description <!-- Add your description here --> ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas
1 parent 379ba85 commit 92d203b

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

src/functions/public/Context/Get-Context.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ filter Get-Context {
3030
3131
Get all contexts that match the pattern 'My*' from the vault.
3232
#>
33-
[OutputType([hashtable[]])]
33+
[OutputType([hashtable])]
3434
[CmdletBinding()]
3535
param(
3636
# The name of the context to retrieve from the vault. Supports wildcard patterns.
@@ -55,11 +55,9 @@ filter Get-Context {
5555
$contexts = Get-SecretInfo -Vault $contextVault.Name | Where-Object { $_.Name -like "$Name" }
5656

5757
Write-Verbose "Found [$($contexts.Count)] contexts in context vault [$($contextVault.Name)]"
58-
$contextList = @()
5958
foreach ($context in $contexts) {
60-
$contextList += Get-Secret -Name $context.Name -Vault $contextVault.Name -AsPlainText:$AsPlainText
59+
Get-Secret -Name $context.Name -Vault $contextVault.Name -AsPlainText:$AsPlainText
6160
}
62-
$contextList
6361
}
6462

6563
Register-ArgumentCompleter -CommandName Get-Context -ParameterName Name -ScriptBlock {

src/functions/public/Context/Remove-Context.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ filter Remove-Context {
5050
)
5151

5252
$contextVault = Get-ContextVault
53-
54-
$contexts = Get-Context -Name $Name -AsPlainText
53+
$contexts = [System.Collections.Generic.List[hashtable]]::new()
54+
Get-Context -Name $Name -AsPlainText | ForEach-Object {
55+
$contexts.Add($_)
56+
}
5557

5658
Write-Verbose "Removing [$($contexts.count)] contexts from vault [$($contextVault.Name)]"
5759
foreach ($context in $contexts) {

src/functions/public/ContextSetting/Remove-ContextSetting.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@ filter Remove-ContextSetting {
5353
)
5454

5555
if ($PSCmdlet.ShouldProcess('Target', "Remove value [$Name] from context [$($contextObj.Name)]")) {
56-
Set-ContextSetting -Name $Name -Value $null -Context $($Context)
56+
Set-ContextSetting -Name $Name -Value $null -Context $Context
5757
}
5858
}

src/functions/public/ContextSetting/Set-ContextSetting.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,5 @@ function Set-ContextSetting {
5656
}
5757
Write-Verbose "Updating context [$($contextObj.Name)] in vault [$($contextVault.Name)]"
5858
Set-Context -Context $contextObj
59-
6059
}
6160
}

tests/Context.Tests.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ Describe 'Context' {
2222
$Context = @{
2323
Name = 'Test'
2424
AccessToken = 'MySecret' | ConvertTo-SecureString -AsPlainText -Force
25+
Expires = '2022-01-01'
26+
Weird = 'true'
2527
}
2628
{ Set-Context -Context $Context } | Should -Not -Throw
2729

28-
$result = Get-Context -Name 'Test' -AsPlainText
30+
$result = @(Get-Context -Name 'Test' -AsPlainText)
31+
$result.Count | Should -Be 1
2932
$result | Should -Not -BeNullOrEmpty
3033
$result.AccessToken | Should -Be 'MySecret'
3134
}

0 commit comments

Comments
 (0)