From 28ae0f9bba435f06a307fb274eb95f3b147fc72f Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Date: Mon, 8 Dec 2025 16:10:25 -0800 Subject: [PATCH] Keep migration to new endpoint --- eng/common/scripts/Create-APIReview.ps1 | 51 +++++++++---------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/eng/common/scripts/Create-APIReview.ps1 b/eng/common/scripts/Create-APIReview.ps1 index 33b1fe391..3f1f3174d 100644 --- a/eng/common/scripts/Create-APIReview.ps1 +++ b/eng/common/scripts/Create-APIReview.ps1 @@ -1,11 +1,9 @@ [CmdletBinding()] Param ( - [Parameter(Mandatory=$False)] - [array] $ArtifactList, [Parameter(Mandatory=$True)] - [string] $ArtifactPath, + [array] $ArtifactList, [Parameter(Mandatory=$False)] - [string] $APIKey, + [string] $ArtifactPath, [string] $SourceBranch, [string] $DefaultBranch, [string] $RepoName, @@ -97,25 +95,17 @@ function Upload-SourceArtifact($filePath, $apiLabel, $releaseStatus, $packageVer $uri = "${APIViewUri}/upload" - # Try Bearer token first, fall back to API key + # Get Bearer token for authentication $bearerToken = Get-ApiViewBearerToken - if ($bearerToken) { - $headers = @{ - "Authorization" = "Bearer $bearerToken"; - "content-type" = "multipart/form-data" - } - } - elseif ($APIKey) { - Write-Warning "##[warning]Bearer token acquisition failed - falling back to API key." - $headers = @{ - "ApiKey" = $APIKey; - "content-type" = "multipart/form-data" - } - } - else { - Write-Error "No authentication available. Either configure AzureCLI@2 task or provide APIKey." + if (-not $bearerToken) { + Write-Error "Failed to acquire Bearer token for APIView authentication." return 401 } + + $headers = @{ + "Authorization" = "Bearer $bearerToken"; + "content-type" = "multipart/form-data" + } try { @@ -156,23 +146,16 @@ function Upload-ReviewTokenFile($packageName, $apiLabel, $releaseStatus, $review Write-Host "Request to APIView: $uri" - # Try Bearer token first, fall back to API key + # Get Bearer token for authentication $bearerToken = Get-ApiViewBearerToken - if ($bearerToken) { - $headers = @{ - "Authorization" = "Bearer $bearerToken" - } - } - elseif ($APIKey) { - Write-Warning "##[warning]Bearer token acquisition failed - falling back to API key. Please migrate to using AzureCLI@2 task with service connection." - $headers = @{ - "ApiKey" = $APIKey - } - } - else { - Write-Error "No authentication available. Either configure AzureCLI@2 task or provide APIKey." + if (-not $bearerToken) { + Write-Error "Failed to acquire Bearer token for APIView authentication." return 401 } + + $headers = @{ + "Authorization" = "Bearer $bearerToken" + } try {