Skip to content

Commit

Permalink
collect
Browse files Browse the repository at this point in the history
  • Loading branch information
freddydk committed Dec 6, 2023
1 parent 86accc6 commit 234047d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
14 changes: 7 additions & 7 deletions Actions/TroubleShooting/TroubleShoot.Secrets.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Param(
[Parameter(HelpMessage = "All GitHub Secrets in compressed JSON format", Mandatory = $true)]
[string] $gitHubSecrets = ""
[PSCustomObject] $gitHubSecrets
)

#
Expand All @@ -25,28 +25,28 @@ function CheckSecretForCommonMistakes {
if ($json.PSObject.Properties.Name.Count -gt 0) {
# JSON Secrets should not contain line breaks
if ($secretValue.contains("`n")) {
Write-Host "::WARNING::JSON Secret $secretName contains line breaks. JSON Secrets available to AL-Go for GitHub should be compressed JSON (i.e. NOT contain any line breaks)."
$warnings += "- 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) {
Write-Host "::WARNING::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."
$warnings += "- 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")) {
Write-Host "::WARNING::Secret $secretName contains line breaks. GitHub Secrets available to AL-Go for GitHub should not contain line breaks."
$warnings += "- Secret $secretName contains line breaks. GitHub Secrets available to AL-Go for GitHub should not contain line breaks."
}
elseif ($secretValue.Length -le 4) {
Write-Host "::WARNING::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."
$warnings += "- 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."
}
}
}

foreach($secretName in $script:gitHubSecrets.PSObject.Properties.Name) {
$secretValue = $script:gitHubSecrets."$secretName"
foreach($secretName in $gitHubSecrets.PSObject.Properties.Name) {
$secretValue = $gitHubSecrets."$secretName"
CheckSecretForCommonMistakes -secretName $secretName -secretValue $secretValue
}
13 changes: 12 additions & 1 deletion Actions/TroubleShooting/TroubleShooting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
[string] $gitHubSecrets = ""
)

$errors = @()
$warnings = @()
$suggestions = @()

. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve)

. (Join-Path -Path $PSScriptRoot -ChildPath "TroubleShoot.Secrets.ps1" -Resolve) -gitHubSecrets $gitHubSecrets
. (Join-Path -Path $PSScriptRoot -ChildPath "TroubleShoot.Secrets.ps1" -Resolve) -gitHubSecrets ($gitHubSecrets | ConvertFrom-Json)

if ($errors.Count -eq 0) { $errors = @("No errors found") }
if ($warnings.Count -eq 0) { $warnings = @("No warnings found") }
if ($suggestions.Count -eq 0) { $suggestions = @("No suggestions found") }

$summaryMD = (@("# Errors") + $errors + @("# Warnings") + $warnings + @("# Suggestions") + $suggestions) -join "`n`n"
Set-Content $ENV:GITHUB_STEP_SUMMARY -Value $summaryMD

0 comments on commit 234047d

Please sign in to comment.