Skip to content

Commit

Permalink
use outputwarn
Browse files Browse the repository at this point in the history
  • Loading branch information
freddydk committed Dec 6, 2023
1 parent 66aafc3 commit 1775036
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 27 deletions.
8 changes: 4 additions & 4 deletions Actions/TroubleShooting/TroubleShoot.Secrets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ function CheckSecretForCommonMistakes {
if ($isJson) {
# JSON Secrets should not contain line breaks
if ($secretValue.contains("`n")) {
AddToSummary -type Warning -Message "Secret $secretName contains line breaks. JSON Secrets available to AL-Go for GitHub should be compressed JSON (i.e. NOT contain any line breaks)."
OutputWarning -Message "Secret $secretName contains line breaks. JSON Secrets available to AL-Go for GitHub should be compressed JSON (i.e. NOT contain any line breaks)."
}
# JSON Secrets properties should not contain values 3 characters or less
foreach($keyName in $json.PSObject.Properties.Name) {
if (IsPropertySecret -propertyName $keyName) {
if ($json."$keyName".Length -le 4) {
AddToSummary -type Warning -Message "JSON Secret $secretName contains properties with very short values. These values will be masked, but the secret might be indirectly exposed and might also cause issues in AL-Go for GitHub."
OutputWarning -Message "JSON Secret $secretName contains properties with very short values. These values will be masked, but the secret might be indirectly exposed and might also cause issues in AL-Go for GitHub."
}
}
}
}
else {
if ($secretValue.contains("`n")) {
AddToSummary -type Warning -Message "Secret $secretName contains line breaks. GitHub Secrets available to AL-Go for GitHub should not contain line breaks."
OutputWarning -Message "Secret $secretName contains line breaks. GitHub Secrets available to AL-Go for GitHub should not contain line breaks."
}
elseif ($secretValue.Length -le 4) {
AddToSummary -type Warning -Message "Secret $secretName has a very short value. This value will be masked, but the secret might be indirectly exposed and might also cause issues in AL-Go for GitHub."
OutputWarning -Message "Secret $secretName has a very short value. This value will be masked, but the secret might be indirectly exposed and might also cause issues in AL-Go for GitHub."
}
}
}
Expand Down
33 changes: 10 additions & 23 deletions Actions/TroubleShooting/TroubleShooting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,34 @@ $global:errors = @()
$global:warnings = @()
$global:suggestions = @()

function AddToSummary {
function OutputWarning {
Param (
[Parameter(Mandatory = $true)]
[string] $Message,
[Parameter(Mandatory = $true)]
[ValidateSet('Error', 'Warning', 'Suggestion')]
[string] $type
[string] $Message
)

switch($type) {
'Error' {
$global:errors += "- $Message"
Write-Host "- $Message"
}
'Warning' {
$global:warnings += "- $Message"
Write-Host "- $Message"
}
'Suggestion' {
$global:suggestions += "- $Message"
Write-Host "- $Message"
}
}
$global:warnings += "- $Message"
Write-Host "- Error: $Message"
}

function OutputWarning {
function OutputError {
Param (
[Parameter(Mandatory = $true)]
[string] $Message
)

AddToSummary -type Warning -Message $Message
$global:errors += "- $Message"
Write-Host "- Warning: $Message"
}

function OutputError {
function OutputSuggestion {
Param (
[Parameter(Mandatory = $true)]
[string] $Message
)

AddToSummary -type Error -Message $Message
$global:suggestions += "- $Message"
Write-Host "- Suggestion: $Message"
}

. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-TestRepoHelper.ps1" -Resolve)
Expand Down

0 comments on commit 1775036

Please sign in to comment.