Skip to content

Commit 8c08198

Browse files
author
Stuart Padley
committed
Mask password if in connection string
1 parent fb62f3c commit 8c08198

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

AgentMode/.github/tsql/inner-loop/Publish.ps1

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,19 @@ if (!(Test-Path $sourceFile)) {
2020

2121
# Print the source file path
2222
Write-Host "Source file: $sourceFile"
23-
# Run SqlPackage.exe /Action:Publish /SourceFile:$SourceFile /TargetConnectionString:$targetConnectionString /p:IncludeCompositeObjects=true
24-
# Note $targetConnectionString can have $ in it
23+
24+
# Mask password in connection string for display
25+
$maskedConnectionString = $targetConnectionString -replace '(?i)(Password|Pwd)=([^;]*)', '$1=*****'
26+
27+
# Print the publish command with masked password
28+
$maskedQuotedConnectionString = '"' + $maskedConnectionString + '"'
29+
$maskedPublishCommand = "$env:USERPROFILE\.dotnet\tools\SqlPackage.exe /Action:Publish /SourceFile:$sourceFile /TargetConnectionString:$maskedQuotedConnectionString /p:IncludeCompositeObjects=true"
30+
$maskedPublishCommand = $maskedPublishCommand -replace '\$', '`$' # Escape $ in the connection string
31+
Write-Host "Running command: $maskedPublishCommand"
32+
33+
# Run the actual publish command (with real password)
2534
$publishCommand = "$env:USERPROFILE\.dotnet\tools\SqlPackage.exe /Action:Publish /SourceFile:$sourceFile /TargetConnectionString:$quotedConnectionString /p:IncludeCompositeObjects=true"
2635
$publishCommand = $publishCommand -replace '\$', '`$' # Escape $ in the connection string
27-
Write-Host "Running command: $publishCommand"
2836
Invoke-Expression $publishCommand
2937
if ($LASTEXITCODE -ne 0) {
3038
Write-Host "Failed to publish the DACPAC. Please check the output for errors."

0 commit comments

Comments
 (0)