Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions ScheduledTasks/DailySupportCheck/Invoke-DailySupportCheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,27 @@ function Import-KurrentDbClientAssembly {
Add-Type -Path $AssemblyPath
}

function Get-KurrentDbWriteActivityCredentials {
[CmdletBinding()]
param([Parameter(Mandatory)] [object] $Settings)

$username = $null
$password = $null
if ($Settings.PSObject.Properties['Username'] -and -not [string]::IsNullOrWhiteSpace([string] $Settings.Username)) {
$username = [string] $Settings.Username
$passwordEnvironmentVariable = [string] $Settings.PasswordEnvironmentVariable
$password = [Environment]::GetEnvironmentVariable($passwordEnvironmentVariable)
if ([string]::IsNullOrWhiteSpace($password)) {
throw "KurrentDB password environment variable '$passwordEnvironmentVariable' is not set."
}
}

[pscustomobject]@{
Username = $username
Password = $password
}
}

function Test-KurrentDbWriteActivity {
[CmdletBinding()]
param([Parameter(Mandatory)] [object] $Context)
Expand Down Expand Up @@ -769,23 +790,16 @@ function Test-KurrentDbWriteActivity {
"esdb://$($baseUri.Host):${port}?tls=false&tlsVerifyCert=false"
}

$password = $null
if ($settings.PSObject.Properties['Username'] -and -not [string]::IsNullOrWhiteSpace([string] $settings.Username)) {
$passwordEnvironmentVariable = [string] $settings.PasswordEnvironmentVariable
$password = [Environment]::GetEnvironmentVariable($passwordEnvironmentVariable)
if ([string]::IsNullOrWhiteSpace($password)) {
throw "KurrentDB password environment variable '$passwordEnvironmentVariable' is not set."
}
}
$credentials = Get-KurrentDbWriteActivityCredentials -Settings $settings

$reader = [SupportTools.KurrentDbClient.KurrentDbEventReader]::new()
$events = $reader.ReadRecentEventsAsync(
$connectionString,
$indexName,
$requestCount,
[timespan]::FromSeconds($timeoutSeconds),
[string] $settings.Username,
$password,
$credentials.Username,
$credentials.Password,
[Threading.CancellationToken]::None).GetAwaiter().GetResult()

[pscustomobject]@{ events = @($events) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
Describe 'Daily support check' {
It 'allows anonymous KurrentDB configuration without a Username property' {
$settings = [pscustomobject]@{ BaseUrl = 'http://kurrentdb' }

$credentials = Get-KurrentDbWriteActivityCredentials -Settings $settings

$credentials.Username | Should -BeNullOrEmpty
$credentials.Password | Should -BeNullOrEmpty
}

It 'uses the packaged KurrentDB client rather than a source-tree build output' {
$configurationPath = Join-Path $PSScriptRoot '..\daily-support-check.json'
$configuration = Get-Content -LiteralPath $configurationPath -Raw | ConvertFrom-Json
Expand Down
Loading