Skip to content

Commit ed6da24

Browse files
Add acquiring ACR access token using Azure.Identity and allow unauthenticated ACR endpoints (#1576)
1 parent b3fc7e2 commit ed6da24

13 files changed

+333
-243
lines changed

Diff for: .ci/ci.yml

+7
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,10 @@ stages:
137137
jobName: TestPkgWinMacOS
138138
displayName: PowerShell Core on macOS
139139
imageName: macOS-latest
140+
141+
- template: test.yml
142+
parameters:
143+
jobName: TestPkgWinAzAuth
144+
displayName: AzAuth PowerShell Core on Windows
145+
imageName: windows-latest
146+
useAzAuth: true

Diff for: .ci/test.yml

+31-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ parameters:
44
displayName: PowerShell Core on Windows
55
powershellExecutable: pwsh
66
buildDirectory: '.'
7+
useAzAuth: false
78

89
jobs:
910
- job: ${{ parameters.jobName }}
@@ -18,6 +19,7 @@ jobs:
1819
Set-SecretStoreConfiguration -Authentication None -Interaction None -Confirm:$false -Password $vaultPassword
1920
Register-SecretVault -Name SecretStore -ModuleName Microsoft.PowerShell.SecretStore -DefaultVault
2021
displayName: Install Secret store
22+
condition: eq(${{ parameters.useAzAuth }}, false)
2123
2224
- task: DownloadBuildArtifacts@0
2325
displayName: 'Download artifacts'
@@ -78,6 +80,34 @@ jobs:
7880
Write-Host "sending " + $vstsCommandString
7981
Write-Host "##$vstsCommandString"
8082
displayName: 'Setup Azure Container Registry secret'
83+
condition: eq(${{ parameters.useAzAuth }}, false)
84+
85+
- powershell: |
86+
# Set environment variable to identify in tests that secret store should not be used.
87+
$vstsCommandString = "vso[task.setvariable variable=UsingAzAuth]true"
88+
Write-Host "sending " + $vstsCommandString
89+
Write-Host "##$vstsCommandString"
90+
displayName: 'Set UsingAzAuth environment variable'
91+
condition: eq(${{ parameters.useAzAuth }}, true)
92+
93+
- task: AzurePowerShell@5
94+
inputs:
95+
azureSubscription: PSResourceGetACR
96+
azurePowerShellVersion: LatestVersion
97+
ScriptType: InlineScript
98+
inline: |
99+
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
100+
$env:PSModulePath = $modulePath + [System.IO.Path]::PathSeparator + $env:PSModulePath
101+
Write-Verbose -Verbose "Importing build utilities (buildtools.psd1)"
102+
Import-Module -Name (Join-Path -Path '${{ parameters.buildDirectory }}' -ChildPath 'buildtools.psd1') -Force
103+
Invoke-ModuleTestsACR -Type Functional
104+
env:
105+
MAPPED_GITHUB_PAT: $(github_pat)
106+
MAPPED_ADO_PUBLIC_PAT: $(ado_public_pat)
107+
MAPPED_ADO_PRIVATE_PAT: $(ado_private_pat)
108+
MAPPED_ADO_PRIVATE_REPO_URL: $(ado_private_repo_url)
109+
displayName: 'Execute functional tests with AzAuth'
110+
condition: eq(${{ parameters.useAzAuth }}, true)
81111

82112
- ${{ parameters.powershellExecutable }}: |
83113
$modulePath = Join-Path -Path $env:AGENT_TEMPDIRECTORY -ChildPath 'TempModules'
@@ -93,4 +123,4 @@ jobs:
93123
displayName: Execute functional tests
94124
workingDirectory: ${{ parameters.buildDirectory }}
95125
errorActionPreference: continue
96-
condition: succeededOrFailed()
126+
condition: eq(${{ parameters.useAzAuth }}, false)

Diff for: buildtools.psd1

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
@{
55
# Script module or binary module file associated with this manifest.
66
RootModule = '.\buildtools.psm1'
7-
7+
88
# Version number of this module.
99
ModuleVersion = '1.0.0'
10-
10+
1111
# Supported PSEditions
1212
CompatiblePSEditions = @('Core')
13-
13+
1414
# ID used to uniquely identify this module
1515
GUID = 'fcdd259e-1163-4da2-8bfa-ce36a839f337'
16-
16+
1717
# Author of this module
1818
Author = 'Microsoft Corporation'
19-
19+
2020
# Company or vendor of this module
2121
CompanyName = 'Microsoft Corporation'
22-
22+
2323
# Copyright statement for this module
2424
Copyright = '(c) Microsoft Corporation. All rights reserved.'
25-
25+
2626
# Description of the functionality provided by this module
2727
Description = "Build utilties."
2828

@@ -32,20 +32,20 @@
3232
# @{ ModuleName = 'Pester'; ModuleVersion = '4.8.1' },
3333
# @{ ModuleName = 'PSScriptAnalyzer'; ModuleVersion = '1.18.0' }
3434
#)
35-
35+
3636
# Minimum version of the PowerShell engine required by this module
3737
PowerShellVersion = '5.1'
38-
38+
3939
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
4040
CmdletsToExport = @()
41-
41+
4242
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
4343
FunctionsToExport = @(
44-
'Get-BuildConfiguration', 'Invoke-ModuleBuild', 'Publish-ModulePackage', 'Install-ModulePackageForTest', 'Invoke-ModuleTests')
45-
44+
'Get-BuildConfiguration', 'Invoke-ModuleBuild', 'Publish-ModulePackage', 'Install-ModulePackageForTest', 'Invoke-ModuleTests', 'Invoke-ModuleTestsACR')
45+
4646
# Variables to export from this module
4747
VariablesToExport = '*'
48-
48+
4949
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
5050
AliasesToExport = @()
5151
}

