From 6bcab03ca0e741f91d5604d442a9a042574e5014 Mon Sep 17 00:00:00 2001 From: Nathan Windisch Date: Thu, 25 Jul 2024 02:45:49 +0100 Subject: [PATCH] Added specifier for the Vault to use with Get-Secret --- Functions/Connect-GraylogService.ps1 | 8 ++++---- Functions/ConvertFrom-GraylogSession.ps1 | 2 +- Functions/Initialize-GraylogServiceVault.ps1 | 6 +++--- Functions/Invoke-GraylogRequest.ps1 | 4 ++-- Functions/Test-GraylogSession.ps1 | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Functions/Connect-GraylogService.ps1 b/Functions/Connect-GraylogService.ps1 index 0d6395d..c122c90 100644 --- a/Functions/Connect-GraylogService.ps1 +++ b/Functions/Connect-GraylogService.ps1 @@ -30,10 +30,10 @@ function Connect-GraylogService { [PSCredential] $Credential ) - if ((Test-Session)) { return } # If the session is still valid, don't create a new one + if ((Test-GraylogSession -SkipSecretCheck)) { return } # If the session is still valid, don't create a new one if (-NOT $Credential) { try { - $Credential = Get-Secret Graylog_Credential -ErrorAction Stop + $Credential = Get-Secret Graylog_Credential -Vault Graylog -ErrorAction Stop } catch { try { Write-Host "The Graylog Credential secret is missing, prompting for input..." @@ -46,7 +46,7 @@ function Connect-GraylogService { } $Request = @{ Method = "POST" - URI = "$(Get-Secret Graylog_BaseURI -AsPlainText)/api/system/sessions" + URI = "$(Get-Secret Graylog_BaseURI -Vault Graylog -AsPlainText)/api/system/sessions" Body = ConvertTo-Json @{ host = $BaseURI.Authority username = $Credential.Username.Split("@")[0] @@ -59,7 +59,7 @@ function Connect-GraylogService { } # Use a regular Invoke-RestMethod for the initial sign-in request to avoid any issues with the WebSession try { $null = Invoke-RestMethod @Request } - catch { throw $_ } + catch { throw $_.Exception.Message } $GraylogSession | ConvertFrom-GraylogSession | Set-Secret Graylog_Session } diff --git a/Functions/ConvertFrom-GraylogSession.ps1 b/Functions/ConvertFrom-GraylogSession.ps1 index 4f9fe27..b3b373f 100644 --- a/Functions/ConvertFrom-GraylogSession.ps1 +++ b/Functions/ConvertFrom-GraylogSession.ps1 @@ -21,7 +21,7 @@ function ConvertFrom-GraylogSession { $InputObject ) - try { $local:Graylog_BaseURI = Get-Secret Graylog_BaseURI -AsPlainText } + try { $local:Graylog_BaseURI = Get-Secret Graylog_BaseURI -Vault Graylog -AsPlainText } catch { Initialize-ServiceVault } # $Output = @{ # Headers = $InputObject.Headers diff --git a/Functions/Initialize-GraylogServiceVault.ps1 b/Functions/Initialize-GraylogServiceVault.ps1 index 045ea5a..d505b1f 100644 --- a/Functions/Initialize-GraylogServiceVault.ps1 +++ b/Functions/Initialize-GraylogServiceVault.ps1 @@ -1,6 +1,6 @@ function Initialize-GraylogServiceVault { try { - $null = Get-SecretVault "Graylog" -ErrorAction Stop + $null = Get-SecretVault Graylog -ErrorAction Stop } catch { try { $null = Register-SecretVault "Graylog" -ModuleName "Microsoft.PowerShell.SecretStore" -ErrorAction Stop @@ -10,7 +10,7 @@ function Initialize-GraylogServiceVault { } try { - $null = Get-Secret Graylog_BaseURI -ErrorAction Stop + $null = Get-Secret Graylog_BaseURI -Vault Graylog -ErrorAction Stop } catch { try { do { @@ -29,7 +29,7 @@ function Initialize-GraylogServiceVault { } try { - $null = Get-Secret Graylog_Credential -ErrorAction Stop + $null = Get-Secret Graylog_Credential -Vault Graylog -ErrorAction Stop } catch { try { Write-Host "The Graylog Credential secret is missing, prompting for input..." diff --git a/Functions/Invoke-GraylogRequest.ps1 b/Functions/Invoke-GraylogRequest.ps1 index 193523e..b5a558f 100644 --- a/Functions/Invoke-GraylogRequest.ps1 +++ b/Functions/Invoke-GraylogRequest.ps1 @@ -49,10 +49,10 @@ function Invoke-GraylogRequest { [string] $ContentType = "application/json" ) - $Session = Get-Secret Graylog_Session Graylog -AsPlainText -ErrorAction Stop + $Session = Get-Secret Graylog_Session -Vault Graylog -AsPlainText -ErrorAction Stop $Request = @{ Method = $Method - URI = "$(Get-Secret Graylog_BaseURI -AsPlainText)/api/$($Path.TrimStart('/api'))" + URI = "$(Get-Secret Graylog_BaseURI -Vault Graylog -AsPlainText)/api/$($Path.TrimStart('/api'))" WebSession = (ConvertTo-GraylogSession $Session) ContentType = $ContentType } diff --git a/Functions/Test-GraylogSession.ps1 b/Functions/Test-GraylogSession.ps1 index fd8b2aa..8bf22b2 100644 --- a/Functions/Test-GraylogSession.ps1 +++ b/Functions/Test-GraylogSession.ps1 @@ -27,11 +27,11 @@ function Test-GraylogSession { ) if (-NOT $SkipSecretCheck) { - try { $null = Get-Secret Graylog_BaseURI -ErrorAction Stop } + try { $null = Get-Secret Graylog_BaseURI -Vault Graylog -ErrorAction Stop } catch { Write-Error "The Graylog BaseURI secret is missing, try running Initialize-GraylogServiceVault?"; return $false } - try { $null = Get-Secret Graylog_Credential -ErrorAction Stop } + try { $null = Get-Secret Graylog_Credential -Vault Graylog -ErrorAction Stop } catch { Write-Error "The Graylog Credential secret is missing, try running Initialize-GraylogServiceVault?"; return $false } - try { $null = Get-Secret Graylog_Session -ErrorAction Stop } + try { $null = Get-Secret Graylog_Session -Vault Graylog -ErrorAction Stop } catch { Write-Error "The Graylog Session secret is missing, try running Connect-GraylogService?"; return $false } if ($SkipSessionCheck) { return $true } }