-
Notifications
You must be signed in to change notification settings - Fork 151
Freddydk/avoidallsecrets #1735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Freddydk/avoidallsecrets #1735
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
472893f
determinesecrets
freddydk 0bc965a
dump
freddydk ee0f473
remove
freddydk f68b458
dump
freddydk 24776a9
use script
freddydk 9b461b4
remove dump
freddydk 619ac55
check secretName
freddydk be50210
use env
freddydk 73d839e
use calculated secrets
freddydk 385bfb9
Merge branch 'main' into avoidallsecrets
freddydk 4b38887
Merge branch 'main' into avoidallsecrets
freddydk a5de2f4
Simplify readsecrets
freddydk 850468f
Merge branch 'avoidallsecrets' of https://github.com/freddydk/AL-Go i…
freddydk dd25a34
precommit
freddydk 4cd8483
remove getsecrets
freddydk 5705f00
import
freddydk 8f6846a
use jsonStr
freddydk c8350f4
env
freddydk 89a7797
correct ref
freddydk 79d8a25
s
freddydk d17843c
msg
freddydk f1dd80a
remove encrypted pwd
freddydk 191b5e0
Merge branch 'main' into avoidallsecrets
freddydk 69bd866
fix analyzer
freddydk 810603e
Merge branch 'avoidallsecrets' of https://github.com/freddydk/AL-Go i…
freddydk 6e8b82e
fix
freddydk 6e9584f
check max
freddydk 0871381
readd buildPP
freddydk 50b1e07
add github_token
freddydk 31a84e4
add script
freddydk 77e4572
add script
freddydk 6ab5130
use app
freddydk bc217f4
Update Actions/ReadSecrets/ReadSecrets.ps1
freddydk 340bd4e
Merge branch 'main' into freddydk/avoidallsecrets
freddydk 7a3374a
Merge branch 'main' into freddydk/avoidallsecrets
freddydk 9a80383
Avoidallsecrets (#1748)
freddydk cf73c1e
Merge branch 'main' into freddydk/avoidallsecrets
freddydk 0ae5561
use env
freddydk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
Param( | ||
[Parameter(HelpMessage = "Comma-separated list of Secrets to get.", Mandatory = $true)] | ||
[string] $getSecrets = "", | ||
[Parameter(HelpMessage = "Determines whether you want to use the GhTokenWorkflow secret for TokenForPush", Mandatory = $false)] | ||
[string] $useGhTokenWorkflowForPush = 'false' | ||
) | ||
|
||
. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve) | ||
|
||
$settings = $env:Settings | ConvertFrom-Json | ConvertTo-HashTable | ||
|
||
# Build an array of secrets to get (and the names of the secrets) | ||
$script:secretsCollection = [System.Collections.ArrayList]::new() | ||
$script:secretNames = @{} | ||
|
||
function AddSecret { | ||
Param( | ||
[string] $secret, | ||
[switch] $useMapping | ||
) | ||
|
||
if ($secret) { | ||
$secretName = $secret | ||
$secretNameProperty = "$($secretName)SecretName" | ||
if ($useMapping.IsPresent -and $settings.Keys -contains $secretNameProperty) { | ||
$secretName = $settings."$secretNameProperty" | ||
} | ||
# Secret is the AL-Go name of the secret | ||
# SecretName is the actual name of the secret to get from the KeyVault or GitHub environment | ||
if ($secretName -and ($script:secretsCollection -notcontains $secret)) { | ||
# Add secret to the collection of secrets to get | ||
$script:secretsCollection += $secret | ||
$script:secretNames += @{ | ||
"$secret" = "$secretName" | ||
} | ||
} | ||
} | ||
} | ||
|
||
AddSecret -secret 'AZURE_CREDENTIALS' -useMapping | ||
foreach($secret in ($getSecrets.Split(',') | Select-Object -Unique)) { | ||
switch ($secret) { | ||
'TokenForPush' { | ||
AddSecret -secret 'TokenForPush' | ||
if ($useGhTokenWorkflowForPush -eq 'true') { | ||
# If we are using the ghTokenWorkflow for commits, we need to get ghTokenWorkflow secret | ||
AddSecret -secret 'ghTokenWorkflow' -useMapping | ||
} | ||
else { | ||
AddSecret -secret 'github_token' | ||
} | ||
} | ||
'GitSubmodulesToken' { | ||
# If we are getting the gitSubModules token, we might need to get the github token as well | ||
AddSecret -secret $secret -useMapping | ||
AddSecret -secret 'github_token' | ||
} | ||
'AppDependencySecrets' { | ||
# Loop through appDependencyProbingPaths and trustedNuGetFeeds and add secrets to the collection of secrets to get | ||
$settingsCollection = @() | ||
if ($settings.Keys -contains 'appDependencyProbingPaths') { | ||
$settingsCollection += $settings.appDependencyProbingPaths | ||
} | ||
if ($settings.Keys -contains 'trustedNuGetFeeds') { | ||
$settingsCollection += $settings.trustedNuGetFeeds | ||
} | ||
foreach($settingsItem in $settingsCollection) { | ||
if ($settingsItem.PsObject.Properties.name -eq "AuthTokenSecret") { | ||
AddSecret -secret $settingsItem.authTokenSecret | ||
} | ||
} | ||
# Look through installApps and installTestApps for secrets and add them to the collection of secrets to get | ||
foreach($installSettingsKey in @('installApps','installTestApps')) { | ||
if ($settings.Keys -contains $installSettingsKey) { | ||
$settings."$installSettingsKey" | ForEach-Object { | ||
# If any of the installApps URLs contains '${{SECRETNAME}}' we need to get the secret | ||
$pattern = '.*(\$\{\{\s*([^}]+?)\s*\}\}).*' | ||
if ($_ -match $pattern) { | ||
AddSecret -secret $matches[2] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
default { | ||
AddSecret -secret $secret -useMapping | ||
} | ||
} | ||
} | ||
|
||
# Calculate output for secrets | ||
# one output called FORMATSTR with the content: {{"secret1":{0},"secret2":{1},"secret3":{2}}} | ||
# and one environment variable per secret called S0, S1, S2 with the name of the GitHub Secret (or Azure DevOps secret) to look for | ||
if ($script:secretsCollection.Count -gt 32) { | ||
throw "Maximum number of secrets exceeded." | ||
} | ||
|
||
$cnt = 0 | ||
$formatArr = @() | ||
foreach($secret in $script:secretsCollection) { | ||
$formatArr += @("""$Secret"":{$cnt}") | ||
Add-Content -Encoding UTF8 -Path $ENV:GITHUB_ENV -Value "S$cnt=$($script:secretNames[$secret])" | ||
freddydk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Write-Host "S$cnt=$($script:secretNames[$secret])" | ||
$cnt++ | ||
} | ||
Add-Content -Encoding UTF8 -Path $ENV:GITHUB_OUTPUT -Value "FORMATSTR={{$($formatArr -join ',')}}" | ||
Write-Host "FORMATSTR={{$($formatArr -join ',')}}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Determine secrets | ||
|
||
Determine the secrets needed for the workflow | ||
|
||
## INPUT | ||
|
||
### ENV variables | ||
|
||
| Name | Description | | ||
| :-- | :-- | | ||
| Settings | env.Settings must be set by a prior call to the ReadSettings Action | | ||
|
||
### Parameters | ||
|
||
| Name | Required | Description | Default value | | ||
| :-- | :-: | :-- | :-- | | ||
| shell | | The shell (powershell or pwsh) in which the PowerShell script in this action should run | powershell | | ||
| getSecrets | Yes | Comma-separated list of secrets to get (add appDependencySecrets to request secrets needed for resolving dependencies in AppDependencyProbingPaths and TrustedNuGetFeeds, add TokenForPush in order to request a token to use for pull requests and commits). Secrets preceded by an asterisk are returned encrypted | | | ||
| useGhTokenWorkflowForPush | false | Determines whether you want to use the GhTokenWorkflow secret for TokenForPush | false | | ||
|
||
## OUTPUT | ||
|
||
### ENV variables | ||
|
||
none | ||
|
||
### OUTPUT variables | ||
|
||
| Name | Description | | ||
| :-- | :-- | | ||
| FORMATSTR | A format string to be used when transferring the secrets to ReadSecrets | | ||
| S0,S1,S2,...,S31 | The actual names of the GitHub secrets to look for | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Determine Secrets | ||
author: Microsoft Corporation | ||
inputs: | ||
shell: | ||
description: Shell in which you want to run the action (powershell or pwsh) | ||
required: false | ||
default: powershell | ||
getSecrets: | ||
description: Comma-separated list of Secrets to get. Secrets preceded by an asterisk are returned encrypted | ||
required: true | ||
useGhTokenWorkflowForPush: | ||
description: Determines whether you want to use the GhTokenWorkflow secret for TokenForPush | ||
required: false | ||
default: 'false' | ||
outputs: | ||
FORMATSTR: | ||
mazhelez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
description: A format string to be used when transferring the secrets to ReadSecrets | ||
value: ${{ steps.DetermineSecrets.outputs.FORMATSTR }} | ||
runs: | ||
using: composite | ||
steps: | ||
- name: run | ||
shell: ${{ inputs.shell }} | ||
id: DetermineSecrets | ||
env: | ||
_getSecrets: ${{ inputs.getSecrets }} | ||
_useGhTokenWorkflowForPush: ${{ inputs.useGhTokenWorkflowForPush }} | ||
run: | | ||
${{ github.action_path }}/../Invoke-AlGoAction.ps1 -ActionName "DetermineSecrets" -Action { | ||
${{ github.action_path }}/DetermineSecrets.ps1 -getSecrets $ENV:_getSecrets -useGhTokenWorkflowForPush $ENV:_useGhTokenWorkflowForPush | ||
} | ||
branding: | ||
icon: terminal | ||
color: blue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.