Revert "Use authenticated GitHub request when env variable is present (#12267)" (#6766)

This reverts commit d60198ec38489bc37b8544484519b638d4fa7eca.

Co-authored-by: Scott Beddall <scbedd@microsoft.com>
This commit is contained in:
Azure SDK Bot 2025-10-02 15:03:34 -07:00 committed by GitHub
parent cfc9354584
commit 524d7bc15f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -105,39 +105,6 @@ function isNewVersion(
return $true
}
function Get-GitHubApiHeaders {
# Use GitHub cli to get an auth token if available
$token = ""
if (Get-Command gh -ErrorAction SilentlyContinue) {
try
{
$token = gh auth token 2>$null
}
catch
{
Write-Host "Failed to get GitHub CLI auth token."
}
}
# Get token from env if not available from gh cli
if (!$token)
{
Write-Host "Checking for GITHUB_TOKEN environment variable."
$token = $env:GITHUB_TOKEN
}
if ($token)
{
Write-Host "Using authenticated GitHub API requests."
$headers = @{
Authorization = "Bearer $token"
}
return $headers
}
Write-Host "Using unauthenticated GitHub API requests."
return @{}
}
<#
.SYNOPSIS
Installs a standalone version of an engsys tool.
@ -168,12 +135,11 @@ function Install-Standalone-Tool (
}
$tag = "${Package}_${Version}"
$headers = Get-GitHubApiHeaders
if (!$Version -or $Version -eq "*") {
Write-Host "Attempting to find latest version for package '$Package'"
$releasesUrl = "https://api.github.com/repos/$Repository/releases"
$releases = Invoke-RestMethod -Uri $releasesUrl -Headers $headers
$releases = Invoke-RestMethod -Uri $releasesUrl
$found = $false
foreach ($release in $releases) {
if ($release.tag_name -like "$Package*") {
@ -197,7 +163,7 @@ function Install-Standalone-Tool (
if (isNewVersion $version $downloadFolder) {
Write-Host "Installing '$Package' '$Version' to '$downloadFolder' from $downloadUrl"
Invoke-WebRequest -Uri $downloadUrl -OutFile $downloadLocation -Headers $headers
Invoke-WebRequest -Uri $downloadUrl -OutFile $downloadLocation
if ($downloadFile -like "*.zip") {
Expand-Archive -Path $downloadLocation -DestinationPath $downloadFolder -Force