Diff for: buildtools.psm1

+28-2
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,29 @@ function Install-ModulePackageForTest {
126126
Unregister-PSResourceRepository -Name $localRepoName -Confirm:$false
127127
}
128128

129+
function Invoke-ModuleTestsACR {
130+
[CmdletBinding()]
131+
param (
132+
[ValidateSet("Functional", "StaticAnalysis")]
133+
[string[]] $Type = "Functional"
134+
)
135+
136+
$acrTestFiles = @(
137+
"FindPSResourceTests/FindPSResourceACRServer.Tests.ps1",
138+
"InstallPSResourceTests/InstallPSResourceACRServer.Tests.ps1",
139+
"PublishPSResourceTests/PublishPSResourceACRServer.Tests.ps1"
140+
)
141+
142+
Invoke-ModuleTests -Type $Type -TestFilePath $acrTestFiles
143+
}
144+
145+
129146
function Invoke-ModuleTests {
130147
[CmdletBinding()]
131148
param (
132149
[ValidateSet("Functional", "StaticAnalysis")]
133-
[string[]] $Type = "Functional"
150+
[string[]] $Type = "Functional",
151+
[string[]] $TestFilePath = "."
134152
)
135153

136154
Write-Verbose -Verbose -Message "Starting module Pester tests..."
@@ -143,7 +161,15 @@ function Invoke-ModuleTests {
143161
$testPath = $config.TestPath
144162
Write-Verbose -Verbose $config.ModuleName
145163
$moduleToTest = Join-Path -Path $config.BuildOutputPath -ChildPath "Microsoft.PowerShell.PSResourceGet"
146-
$command = "Import-Module -Name ${moduleToTest} -Force -Verbose; Set-Location -Path ${testPath}; Invoke-Pester -Path . -OutputFile ${testResultFileName} -Tags '${tags}' -ExcludeTag '${excludeTag}'"
164+
165+
if ($TestFilePath.Count -gt 1) {
166+
$TestFilePathJoined = $TestFilePath -join ','
167+
}
168+
else {
169+
$TestFilePathJoined = $TestFilePath
170+
}
171+
172+
$command = "Import-Module -Name ${moduleToTest} -Force -Verbose; Set-Location -Path ${testPath}; Invoke-Pester -Script ${TestFilePathJoined} -OutputFile ${testResultFileName} -Tags '${tags}' -ExcludeTag '${excludeTag}'"
147173
$pwshExePath = (Get-Process -Id $pid).Path
148174

149175
Write-Verbose -Verbose -Message "Running Pester tests with command: $command using pwsh.exe path: $pwshExePath"

Diff for: doBuild.ps1

+16-3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ function DoBuild
7676
)
7777

7878
$depAssemblyNames = @(
79+
'Azure.Core'
80+
'Azure.Identity'
81+
'Microsoft.Bcl.AsyncInterfaces'
82+
'Microsoft.Extensions.FileProviders.Abstractions'
83+
'Microsoft.Extensions.FileSystemGlobbing'
84+
'Microsoft.Extensions.Primitives'
85+
'Microsoft.Identity.Client'
86+
'Microsoft.Identity.Client.Extensions.Msal'
87+
'Microsoft.IdentityModel.Abstractions'
88+
'Newtonsoft.Json'
7989
'NuGet.Commands'
8090
'NuGet.Common'
8191
'NuGet.Configuration'
@@ -87,16 +97,19 @@ function DoBuild
8797
'NuGet.ProjectModel'
8898
'NuGet.Protocol'
8999
'NuGet.Versioning'
90-
'Newtonsoft.Json'
91-
'System.Text.Json'
92100
'System.Buffers'
101+
'System.Diagnostics.DiagnosticSource'
102+
'System.IO.FileSystem.AccessControl'
103+
'System.Memory.Data'
93104
'System.Memory'
94105
'System.Numerics.Vectors'
95106
'System.Runtime.CompilerServices.Unsafe'
107+
'System.Security.AccessControl'
108+
'System.Security.Cryptography.ProtectedData'
109+
'System.Security.Principal.Windows'
96110
'System.Text.Encodings.Web'
97111
'System.Text.Json'
98112
'System.Threading.Tasks.Extensions'
99-
'Microsoft.Bcl.AsyncInterfaces'
100113
'System.ValueTuple'
101114
)
102115

0 commit comments

Comments
 (0)