Added specifier for the Vault to use with Get-Secret

This commit is contained in:
Nathan Windisch 2024-07-25 02:45:49 +01:00
parent d8f1ac024e
commit 6bcab03ca0
5 changed files with 13 additions and 13 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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..."

View File

@ -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
}

View File

@ -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 }
}