Keep apikey fallback while migrating
This commit is contained in:
parent
b4ff6c4578
commit
ef74176810
@ -2,8 +2,10 @@
|
|||||||
Param (
|
Param (
|
||||||
[Parameter(Mandatory=$False)]
|
[Parameter(Mandatory=$False)]
|
||||||
[array] $ArtifactList,
|
[array] $ArtifactList,
|
||||||
[Parameter(Mandatory=$False)]
|
[Parameter(Mandatory=$True)]
|
||||||
[string] $ArtifactPath,
|
[string] $ArtifactPath,
|
||||||
|
[Parameter(Mandatory=$False)]
|
||||||
|
[string] $APIKey,
|
||||||
[string] $SourceBranch,
|
[string] $SourceBranch,
|
||||||
[string] $DefaultBranch,
|
[string] $DefaultBranch,
|
||||||
[string] $RepoName,
|
[string] $RepoName,
|
||||||
@ -27,17 +29,13 @@ function Get-ApiViewBearerToken()
|
|||||||
{
|
{
|
||||||
$audience = "api://apiview"
|
$audience = "api://apiview"
|
||||||
try {
|
try {
|
||||||
$tokenResponse = az account get-access-token --resource $audience --output json | ConvertFrom-Json
|
$tokenResponse = az account get-access-token --resource $audience --output json 2>$null | ConvertFrom-Json
|
||||||
if ($tokenResponse -and $tokenResponse.accessToken) {
|
if ($tokenResponse -and $tokenResponse.accessToken) {
|
||||||
return $tokenResponse.accessToken
|
return $tokenResponse.accessToken
|
||||||
}
|
}
|
||||||
else {
|
return $null
|
||||||
Write-Error "Failed to acquire access token - no token in response"
|
|
||||||
return $null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Error "Failed to acquire access token: $($_.Exception.Message)"
|
|
||||||
return $null
|
return $null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -99,15 +97,24 @@ function Upload-SourceArtifact($filePath, $apiLabel, $releaseStatus, $packageVer
|
|||||||
|
|
||||||
$uri = "${APIViewUri}/upload"
|
$uri = "${APIViewUri}/upload"
|
||||||
|
|
||||||
# Get Bearer token for authentication
|
# Try Bearer token first, fall back to API key
|
||||||
$bearerToken = Get-ApiViewBearerToken
|
$bearerToken = Get-ApiViewBearerToken
|
||||||
if (-not $bearerToken) {
|
if ($bearerToken) {
|
||||||
return 401
|
$headers = @{
|
||||||
|
"Authorization" = "Bearer $bearerToken";
|
||||||
|
"content-type" = "multipart/form-data"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
elseif ($APIKey) {
|
||||||
$headers = @{
|
Write-Warning "##[warning]Bearer token acquisition failed - falling back to API key."
|
||||||
"Authorization" = "Bearer $bearerToken";
|
$headers = @{
|
||||||
"content-type" = "multipart/form-data"
|
"ApiKey" = $APIKey;
|
||||||
|
"content-type" = "multipart/form-data"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Error "No authentication available. Either configure AzureCLI@2 task or provide APIKey."
|
||||||
|
return 401
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -149,14 +156,22 @@ function Upload-ReviewTokenFile($packageName, $apiLabel, $releaseStatus, $review
|
|||||||
|
|
||||||
Write-Host "Request to APIView: $uri"
|
Write-Host "Request to APIView: $uri"
|
||||||
|
|
||||||
# Get Bearer token for authentication
|
# Try Bearer token first, fall back to API key
|
||||||
$bearerToken = Get-ApiViewBearerToken
|
$bearerToken = Get-ApiViewBearerToken
|
||||||
if (-not $bearerToken) {
|
if ($bearerToken) {
|
||||||
return 401
|
$headers = @{
|
||||||
|
"Authorization" = "Bearer $bearerToken"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
elseif ($APIKey) {
|
||||||
$headers = @{
|
Write-Warning "##[warning]Bearer token acquisition failed - falling back to API key. Please migrate to using AzureCLI@2 task with service connection."
|
||||||
"Authorization" = "Bearer $bearerToken"
|
$headers = @{
|
||||||
|
"ApiKey" = $APIKey
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Error "No authentication available. Either configure AzureCLI@2 task or provide APIKey."
|
||||||
|
return 401
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user