Skip to content

Commit

Permalink
CLeanup Get-Context
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusStorhaug committed Dec 8, 2024
1 parent 60874f1 commit e57d265
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/functions/public/Get-Context.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ filter Get-Context {

begin {
$commandName = $MyInvocation.MyCommand.Name
$indent = ((Get-PSCallStack).Count - 1) * " "
Write-Debug "$indent`[$commandName] - Start"
Write-Debug "[$commandName] - Start"
$null = Get-ContextVault
$vaultName = $script:Config.VaultName
$contextInfos = Get-ContextInfo
Expand All @@ -40,19 +39,19 @@ filter Get-Context {
process {
try {
if (-not $PSBoundParameters.ContainsKey('ID')) {
Write-Debug "$indent`Retrieving all contexts from [$vaultName]"
Write-Debug "Retrieving all contexts from [$vaultName]"
} elseif ([string]::IsNullOrEmpty($ID)) {
Write-Debug "$indent`Return 0 contexts from [$vaultName]"
Write-Debug "Return 0 contexts from [$vaultName]"
return
} elseif ($ID.Contains('*')) {
Write-Debug "$indent`Retrieving contexts like [$ID] from [$vaultName]"
Write-Debug "Retrieving contexts like [$ID] from [$vaultName]"
$contextInfos = $contextInfos | Where-Object { $_.ID -like $ID }
} else {
Write-Debug "$indent`Retrieving context [$ID] from [$vaultName]"
Write-Debug "Retrieving context [$ID] from [$vaultName]"
$contextInfos = $contextInfos | Where-Object { $_.ID -eq $ID }
}

Write-Debug "$indent`Found [$($contextInfos.Count)] contexts in [$vaultName]"
Write-Debug "Found [$($contextInfos.Count)] contexts in [$vaultName]"
$contextInfos | ForEach-Object {
$contextJson = Get-Secret -Name $_.SecretName -Vault $vaultName -AsPlainText -Verbose:$false
ConvertFrom-ContextJson -JsonString $contextJson
Expand All @@ -64,6 +63,6 @@ filter Get-Context {
}

end {
Write-Debug "$indent`[$commandName] - End"
Write-Debug "[$commandName] - End"
}
}

0 comments on commit e57d265

Please sign in to comment.