From cbff29908b82f5112d0c776f407230423915077b Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Date: Mon, 8 Dec 2025 15:52:53 -0800 Subject: [PATCH] Remove testing logs --- .../templates/steps/create-apireview.yml | 17 +---- eng/common/scripts/Create-APIReview.ps1 | 64 +------------------ 2 files changed, 2 insertions(+), 79 deletions(-) diff --git a/eng/common/pipelines/templates/steps/create-apireview.yml b/eng/common/pipelines/templates/steps/create-apireview.yml index e6289f60e..b65251c1e 100644 --- a/eng/common/pipelines/templates/steps/create-apireview.yml +++ b/eng/common/pipelines/templates/steps/create-apireview.yml @@ -29,26 +29,11 @@ parameters: - name: AzureServiceConnection type: string default: 'APIView prod deployment' - - name: TestAuthOnly - type: boolean - default: true # TEMPORARY: Set to true for testing Bearer auth, revert to false before merging steps: - # Test authentication mode - just verify Bearer token works - - ${{ if eq(parameters.TestAuthOnly, true) }}: - - task: AzureCLI@2 - inputs: - azureSubscription: ${{ parameters.AzureServiceConnection }} - scriptType: pscore - scriptLocation: scriptPath - scriptPath: ${{ parameters.SourceRootPath }}/eng/common/scripts/Create-APIReview.ps1 - arguments: -TestAuth - displayName: Test APIView Bearer Token Authentication - condition: succeededOrFailed() - # Automatic API review is generated for a package when pipeline runs irrespective of how pipeline gets triggered. # Below condition ensures that API review is generated only for manual pipeline runs when flag GenerateApiReviewForManualOnly is set to true. - - ${{ if and(ne(parameters.TestAuthOnly, true), or(ne(parameters.GenerateApiReviewForManualOnly, true), eq(variables['Build.Reason'], 'Manual'))) }}: + - ${{ if or(ne(parameters.GenerateApiReviewForManualOnly, true), eq(variables['Build.Reason'], 'Manual')) }}: # ideally this should be done as initial step of a job in caller template # We can remove this step later once it is added in caller - template: /eng/common/pipelines/templates/steps/set-default-branch.yml diff --git a/eng/common/scripts/Create-APIReview.ps1 b/eng/common/scripts/Create-APIReview.ps1 index 74c524a14..bd57d9eb1 100644 --- a/eng/common/scripts/Create-APIReview.ps1 +++ b/eng/common/scripts/Create-APIReview.ps1 @@ -16,73 +16,11 @@ Param ( [string] $ArtifactName = "packages", [bool] $MarkPackageAsShipped = $false, [Parameter(Mandatory=$False)] - [array] $PackageInfoFiles, - [string] $APIViewAudience = "api://apiview", - [switch] $TestAuth + [array] $PackageInfoFiles ) Set-StrictMode -Version 3 -# Test authentication mode - just verify Bearer token works and exit -if ($TestAuth) { - Write-Host "=== APIView Authentication Test Mode ===" -ForegroundColor Cyan - Write-Host "Testing Bearer token authentication against APIView..." - Write-Host "" - - try { - Write-Host "Step 1: Acquiring access token for audience: $APIViewAudience" - $tokenResponse = az account get-access-token --resource $APIViewAudience --output json 2>&1 - if ($LASTEXITCODE -ne 0) { - Write-Host "FAILED: Could not acquire token. Error: $tokenResponse" -ForegroundColor Red - Write-Host "Make sure you are logged in with 'az login'" -ForegroundColor Yellow - exit 1 - } - $parsed = $tokenResponse | ConvertFrom-Json - Write-Host "SUCCESS: Token acquired! Expires: $($parsed.expiresOn)" -ForegroundColor Green - Write-Host "" - - Write-Host "Step 2: Testing authenticated request to APIView..." - $headers = @{ - "Authorization" = "Bearer $($parsed.accessToken)" - } - - # Make a simple GET request to verify the token is accepted - # Using the reviews endpoint which should return 200 or redirect if auth works - $testUri = "https://apiview.dev/api/reviews" - Write-Host "Calling: GET $testUri" - - try { - $response = Invoke-WebRequest -Uri $testUri -Headers $headers -Method GET -MaximumRedirection 0 -ErrorAction Stop - Write-Host "SUCCESS: API responded with status $($response.StatusCode)" -ForegroundColor Green - } - catch { - $statusCode = $_.Exception.Response.StatusCode.Value__ - if ($statusCode -eq 401 -or $statusCode -eq 403) { - Write-Host "FAILED: Authentication rejected (HTTP $statusCode)" -ForegroundColor Red - Write-Host "The token was acquired but APIView rejected it." -ForegroundColor Yellow - Write-Host "This may indicate the service principal doesn't have access." -ForegroundColor Yellow - exit 1 - } - elseif ($statusCode -ge 200 -and $statusCode -lt 400) { - Write-Host "SUCCESS: API responded with status $statusCode" -ForegroundColor Green - } - else { - Write-Host "WARNING: API responded with status $statusCode" -ForegroundColor Yellow - Write-Host "This may be expected depending on the endpoint. Auth likely worked." -ForegroundColor Yellow - } - } - - Write-Host "" - Write-Host "=== Authentication Test Complete ===" -ForegroundColor Cyan - Write-Host "Bearer token authentication is working!" -ForegroundColor Green - exit 0 - } - catch { - Write-Host "FAILED: Unexpected error: $($_.Exception.Message)" -ForegroundColor Red - exit 1 - } -} - . (Join-Path $PSScriptRoot common.ps1) . (Join-Path $PSScriptRoot Helpers ApiView-Helpers.ps1)