Skip to content

Commit a8c58f1

Browse files
AlitzelMendezazure-sdk
authored andcommitted
Feedback
1 parent 9f64f19 commit a8c58f1

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

eng/common/pipelines/templates/steps/create-apireview.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ parameters:
2626
- name: PackageInfoFiles
2727
type: object
2828
default: []
29-
- name: AzureServiceConnection
30-
type: string
31-
default: 'APIView prod deployment'
3229

3330
steps:
3431
# Automatic API review is generated for a package when pipeline runs irrespective of how pipeline gets triggered.
@@ -42,7 +39,7 @@ steps:
4239

4340
- task: AzureCLI@2
4441
inputs:
45-
azureSubscription: ${{ parameters.AzureServiceConnection }}
42+
azureSubscription: 'APIView prod deployment'
4643
scriptType: pscore
4744
scriptLocation: scriptPath
4845
scriptPath: ${{ parameters.SourceRootPath }}/eng/common/scripts/Create-APIReview.ps1

eng/common/scripts/Create-APIReview.ps1

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,19 @@ Set-StrictMode -Version 3
2323
. (Join-Path $PSScriptRoot Helpers ApiView-Helpers.ps1)
2424

2525
# Get Bearer token for APIView authentication
26+
# In Azure DevOps, this uses the service connection's Managed Identity/Service Principal
2627
function Get-ApiViewBearerToken()
2728
{
28-
$audience = "api://apiview"
2929
try {
30-
$tokenResponse = az account get-access-token --resource $audience --output json 2>$null | ConvertFrom-Json
31-
if ($tokenResponse -and $tokenResponse.accessToken) {
32-
return $tokenResponse.accessToken
30+
$tokenResponse = az account get-access-token --resource "api://apiview" --output json 2>&1
31+
if ($LASTEXITCODE -ne 0) {
32+
Write-Error "Failed to acquire access token: $tokenResponse"
33+
return $null
3334
}
34-
return $null
35+
return ($tokenResponse | ConvertFrom-Json).accessToken
3536
}
3637
catch {
38+
Write-Error "Failed to acquire access token: $($_.Exception.Message)"
3739
return $null
3840
}
3941
}
@@ -99,7 +101,7 @@ function Upload-SourceArtifact($filePath, $apiLabel, $releaseStatus, $packageVer
99101
$bearerToken = Get-ApiViewBearerToken
100102
if (-not $bearerToken) {
101103
Write-Error "Failed to acquire Bearer token for APIView authentication."
102-
return 401
104+
return [System.Net.HttpStatusCode]::Unauthorized
103105
}
104106

105107
$headers = @{
@@ -150,7 +152,7 @@ function Upload-ReviewTokenFile($packageName, $apiLabel, $releaseStatus, $review
150152
$bearerToken = Get-ApiViewBearerToken
151153
if (-not $bearerToken) {
152154
Write-Error "Failed to acquire Bearer token for APIView authentication."
153-
return 401
155+
return [System.Net.HttpStatusCode]::Unauthorized
154156
}
155157

156158
$headers = @{

0 commit comments

Comments
 (0)