Skip to content
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

[CI Environment] Token Mechanism Uplift (support tokens as GitHub Secret + Migrate Settings.Json to Settings YAML) #1516

Merged
merged 123 commits into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
6556297
added custom token
ahmadabdalla May 28, 2022
5c63406
set telemtry to false
ahmadabdalla May 28, 2022
c6ea610
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla May 31, 2022
c66f8c5
updated naming convention
ahmadabdalla Jun 9, 2022
0023e2e
Merge branch 'users/ahmad/tokenUpdates' of https://github.com/ahmadab…
ahmadabdalla Jun 9, 2022
2fbac34
test
ahmadabdalla Jun 9, 2022
c40e86e
test
ahmadabdalla Jun 9, 2022
2b8c871
test
ahmadabdalla Jun 9, 2022
606721f
crocs
ahmadabdalla Jun 9, 2022
5677b2f
test
ahmadabdalla Jun 9, 2022
a980a54
set local tokens to false
ahmadabdalla Jun 9, 2022
1df43c0
test
ahmadabdalla Jun 9, 2022
018a6cd
test
ahmadabdalla Jun 9, 2022
063bb7e
test
ahmadabdalla Jun 9, 2022
f7ec740
fix
ahmadabdalla Jun 9, 2022
6fe7645
fix
ahmadabdalla Jun 9, 2022
3d3c573
fix
ahmadabdalla Jun 9, 2022
f7ca33a
test
ahmadabdalla Jun 9, 2022
8d6ba72
updated global modules test
ahmadabdalla Jun 17, 2022
8b8df8d
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jun 17, 2022
7c8f6a5
First major test
ahmadabdalla Jun 18, 2022
74b1559
test
ahmadabdalla Jun 18, 2022
9c9b8c7
fixed global variable path
ahmadabdalla Jun 18, 2022
caa197f
fix
ahmadabdalla Jun 18, 2022
5245273
test
ahmadabdalla Jun 18, 2022
093ab51
fix
ahmadabdalla Jun 18, 2022
44544c2
Updated ADO - Attempt 1
ahmadabdalla Jun 19, 2022
eb8ae54
fixed azure service connection
ahmadabdalla Jun 19, 2022
4a5f826
bug fix
ahmadabdalla Jun 19, 2022
b6fe770
bug fix
ahmadabdalla Jun 19, 2022
1132782
trial
ahmadabdalla Jun 19, 2022
9638934
test gha
ahmadabdalla Jun 19, 2022
1a1fe30
test XASA
ahmadabdalla Jun 19, 2022
2419d45
test
ahmadabdalla Jun 19, 2022
746e978
test
ahmadabdalla Jun 19, 2022
69fc55d
removed settings.json dependency for ADO
ahmadabdalla Jun 19, 2022
3816ac2
test removing the condition
ahmadabdalla Jun 20, 2022
e9ffc12
test
ahmadabdalla Jun 20, 2022
95ed6af
restored token
ahmadabdalla Jun 20, 2022
be6af04
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jun 20, 2022
be88d21
updates and fetched
ahmadabdalla Jun 20, 2022
267e058
removed dependency on settings for dep pipeline gha
ahmadabdalla Jun 21, 2022
51e2d77
test
ahmadabdalla Jun 21, 2022
7faa4ad
added env. agent
ahmadabdalla Jun 21, 2022
3c23e29
bug fix
ahmadabdalla Jun 21, 2022
ea0c78a
updated ado
ahmadabdalla Jun 22, 2022
5af2f83
test with no policies
ahmadabdalla Jun 23, 2022
a7eb84d
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jun 23, 2022
e8fa7e4
bug fix in kv tokens input
ahmadabdalla Jun 24, 2022
043c4cb
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jun 25, 2022
31ca088
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jun 26, 2022
3882af8
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jun 27, 2022
f307777
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jun 27, 2022
2e52ec5
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jun 28, 2022
cf94dac
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jun 29, 2022
b99e405
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jun 30, 2022
d539d5b
Users/ahmad/token update settings (#21)
ahmadabdalla Jul 4, 2022
a450427
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jul 4, 2022
e594960
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jul 5, 2022
acf77f0
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jul 6, 2022
706d7c2
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jul 7, 2022
67f2e51
removed local tokens validations in the pester test
ahmadabdalla Jul 8, 2022
d7ad8a9
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jul 10, 2022
eb1b79e
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jul 16, 2022
3a295e1
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jul 16, 2022
2e3f11c
uplifted local test script
ahmadabdalla Jul 16, 2022
3ef3699
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jul 17, 2022
d8f53df
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jul 18, 2022
22393cb
updated ado module pipelines with settings.yml
ahmadabdalla Jul 19, 2022
f49e8a4
changed github to use settings.yml and token prefix
ahmadabdalla Jul 19, 2022
709c766
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jul 20, 2022
384fea1
update generic doco
ahmadabdalla Jul 20, 2022
1baf387
Updated documentation
ahmadabdalla Jul 20, 2022
7e07d99
updated app security group duplicate
ahmadabdalla Jul 20, 2022
66a39b9
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jul 21, 2022
e9d4589
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jul 22, 2022
6059add
updated from upstream/main
ahmadabdalla Jul 22, 2022
bfaf75f
added repo root path
ahmadabdalla Jul 22, 2022
acbe806
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jul 23, 2022
ac79def
updated based on latest ADO pipeline changes
ahmadabdalla Jul 23, 2022
402cd64
Update docs/wiki/The CI environment - Token replacement.md
ahmadabdalla Jul 23, 2022
24717bf
Update utilities/tools/Test-ModuleLocally.ps1
ahmadabdalla Jul 23, 2022
e90c894
Update docs/wiki/The CI environment - Token replacement.md
ahmadabdalla Jul 23, 2022
2c55441
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jul 24, 2022
d1e379b
Merge branch 'users/ahmad/tokenUpdates' of https://github.com/ahmadab…
ahmadabdalla Jul 24, 2022
348bc67
duplicate env. var
ahmadabdalla Jul 24, 2022
40ec8cd
updated new dependency job with token changes
ahmadabdalla Jul 24, 2022
2100122
bug fixes
ahmadabdalla Jul 24, 2022
4d8e4a7
added token message
ahmadabdalla Jul 24, 2022
69ba74d
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jul 24, 2022
ac9ab21
enabling telemtry and setting local token
ahmadabdalla Jul 25, 2022
c363517
fix for ado deploy
ahmadabdalla Jul 25, 2022
3c9bc1a
requested powershell-yaml module
ahmadabdalla Jul 25, 2022
f7d3f46
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Jul 25, 2022
54a4b01
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Aug 2, 2022
ea8ecd4
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Aug 8, 2022
9455f67
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Aug 8, 2022
e5f8e83
updated test script
ahmadabdalla Aug 9, 2022
fba187b
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Aug 9, 2022
93eca00
fixed test name prefix and token converter
ahmadabdalla Aug 10, 2022
ecbf7bf
updated github actions
ahmadabdalla Aug 10, 2022
f85a6ca
fixes post merges
ahmadabdalla Aug 10, 2022
80f39c3
updated pipeline jobs
ahmadabdalla Aug 10, 2022
5a52419
disabled the enableDefaultTelemetry
ahmadabdalla Aug 10, 2022
e4d9efa
updated token function in devops
ahmadabdalla Aug 10, 2022
d4fadee
updated settings yaml
ahmadabdalla Aug 11, 2022
530e5e1
enabled telemetry
ahmadabdalla Aug 11, 2022
e9041ff
updated role assignment
ahmadabdalla Aug 11, 2022
a790f59
updated subscription id
ahmadabdalla Aug 11, 2022
3d4bdde
Merge remote-tracking branch 'origin/main' into users/ahmad/1440_tokens
ahmadabdalla Aug 11, 2022
a034c10
updated from carml branch
ahmadabdalla Aug 11, 2022
c82bc9a
Update docs/wiki/Getting started - Scenario 2 Onboard module library …
ahmadabdalla Aug 12, 2022
d7b1cef
Update docs/wiki/The CI environment - Token replacement.md
ahmadabdalla Aug 12, 2022
9b97839
updated scripts based on feedback
ahmadabdalla Aug 12, 2022
f98b02b
removed reference to global.variables.yml
ahmadabdalla Aug 12, 2022
4f47315
Merge remote-tracking branch 'upstream/main' into users/ahmad/tokenUp…
ahmadabdalla Aug 12, 2022
95305bb
Token comments updates (#23)
ahmadabdalla Aug 12, 2022
5c70ad7
updated test local script based on feedback
ahmadabdalla Aug 13, 2022
792d80a
Update docs/wiki/Getting started - Scenario 2 Onboard module library …
ahmadabdalla Aug 13, 2022
891e7e9
Update utilities/tools/Test-ModuleLocally.ps1
ahmadabdalla Aug 13, 2022
0871459
Update docs/wiki/Getting started - Scenario 2 Onboard module library …
ahmadabdalla Aug 13, 2022
f940c91
Update docs/wiki/The CI environment - Token replacement.md
ahmadabdalla Aug 13, 2022
790c223
updated based on feedback
ahmadabdalla Aug 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions .github/actions/templates/validateModuleDeployment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
## |============================================================================================================================================================================|
## | Parameter | Required | Default | Description | Example |
## |---------------------------|----------|---------|-------------------------------------------------------|-------------------------------------------------------------------|
## | templateFilePath | true | '' | The path to the template file to use for deployment | 'arm/Microsoft.ApiManagement/service/deploy.bicep' |
## | templateFilePath | true | '' | The path to the template file to use for deployment | 'arm/Microsoft.ApiManagement/service/deploy.bicep' |
## | parameterFilePath | true | '' | The path to the parameter file to use for deployment | 'arm/Microsoft.ApiManagement/service/.parameters/parameters.json' |
## | location | true | '' | The location to use for deployment | 'WestEurope' |
## | resourceGroupName | false | '' | The resource group to deploy to | 'validation-rg' |
Expand Down Expand Up @@ -129,18 +129,15 @@ runs:
# Load used functions
. (Join-Path $env:GITHUB_WORKSPACE 'utilities' 'pipelines' 'tokensReplacement' 'Convert-TokensInFile.ps1')

# Load Settings File
$Settings = Get-Content -Path "settings.json" | ConvertFrom-Json -AsHashTable

# Construct Token Function Input
$ConvertTokensInputs = @{
Tokens = @{}
FilePath = '${{ inputs.parameterFilePath }}'
TokenPrefix = $Settings.parameterFileTokens.tokenPrefix
TokenSuffix = $Settings.parameterFileTokens.tokenSuffix
TokenPrefix = '${{ env.tokenPrefix }}'
TokenSuffix = '${{ env.tokenSuffix }}'
}

# Local tokens
# Add enforced tokens
$ConvertTokensInputs.Tokens += @{
resourceGroupName = '${{ inputs.resourceGroupName }}'
subscriptionId = '${{ inputs.subscriptionId }}'
Expand All @@ -149,14 +146,18 @@ runs:
deploymentSpId = '${{ env.DEPLOYMENT_SP_ID }}'
}

# Add local tokens
if ($Settings.parameterFileTokens.localTokens) {
$tokenMap = @{}
foreach ($token in $Settings.parameterFileTokens.localTokens) {
$tokenMap += @{ $token.name = $token.value }
}
Write-Verbose ('Using local tokens [{0}]' -f ($tokenMap.Keys -join ', ')) -Verbose
$ConvertTokensInputs.Tokens += $tokenMap
# Add local (source control) tokens
$tokenMap = @{}
foreach ($token in (Get-ChildItem env: | Where-Object -Property Name -Like "localToken_*")) {
$tokenMap += @{ $token.Name.Replace('localToken_','') = $token.value }
}
Write-Verbose ('Using local tokens [{0}]' -f ($tokenMap.Keys -join ', ')) -Verbose
$ConvertTokensInputs.Tokens += $tokenMap

# Swap 'namePrefix' token if provided as a GitHub secret
if($ConvertTokensInputs.Tokens.namePrefix -and '${{ env.TOKEN_NAMEPREFIX }}'){
Write-Verbose 'Using [namePrefix] token from GitHub' -Verbose
$ConvertTokensInputs.Tokens.namePrefix = '${{ env.TOKEN_NAMEPREFIX }}'
}

# Add custom tokens (passed in via the pipeline)
Expand Down Expand Up @@ -200,10 +201,9 @@ runs:
$functionInput['parameterFilePath'] = Join-Path $env:GITHUB_WORKSPACE '${{ inputs.parameterFilePath }}'
}

$projectSettings = Get-Content -Path 'settings.json' | ConvertFrom-Json
if (-not [String]::IsNullOrEmpty($projectSettings.enableDefaultTelemetry) -and (Get-Content -Path $functionInput.templateFilePath -Raw) -like '*param enableDefaultTelemetry*') {
if (-not [System.Convert]::ToBoolean('${{ env.enableDefaultTelemetry }}') -and (Get-Content -Path $functionInput.templateFilePath -Raw) -like '*param enableDefaultTelemetry*') {
$functionInput['additionalParameters'] += @{
enableDefaultTelemetry = $projectSettings.enableDefaultTelemetry
enableDefaultTelemetry = [System.Convert]::ToBoolean('${{ env.enableDefaultTelemetry }}')
}
}

Expand Down Expand Up @@ -242,10 +242,9 @@ runs:
$functionInput['parameterFilePath'] = Join-Path $env:GITHUB_WORKSPACE '${{ inputs.parameterFilePath }}'
}

$projectSettings = Get-Content -Path 'settings.json' | ConvertFrom-Json
if (-not [String]::IsNullOrEmpty($projectSettings.enableDefaultTelemetry) -and (Get-Content -Path $functionInput.templateFilePath -Raw) -like '*param enableDefaultTelemetry*') {
if (-not [System.Convert]::ToBoolean('${{ env.enableDefaultTelemetry }}') -and (Get-Content -Path $functionInput.templateFilePath -Raw) -like '*param enableDefaultTelemetry*') {
$functionInput['additionalParameters'] += @{
enableDefaultTelemetry = $projectSettings.enableDefaultTelemetry
enableDefaultTelemetry = [System.Convert]::ToBoolean('${{ env.enableDefaultTelemetry }}')
}
}

Expand Down
29 changes: 22 additions & 7 deletions .github/actions/templates/validateModulePester/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ runs:
# This is the latest tested Pester version. Uncomment the next line in case of a future breaking change in the default version installed on the runner.
# @{ Name = 'Pester'; Version = '5.3.1' }
@{ Name = 'Az.Resources' }
@{ Name = 'powershell-yaml'; Version = '0.4.2'}
)

# Set agent up
Expand Down Expand Up @@ -76,18 +77,32 @@ runs:
Write-Verbose "- [($moduleFolderPath]" -Verbose
}

$enforcedTokenList = @{}
$GlobalVariablesObject = Get-Content -Path 'global.variables.yml' | ConvertFrom-Yaml | Select-Object -ExpandProperty variables

# Construct Token Configuration Input
$tokenConfiguration = @{
Tokens = @{}
TokenPrefix = $GlobalVariablesObject | Select-Object -ExpandProperty tokenPrefix
TokenSuffix = $GlobalVariablesObject | Select-Object -ExpandProperty tokenSuffix
}

## Enforced Tokens
if (-not [String]::IsNullOrEmpty('${{ env.ARM_SUBSCRIPTION_ID }}')) {
$enforcedTokenList['subscriptionId'] = '${{ env.ARM_SUBSCRIPTION_ID }}'
$tokenConfiguration.Tokens['subscriptionId'] = '${{ env.ARM_SUBSCRIPTION_ID }}'
}
if (-not [String]::IsNullOrEmpty('${{ env.ARM_MGMTGROUP_ID }}')) {
$enforcedTokenList['managementGroupId'] = '${{ env.ARM_MGMTGROUP_ID }}'
$tokenConfiguration.Tokens['managementGroupId'] = '${{ env.ARM_MGMTGROUP_ID }}'
}
if (-not [String]::IsNullOrEmpty('${{ env.DEPLOYMENT_SP_ID }}')) {
$enforcedTokenList['deploymentSpId'] = '${{ env.DEPLOYMENT_SP_ID }}'
$tokenConfiguration.Tokens['deploymentSpId'] = '${{ env.DEPLOYMENT_SP_ID }}'
}
if (-not [String]::IsNullOrEmpty('${{ env.ARM_TENANT_ID }}')) {
$enforcedTokenList['tenantId'] = '${{ env.ARM_TENANT_ID }}'
$tokenConfiguration.Tokens['tenantId'] = '${{ env.ARM_TENANT_ID }}'
}

## Local Tokens from global.variables.yml
foreach ($localToken in $GlobalVariablesObject.Keys | ForEach-Object { if ($PSItem.contains('localToken_')) { $PSItem } }) {
$tokenConfiguration.Tokens[$localToken.Replace('localToken_', '')] = $GlobalVariablesObject.$localToken
}

# --------------------- #
Expand All @@ -96,8 +111,8 @@ runs:
Invoke-Pester -Configuration @{
Run = @{
Container = New-PesterContainer -Path 'arm/.global/global.module.tests.ps1' -Data @{
moduleFolderPaths = $moduleFolderPaths
enforcedTokenList = $enforcedTokenList
moduleFolderPaths = $moduleFolderPaths
tokenConfiguration = $tokenConfiguration
}
}
TestResult = @{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ env:
ARM_MGMTGROUP_ID: '${{ secrets.ARM_MGMTGROUP_ID }}'
ARM_TENANT_ID: '${{ secrets.ARM_TENANT_ID }}'
DEPLOYMENT_SP_ID: '${{ secrets.DEPLOYMENT_SP_ID }}'
TOKEN_NAMEPREFIX: '${{ secrets.TOKEN_NAMEPREFIX }}'

jobs:
###########################
Expand Down
47 changes: 24 additions & 23 deletions arm/.global/global.module.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ param (
(Get-ChildItem $_ -File -Depth 0 -Include @('deploy.json', 'deploy.bicep') -Force).Count -gt 0
}),

# Tokens to test for (i.e. their value should not be used in the parameter files, but their placeholder)
# Dedicated Tokens configuration hashtable containing the tokens and token prefix and suffix.
[Parameter(Mandatory = $false)]
[hashtable] $enforcedTokenList = @{}
[hashtable] $tokenConfiguration = @{}
)

$script:RepoRoot = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent
$script:Settings = Get-Content -Path (Join-Path $PSScriptRoot '..\..\settings.json') | ConvertFrom-Json -AsHashtable
$script:RGdeployment = 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
$script:Subscriptiondeployment = 'https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#'
$script:MGdeployment = 'https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#'
$script:Tenantdeployment = 'https://schema.management.azure.com/schemas/2019-08-01/tenantDeploymentTemplate.json#'
$script:moduleFolderPaths = $moduleFolderPaths
$script:enforcedTokenList = $enforcedTokenList

# For runtime purposes, we cache the compiled template in a hashtable that uses a formatted relative module path as a key
$script:convertedTemplates = @{}
Expand Down Expand Up @@ -147,7 +145,6 @@ Describe 'File/folder tests' -Tag Modules {
}
}
}

