Files
elysium/Update-KHDB.ps1
T
tomas.kracmar dabf543360 refactor(Update-KHDB): move the updater into the module as Update-ElysiumKhdb
First root script converted to a module cmdlet. Behavior is unchanged;
the code moves mostly verbatim:

- Update-KHDB (the function) -> src/Elysium/Public/Update-ElysiumKhdb.ps1,
  exported, with comment-based help and [CmdletBinding()]. It now sets
  TLS 1.2 itself, since the module may be imported without the script.
- Manifest/shard/merge/validation helpers -> Private/Khdb.ps1.
- HTTP download helpers (Azure SAS, native SigV4 S3, retry) ->
  Private/Storage.ps1; Get-BooleanSetting -> Private/Settings.ps1.
- The per-script Start/Stop-*Transcript pair -> one shared
  Start/Stop-ElysiumTranscript in Private/Transcript.ps1 (the other
  scripts switch to it as they are converted).
- $scriptRoot becomes $InstallRoot: the repo root in both the module
  (two levels above src/Elysium) and the Elysium.Common.ps1 loader.
  Settings, KHDB and Reports stay where they are for now.

Update-KHDB.ps1 is now a thin wrapper: relaunch under pwsh as before,
import the module from src/Elysium, call Update-ElysiumKhdb with the
bound parameters. The menu and direct invocations are unchanged.

Tests: manifest validation, out-of-order merge, empty KHDB, and an
end-to-end Update-ElysiumKhdb run against a fake Azure container with
only Invoke-DownloadWithRetry mocked - first sync (case and HASH:count
normalization, ordered merge), no-op second run (manifest only), one
changed shard plus removal of a shard the manifest no longer lists.
14/14 Pester tests pass. Separately, the wrapper ran the real HTTP
code against a local stand-in for an S3-compatible endpoint, on both
the serial and the PowerShell 7 parallel path (helpers injected into
runspaces from module scope), and produced the same merged KHDB.
2026-11-04 11:54:03 +01:00

46 lines
1.7 KiB
PowerShell

##################################################
## ____ ___ ____ _____ _ _ _____ _____ ##
## / ___/ _ \| _ \| ____| | \ | | ____|_ _| ##
## | | | | | | |_) | _| | \| | _| | | ##
## | |__| |_| | _ <| |___ _| |\ | |___ | | ##
## \____\__\_\_| \_\_____(_)_| \_|_____| |_| ##
##################################################
## Project: Elysium ##
## File: Update-KHDB.ps1 ##
## Support: support@cqre.net ##
##################################################
<#
.SYNOPSIS
Known-hashes database updater for the Elysium AD password testing tool.
.DESCRIPTION
Downloads a sharded KHDB manifest, performs incremental shard updates, validates
checksums, and atomically refreshes the merged khdb.txt for downstream scripts.
Supports Azure Blob Storage (via SAS) and S3-compatible endpoints (SigV4).
Thin wrapper around the Update-ElysiumKhdb cmdlet in src/Elysium, kept so existing
invocations and the menu keep working.
.PARAMETER MaxParallelTransfers
Concurrent shard downloads on PowerShell 7+ (default 5).
#>
[CmdletBinding()]
param(
[ValidateRange(1, 64)]
[int]$MaxParallelTransfers = 5
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
[string]$commonHelper = Join-Path -Path $PSScriptRoot -ChildPath 'Elysium.Common.ps1'
if (-not (Test-Path -LiteralPath $commonHelper)) { throw "Common helper not found at $commonHelper" }
. $commonHelper
Restart-WithPwshIfAvailable -BoundParameters $PSBoundParameters -UnboundArguments $MyInvocation.UnboundArguments
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'src/Elysium/Elysium.psd1') -Force
Update-ElysiumKhdb @PSBoundParameters
Write-Host "Script execution completed."