Skip to content

Commit 8f84778

Browse files
praveenkuttappanazure-sdk
authored andcommitted
Use authenticated GitHub request when env variable is present
1 parent 77f044b commit 8f84778

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

eng/common/scripts/Helpers/AzSdkTool-Helpers.ps1

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@ function isNewVersion(
105105
return $true
106106
}
107107

108+
function Get-GitHubApiHeaders {
109+
$token = $env:GITHUB_TOKEN
110+
if ($token)
111+
{
112+
Write-Host "Using authenticated GitHub API requests to install MCP server."
113+
$headers = @{
114+
Authorization = "bearer $token"
115+
}
116+
return $headers
117+
}
118+
return @{}
119+
}
120+
108121
<#
109122
.SYNOPSIS
110123
Installs a standalone version of an engsys tool.
@@ -135,11 +148,12 @@ function Install-Standalone-Tool (
135148
}
136149

137150
$tag = "${Package}_${Version}"
151+
$headers = Get-GitHubApiHeaders
138152

139153
if (!$Version -or $Version -eq "*") {
140154
Write-Host "Attempting to find latest version for package '$Package'"
141155
$releasesUrl = "https://api.github.com/repos/$Repository/releases"
142-
$releases = Invoke-RestMethod -Uri $releasesUrl
156+
$releases = Invoke-RestMethod -Uri $releasesUrl -Headers $headers
143157
$found = $false
144158
foreach ($release in $releases) {
145159
if ($release.tag_name -like "$Package*") {
@@ -163,7 +177,7 @@ function Install-Standalone-Tool (
163177

164178
if (isNewVersion $version $downloadFolder) {
165179
Write-Host "Installing '$Package' '$Version' to '$downloadFolder' from $downloadUrl"
166-
Invoke-WebRequest -Uri $downloadUrl -OutFile $downloadLocation
180+
Invoke-WebRequest -Uri $downloadUrl -OutFile $downloadLocation -Headers $headers
167181

168182
if ($downloadFile -like "*.zip") {
169183
Expand-Archive -Path $downloadLocation -DestinationPath $downloadFolder -Force

0 commit comments

Comments
 (0)