Describe 'Readme tests' -Tag Readme {

Context 'Readme content tests' {
Expand Down Expand Up @@ -515,7 +512,7 @@ Describe 'Deployment template tests' -Tag Template {
parameterFile_AllParameterNames = $parameterFile_AllParameterNames
templateFile_AllParameterNames = $TemplateFile_AllParameterNames
templateFile_RequiredParametersNames = $TemplateFile_RequiredParametersNames
tokenSettings = $Settings.parameterFileTokens
tokenConfiguration = $tokenConfiguration
}
}
}
Expand Down Expand Up @@ -920,35 +917,39 @@ Describe 'Deployment template tests' -Tag Template {
if (Test-Path (Join-Path $moduleFolderPath '.parameters')) {
$ParameterFilePaths = (Get-ChildItem (Join-Path -Path $moduleFolderPath -ChildPath '.parameters' -AdditionalChildPath '*parameters.json') -Recurse -Force).FullName
foreach ($ParameterFilePath in $ParameterFilePaths) {
foreach ($token in $enforcedTokenList.Keys) {
foreach ($token in $tokenConfiguration.Tokens.Keys) {
$parameterFileTokenTestCases += @{
parameterFilePath = $ParameterFilePath
parameterFileName = Split-Path $ParameterFilePath -Leaf
tokenSettings = $Settings.parameterFileTokens
tokenPrefix = $tokenConfiguration.TokenPrefix
tokenSuffix = $tokenConfiguration.TokenSuffix
tokenName = $token
tokenValue = $enforcedTokenList[$token]
tokenValue = $tokenConfiguration.Tokens[$token]
moduleFolderName = $moduleFolderPath.Replace('\', '/').Split('/arm/')[1]
}
}
}
}
}

It '[<moduleFolderName>] [Tokens] Parameter file [<parameterFileName>] should not contain the plain value for token [<tokenName>] guid' -TestCases $parameterFileTokenTestCases {
param (
[string] $parameterFilePath,
[string] $parameterFileName,
[hashtable] $tokenSettings,
[string] $tokenName,
[string] $tokenValue,
[string] $moduleFolderName
)
$ParameterFileTokenName = -join ($tokenSettings.tokenPrefix, $tokenName, $tokenSettings.tokenSuffix)
$ParameterFileContent = Get-Content -Path $parameterFilePath
foreach ($parameterFileTokenTestCase in $parameterFileTokenTestCases) {
It '[<moduleFolderName>] [Tokens] Parameter file [<parameterFileName>] should not contain the plain value for token [<tokenName>]' -TestCases $parameterFileTokenTestCase {
param (
[string] $parameterFilePath,
[string] $parameterFileName,
[string] $tokenPrefix,
[string] $tokenSuffix,
[string] $tokenName,
[string] $tokenValue,
[string] $moduleFolderName
)
$ParameterFileTokenName = -join ($tokenPrefix, $tokenName, $tokenSuffix)
$ParameterFileContent = Get-Content -Path $parameterFilePath

$incorrectReferencesFound = $ParameterFileContent | Select-String -Pattern $tokenValue -AllMatches
if ($incorrectReferencesFound.Matches) {
$incorrectReferencesFound.Matches.Count | Should -Be 0 -Because ('Parameter file should not contain the [{0}] value, instead should reference the token value [{1}]. Please check the {2} lines: [{3}]' -f $tokenName, $ParameterFileTokenName, $incorrectReferencesFound.Matches.Count, ($incorrectReferencesFound.Line.Trim() -join ",`n"))
$incorrectReferencesFound = $ParameterFileContent | Select-String -Pattern $tokenValue -AllMatches
if ($incorrectReferencesFound.Matches) {
$incorrectReferencesFound.Matches.Count | Should -Be 0 -Because ('Parameter file should not contain the [{0}] value, instead should reference the token value [{1}]. Please check the {2} lines: [{3}]' -f $tokenName, $ParameterFileTokenName, $incorrectReferencesFound.Matches.Count, ($incorrectReferencesFound.Line.Trim() -join ",`n"))
}
}
}
}
Expand Down
24 changes: 22 additions & 2 deletions global.variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@ variables:
################################################## Common Variables #######################################################
###########################################################################################################################

# Enable or disable CARMLs CI telemetry tracking. Note: This tracks the number of deployments only.
# See: https://github.com/Azure/ResourceModules/wiki/The%20library%20-%20Module%20design#telemetry
enableDefaultTelemetry: false

######################################
# Local tokens settings
######################################

# the 'localToken_' prefix will be removed from the key name when the pipelines run.
# e.g. if you have a token in your parameter file as <<customKey>>, then the token defined in this file looks like "localToken_customKey": 'value'
localToken_namePrefix: 'zu3bx' # A 3-5 character length string, included in the resources names, is overridden if provided as GitHub Secret / ADO Variable
eriqua marked this conversation as resolved.
Show resolved Hide resolved

######################################
# global tokens settings
######################################

# this determines the starting prefix and ending suffix of the token in your file.
tokenPrefix: '<<'
tokenSuffix: '>>'

######################################
# Validation deployment settings
######################################
Expand All @@ -24,7 +44,7 @@ variables:
######################################

bicepRegistryDoPublish: true # Set to true, if you would like to publish module templates to a bicep registry
bicepRegistryName: adpsxxazacrx001 # The name of the bicep registry (ACR) to publish to. If it does not exist, it will be created.
bicepRegistryName: adpzu3bxazacrx001 # The name of the bicep registry (ACR) to publish to. If it does not exist, it will be created.
bicepRegistryRGName: 'artifacts-rg' # The resource group that hosts the private bicep registry (ACR)
bicepRegistryRgLocation: 'West Europe' # The location of the resource group to publish to

Expand All @@ -38,7 +58,7 @@ variables:

vmImage: 'ubuntu-latest' # Use this for Microsoft-hosted agents
poolName: '' # Use this for self-hosted agents
serviceConnection: 'CARML-CSU-Tenant-Connection'
serviceConnection: 'carml'

######################################
# Source
Expand Down
19 changes: 0 additions & 19 deletions settings.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,20 @@ function Get-DependencyResourceNameList {
}

# Replace tokens in dependency parameter files
$Settings = Get-Content -Path (Join-Path $repoRootPath 'settings.json') | ConvertFrom-Json -AsHashtable
$GlobalVariablesObject = Get-Content -Path (Join-Path $repoRootPath 'global.variables.yml') | ConvertFrom-Yaml -ErrorAction Stop | Select-Object -ExpandProperty variables

# Add local tokens
if ($Settings.parameterFileTokens.localTokens) {
$tokenMap = @{}
foreach ($token in $Settings.parameterFileTokens.localTokens) {
$tokenMap += @{ $token.name = $token.value }
}
Write-Verbose ('Using local tokens [{0}]' -f ($tokenMap.Keys -join ', '))
# Construct Token Configuration Input
$tokenConfiguration = @{
Tokens = @{}
TokenPrefix = $GlobalVariablesObject | Select-Object -ExpandProperty tokenPrefix
TokenSuffix = $GlobalVariablesObject | Select-Object -ExpandProperty tokenSuffix
}

$ConvertTokensInputs = @{
Tokens = $tokenMap
TokenPrefix = $Settings.parameterFileTokens.tokenPrefix
TokenSuffix = $Settings.parameterFileTokens.tokenSuffix
Verbose = $false
}
$parameterFilePaths | ForEach-Object { $null = Convert-TokensInFile @ConvertTokensInputs -FilePath $_ }
## Local Tokens from global.variables.yml
foreach ($localToken in $GlobalVariablesObject.Keys | ForEach-Object { if ($PSItem.contains('localToken_')) { $PSItem } }) {
$tokenConfiguration.Tokens[$localToken.Replace('localToken_', '')] = $GlobalVariablesObject.$localToken
}
$parameterFilePaths | ForEach-Object { $null = Convert-TokensInFile @tokenConfiguration -FilePath $_ }

$dependencyResourceNames = [System.Collections.ArrayList]@()
foreach ($parameterFilePath in $parameterFilePaths) {
Expand All @@ -60,10 +56,8 @@ function Get-DependencyResourceNameList {
}
}

if ($Settings.parameterFileTokens.localTokens) {
Write-Verbose 'Restoring Tokens'
$parameterFilePaths | ForEach-Object { $null = Convert-TokensInFile @ConvertTokensInputs -FilePath $_ -SwapValueWithName $true }
}
Write-Verbose 'Restoring Tokens'
$parameterFilePaths | ForEach-Object { $null = Convert-TokensInFile @tokenConfiguration -FilePath $_ -SwapValueWithName $true }

return $dependencyResourceNames
}
Loading