Modules/businessdev.ALbuild.Containers/Private/Format-BcRedactedText.ps1
|
function Format-BcRedactedText { <# .SYNOPSIS Redacts secret values (password/token/secret/api-key) from text before it is logged or thrown. .DESCRIPTION A failed 'docker run' otherwise surfaces the full command line - including '--env password=<clear>' and any PAT/token env values - in the exception message, job output and logs. This masks the value of any 'key=value' pair whose key looks sensitive, keeping the key visible for diagnosis (e.g. 'password=***'). Null/empty safe; returns the input unchanged when nothing matches. #> [CmdletBinding()] [OutputType([string])] param([Parameter(Position = 0)] [AllowNull()] [AllowEmptyString()] [string] $Text) if ([string]::IsNullOrEmpty($Text)) { return $Text } return [regex]::Replace($Text, '(?i)\b(password|passwd|pwd|pat|token|secret|apikey|api-key|accesskey)=\S+', '$1=***') } |