From b4ff6c45784288dbf88a9f6ecfbd6f788eff07fd Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Date: Mon, 8 Dec 2025 16:01:28 -0800 Subject: [PATCH] Additional clean up --- eng/common/scripts/Create-APIReview.ps1 | 46 ++++++++++--------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/eng/common/scripts/Create-APIReview.ps1 b/eng/common/scripts/Create-APIReview.ps1 index bd57d9eb1..017630681 100644 --- a/eng/common/scripts/Create-APIReview.ps1 +++ b/eng/common/scripts/Create-APIReview.ps1 @@ -4,8 +4,6 @@ Param ( [array] $ArtifactList, [Parameter(Mandatory=$False)] [string] $ArtifactPath, - [Parameter(Mandatory=$False)] - [string] $APIKey, [string] $SourceBranch, [string] $DefaultBranch, [string] $RepoName, @@ -25,23 +23,21 @@ Set-StrictMode -Version 3 . (Join-Path $PSScriptRoot Helpers ApiView-Helpers.ps1) # Get Bearer token for APIView authentication -# Uses Azure CLI to get an access token for the specified audience -function Get-ApiViewBearerToken($audience) +function Get-ApiViewBearerToken() { + $audience = "api://apiview" try { - Write-Host "Acquiring access token for audience: $audience" $tokenResponse = az account get-access-token --resource $audience --output json | ConvertFrom-Json if ($tokenResponse -and $tokenResponse.accessToken) { - Write-Host "Successfully acquired access token" return $tokenResponse.accessToken } else { - Write-Host "Failed to acquire access token - no token in response" -ForegroundColor Yellow + Write-Error "Failed to acquire access token - no token in response" return $null } } catch { - Write-Host "Failed to acquire access token: $($_.Exception.Message)" -ForegroundColor Yellow + Write-Error "Failed to acquire access token: $($_.Exception.Message)" return $null } } @@ -103,18 +99,16 @@ function Upload-SourceArtifact($filePath, $apiLabel, $releaseStatus, $packageVer $uri = "${APIViewUri}/upload" - # Get Bearer token for authentication (preferred) or fall back to API key - $bearerToken = Get-ApiViewBearerToken $APIViewAudience - if ($bearerToken) { - $headers = @{ - "Authorization" = "Bearer $bearerToken"; - "content-type" = "multipart/form-data" - } - } - else { - Write-Host "ERROR: No authentication method available. Either Azure CLI login or APIKey is required." -ForegroundColor Red + # Get Bearer token for authentication + $bearerToken = Get-ApiViewBearerToken + if (-not $bearerToken) { return 401 } + + $headers = @{ + "Authorization" = "Bearer $bearerToken"; + "content-type" = "multipart/form-data" + } try { @@ -155,17 +149,15 @@ function Upload-ReviewTokenFile($packageName, $apiLabel, $releaseStatus, $review Write-Host "Request to APIView: $uri" - # Get Bearer token for authentication (preferred) or fall back to API key - $bearerToken = Get-ApiViewBearerToken $APIViewAudience - if ($bearerToken) { - $headers = @{ - "Authorization" = "Bearer $bearerToken" - } - } - else { - Write-Host "ERROR: No authentication method available. Either Azure CLI login or APIKey is required." -ForegroundColor Red + # Get Bearer token for authentication + $bearerToken = Get-ApiViewBearerToken + if (-not $bearerToken) { return 401 } + + $headers = @{ + "Authorization" = "Bearer $bearerToken" + } try {