@@ -4,25 +4,42 @@ Param (
44 [array ] $ArtifactList ,
55 [Parameter (Mandatory = $True )]
66 [string ] $ArtifactPath ,
7- [Parameter (Mandatory = $True )]
8- [string ] $APIKey ,
97 [string ] $SourceBranch ,
108 [string ] $DefaultBranch ,
119 [string ] $RepoName ,
1210 [string ] $BuildId ,
1311 [string ] $PackageName = " " ,
1412 [string ] $ConfigFileDir = " " ,
15- [string ] $APIViewUri = " https://apiview.dev/AutoReview " ,
13+ [string ] $APIViewUri = " https://apiview.dev/autoreview " ,
1614 [string ] $ArtifactName = " packages" ,
1715 [bool ] $MarkPackageAsShipped = $false ,
1816 [Parameter (Mandatory = $False )]
1917 [array ] $PackageInfoFiles
2018)
2119
2220Set-StrictMode - Version 3
21+
2322. (Join-Path $PSScriptRoot common.ps1)
2423. (Join-Path $PSScriptRoot Helpers ApiView- Helpers.ps1)
2524
25+ # Get Bearer token for APIView authentication
26+ # In Azure DevOps, this uses the service connection's Managed Identity/Service Principal
27+ function Get-ApiViewBearerToken ()
28+ {
29+ try {
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
34+ }
35+ return ($tokenResponse | ConvertFrom-Json ).accessToken
36+ }
37+ catch {
38+ Write-Error " Failed to acquire access token: $ ( $_.Exception.Message ) "
39+ return $null
40+ }
41+ }
42+
2643# Submit API review request and return status whether current revision is approved or pending or failed to create review
2744function Upload-SourceArtifact ($filePath , $apiLabel , $releaseStatus , $packageVersion , $packageType )
2845{
@@ -78,9 +95,17 @@ function Upload-SourceArtifact($filePath, $apiLabel, $releaseStatus, $packageVer
7895 Write-Host " Request param, compareAllRevisions: true"
7996 }
8097
81- $uri = " ${APIViewUri} /UploadAutoReview"
98+ $uri = " ${APIViewUri} /upload"
99+
100+ # Get Bearer token for authentication
101+ $bearerToken = Get-ApiViewBearerToken
102+ if (-not $bearerToken ) {
103+ Write-Error " Failed to acquire Bearer token for APIView authentication."
104+ return [System.Net.HttpStatusCode ]::Unauthorized
105+ }
106+
82107 $headers = @ {
83- " ApiKey " = $apiKey ;
108+ " Authorization " = " Bearer $bearerToken " ;
84109 " content-type" = " multipart/form-data"
85110 }
86111
@@ -115,20 +140,28 @@ function Upload-ReviewTokenFile($packageName, $apiLabel, $releaseStatus, $review
115140 if ($MarkPackageAsShipped ) {
116141 $params += " &setReleaseTag=true"
117142 }
118- $uri = " ${APIViewUri} /CreateApiReview ?${params} "
143+ $uri = " ${APIViewUri} /create ?${params} "
119144 if ($releaseStatus -and ($releaseStatus -ne " Unreleased" ))
120145 {
121146 $uri += " &compareAllRevisions=true"
122147 }
123148
124149 Write-Host " Request to APIView: $uri "
150+
151+ # Get Bearer token for authentication
152+ $bearerToken = Get-ApiViewBearerToken
153+ if (-not $bearerToken ) {
154+ Write-Error " Failed to acquire Bearer token for APIView authentication."
155+ return [System.Net.HttpStatusCode ]::Unauthorized
156+ }
157+
125158 $headers = @ {
126- " ApiKey " = $APIKey ;
159+ " Authorization " = " Bearer $bearerToken "
127160 }
128161
129162 try
130163 {
131- $Response = Invoke-WebRequest - Method ' GET ' - Uri $uri - Headers $headers
164+ $Response = Invoke-WebRequest - Method ' POST ' - Uri $uri - Headers $headers
132165 Write-Host " API review: $ ( $Response.Content ) "
133166 $StatusCode = $Response.StatusCode
134167 }
0 commit comments