Skip to content

Commit

Permalink
Ensure we are passing lists (#41)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
MariusStorhaug authored Nov 16, 2024
1 parent 379ba85 commit 92d203b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/functions/public/Context/Get-Context.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions src/functions/public/Context/Remove-Context.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
1 change: 0 additions & 1 deletion src/functions/public/ContextSetting/Set-ContextSetting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,5 @@ function Set-ContextSetting {
}
Write-Verbose "Updating context [$($contextObj.Name)] in vault [$($contextVault.Name)]"
Set-Context -Context $contextObj

}
}
5 changes: 4 additions & 1 deletion tests/Context.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down

0 comments on commit 92d203b

Please sign in to comment.