Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
10 changes: 6 additions & 4 deletions eng/common/scripts/Helpers/Metadata-Helpers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ function Generate-AadToken ($TenantId, $ClientId, $ClientSecret)
return $resp.access_token
}

function GetAllGithubUsers ([string]$TenantId, [string]$ClientId, [string]$ClientSecret)
function GetAllGithubUsers ([string]$TenantId, [string]$ClientId, [string]$ClientSecret, [string]$Token)
{
# API documentation (out of date): https://github.com/microsoft/opensource-management-portal/blob/main/docs/api.md
# API documentation: https://github.com/1ES-microsoft/opensource-management-portal/blob/trunk/docs/microsoft.api.md
$OpensourceAPIBaseURI = "https://repos.opensource.microsoft.com/api/people/links"

$Headers = @{
Expand All @@ -28,8 +28,10 @@ function GetAllGithubUsers ([string]$TenantId, [string]$ClientId, [string]$Clien
}

try {
$opsAuthToken = Generate-AadToken -TenantId $TenantId -ClientId $ClientId -ClientSecret $ClientSecret
$Headers["Authorization"] = "Bearer $opsAuthToken"
if (!$Token) {
$Token = Generate-AadToken -TenantId $TenantId -ClientId $ClientId -ClientSecret $ClientSecret
}
$Headers["Authorization"] = "Bearer $Token"
Write-Host "Fetching all github alias links"
$resp = Invoke-RestMethod $OpensourceAPIBaseURI -Method 'GET' -Headers $Headers -MaximumRetryCount 3
} catch {
Expand Down
14 changes: 11 additions & 3 deletions eng/pipelines/live-test-cleanup-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ steps:
parameters:
SubscriptionConfigurations: ${{ parameters.SubscriptionConfigurations }}

- task: AzureCLI@2
displayName: Authenticate to OpenSource API
inputs:
azureSubscription: opensource-api-connection
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
$jwt_accessToken = az account get-access-token --scope 2789159d-8d8b-4d13-b90b-ca29c1707afd/.default --query "accessToken" --output tsv
Write-Host "##vso[task.setvariable variable=opensource-api-token;isSecret=true]$jwt_accessToken"

- pwsh: |
eng/common/scripts/Import-AzModules.ps1
Import-Module Az.Accounts
Expand All @@ -28,9 +38,7 @@ steps:
'@ | ConvertFrom-Json -AsHashtable

./eng/scripts/live-test-resource-cleanup.ps1 `
-OpensourceApiApplicationId $(opensource-aad-app-id) `
-OpensourceApiApplicationSecret $(opensource-aad-secret) `
-OpensourceApiApplicationTenant $(opensource-aad-tenant-id) `
-OpensourceApiApplicationToken $(opensource-api-token) `
-GithubAliasCachePath ${{ parameters.GithubAliasCachePath }} `
@subscriptionConfiguration `
-Verbose `
Expand Down
12 changes: 2 additions & 10 deletions eng/scripts/live-test-resource-cleanup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,9 @@ param (
[ValidateNotNullOrEmpty()]
[string] $ProvisionerApplicationSecret,

[Parameter(ParameterSetName = 'Provisioner', Mandatory = $true)]
[ValidatePattern('^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$')]
[string] $OpensourceApiApplicationId,

[Parameter(ParameterSetName = 'Provisioner', Mandatory = $true)]
[ValidatePattern('^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$')]
[string] $OpensourceApiApplicationTenantId,

[Parameter(ParameterSetName = 'Provisioner', Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $OpensourceApiApplicationSecret,
[string] $OpensourceApiApplicationToken,

[Parameter(ParameterSetName = 'Provisioner', Mandatory = $true)]
[Parameter(ParameterSetName = 'Interactive')]
Expand Down Expand Up @@ -167,7 +159,7 @@ function AddGithubUsersToAliasCache() {
$users = Get-Content $GithubAliasCachePath | ConvertFrom-Json -AsHashtable
} else {
Write-Host "Retrieving github -> microsoft alias mappings from opensource API."
$users = GetAllGithubUsers $OpensourceApiApplicationTenantId $OpensourceApiApplicationId $OpensourceApiApplicationSecret
$users = GetAllGithubUsers -Token $OpensourceApiApplicationToken
}
if (!$users) {
Write-Error "Failed to retrieve github -> microsoft alias mappings from opensource api."
Expand Down