Additional clean up
This commit is contained in:
parent
cbff29908b
commit
b4ff6c4578
@ -4,8 +4,6 @@ Param (
|
|||||||
[array] $ArtifactList,
|
[array] $ArtifactList,
|
||||||
[Parameter(Mandatory=$False)]
|
[Parameter(Mandatory=$False)]
|
||||||
[string] $ArtifactPath,
|
[string] $ArtifactPath,
|
||||||
[Parameter(Mandatory=$False)]
|
|
||||||
[string] $APIKey,
|
|
||||||
[string] $SourceBranch,
|
[string] $SourceBranch,
|
||||||
[string] $DefaultBranch,
|
[string] $DefaultBranch,
|
||||||
[string] $RepoName,
|
[string] $RepoName,
|
||||||
@ -25,23 +23,21 @@ Set-StrictMode -Version 3
|
|||||||
. (Join-Path $PSScriptRoot Helpers ApiView-Helpers.ps1)
|
. (Join-Path $PSScriptRoot Helpers ApiView-Helpers.ps1)
|
||||||
|
|
||||||
# Get Bearer token for APIView authentication
|
# Get Bearer token for APIView authentication
|
||||||
# Uses Azure CLI to get an access token for the specified audience
|
function Get-ApiViewBearerToken()
|
||||||
function Get-ApiViewBearerToken($audience)
|
|
||||||
{
|
{
|
||||||
|
$audience = "api://apiview"
|
||||||
try {
|
try {
|
||||||
Write-Host "Acquiring access token for audience: $audience"
|
|
||||||
$tokenResponse = az account get-access-token --resource $audience --output json | ConvertFrom-Json
|
$tokenResponse = az account get-access-token --resource $audience --output json | ConvertFrom-Json
|
||||||
if ($tokenResponse -and $tokenResponse.accessToken) {
|
if ($tokenResponse -and $tokenResponse.accessToken) {
|
||||||
Write-Host "Successfully acquired access token"
|
|
||||||
return $tokenResponse.accessToken
|
return $tokenResponse.accessToken
|
||||||
}
|
}
|
||||||
else {
|
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
|
return $null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Host "Failed to acquire access token: $($_.Exception.Message)" -ForegroundColor Yellow
|
Write-Error "Failed to acquire access token: $($_.Exception.Message)"
|
||||||
return $null
|
return $null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,18 +99,16 @@ function Upload-SourceArtifact($filePath, $apiLabel, $releaseStatus, $packageVer
|
|||||||
|
|
||||||
$uri = "${APIViewUri}/upload"
|
$uri = "${APIViewUri}/upload"
|
||||||
|
|
||||||
# Get Bearer token for authentication (preferred) or fall back to API key
|
# Get Bearer token for authentication
|
||||||
$bearerToken = Get-ApiViewBearerToken $APIViewAudience
|
$bearerToken = Get-ApiViewBearerToken
|
||||||
if ($bearerToken) {
|
if (-not $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
|
|
||||||
return 401
|
return 401
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$headers = @{
|
||||||
|
"Authorization" = "Bearer $bearerToken";
|
||||||
|
"content-type" = "multipart/form-data"
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -155,17 +149,15 @@ function Upload-ReviewTokenFile($packageName, $apiLabel, $releaseStatus, $review
|
|||||||
|
|
||||||
Write-Host "Request to APIView: $uri"
|
Write-Host "Request to APIView: $uri"
|
||||||
|
|
||||||
# Get Bearer token for authentication (preferred) or fall back to API key
|
# Get Bearer token for authentication
|
||||||
$bearerToken = Get-ApiViewBearerToken $APIViewAudience
|
$bearerToken = Get-ApiViewBearerToken
|
||||||
if ($bearerToken) {
|
if (-not $bearerToken) {
|
||||||
$headers = @{
|
|
||||||
"Authorization" = "Bearer $bearerToken"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Write-Host "ERROR: No authentication method available. Either Azure CLI login or APIKey is required." -ForegroundColor Red
|
|
||||||
return 401
|
return 401
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$headers = @{
|
||||||
|
"Authorization" = "Bearer $bearerToken"
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user