fix(scripts): satisfy PSScriptAnalyzer (lint gate)
Lint / pssa (push) Successful in 31s
Lint / python (push) Successful in 1m3s

- Remove-Securely: suppress PSUseShouldProcessForStateChangingFunctions
  (internal best-effort shred; ShouldProcess prompts are undesirable)
  + add [CmdletBinding()].
- Replace the two empty catch blocks (Set-CIGuestCredential.ps1,
  Test-CIGuestWinRM.ps1) with Write-Verbose so PSAvoidUsingEmptyCatchBlock
  is satisfied while keeping best-effort behavior.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Simone
2026-05-17 22:31:34 +02:00
parent 1fbe2c87cc
commit be4396ce83
2 changed files with 11 additions and 2 deletions
+8 -1
View File
@@ -115,6 +115,11 @@ function Invoke-AsSystem {
# --- Harden + shred helper for the transient secret file ------------------ # --- Harden + shred helper for the transient secret file ------------------
function Remove-Securely { function Remove-Securely {
# Best-effort cleanup helper; ShouldProcess prompting is undesirable
# for an internal shred-and-delete of our own temp file.
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions', '')]
[CmdletBinding()]
param([Parameter(Mandatory)] [string] $Path) param([Parameter(Mandatory)] [string] $Path)
if (-not (Test-Path -LiteralPath $Path)) { return } if (-not (Test-Path -LiteralPath $Path)) { return }
try { try {
@@ -124,7 +129,9 @@ function Remove-Securely {
[Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($rnd) [Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($rnd)
[IO.File]::WriteAllBytes($Path, $rnd) [IO.File]::WriteAllBytes($Path, $rnd)
} }
} catch { } } catch {
Write-Verbose "secure overwrite failed (continuing to delete): $_"
}
Remove-Item -LiteralPath $Path -Force -ErrorAction SilentlyContinue Remove-Item -LiteralPath $Path -Force -ErrorAction SilentlyContinue
} }
+3 -1
View File
@@ -116,7 +116,9 @@ try {
$cn = $ssl.RemoteCertificate.Subject # e.g. "CN=WINBUILD" $cn = $ssl.RemoteCertificate.Subject # e.g. "CN=WINBUILD"
if ($cn -match 'CN=([^,]+)') { $guestCn = $Matches[1].Trim() } if ($cn -match 'CN=([^,]+)') { $guestCn = $Matches[1].Trim() }
$ssl.Dispose(); $tcpc.Close() $ssl.Dispose(); $tcpc.Close()
} catch { } } catch {
Write-Verbose "cert CN probe failed (hostname auto-detect skipped): $_"
}
if ($guestCn) { if ($guestCn) {
Write-Host " guest cert CN (hostname): $guestCn" -ForegroundColor Cyan Write-Host " guest cert CN (hostname): $guestCn" -ForegroundColor Cyan
} }