Skip to content

Commit

Permalink
Fix #799
Browse files Browse the repository at this point in the history
Replaces Invoke-WebRequest with Resolve-SystemNetWebRequest
  • Loading branch information
aaronparker committed Feb 22, 2025
1 parent 897313a commit 9340dc0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
20 changes: 12 additions & 8 deletions Evergreen/Apps/Get-mySQLConnectorNET.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,29 @@ function Get-mySQLConnectorNET {
$Version = ($Tags | Sort-Object -Property @{ Expression = { [System.Version]$_.Tag }; Descending = $true } | Select-Object -First 1).Tag

# Build the output object
if ($Null -ne $Version) {
if ($null -ne $Version) {
foreach ($Architecture in $res.Get.Download.Uri.GetEnumerator()) {

# https://dev.mysql.com/get/Downloads/Connector-ODBC/9.1/mysql-connector-odbc-9.1.0-winx64.msi
# https://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-workbench-community-8.0.40-winx64.msi
# redirect to
# https://cdn.mysql.com//Downloads/Connector-ODBC/9.1/mysql-connector-odbc-9.1.0-winx64.msi
# https://cdn.mysql.com//Downloads/MySQLGUITools/mysql-workbench-community-8.0.40-winx64.msi
#
# The sub path is only major.minor
# The version ist major.minor.patch, while the tag can have also have major.minor.patch.build
$Uri = $res.Get.Download.Uri[$Architecture.Key] -replace $res.Get.Download.ReplaceVersionShort, (($Version -split '\.')[0, 1] -join '.') -replace $res.Get.Download.ReplaceVersion, (($Version -split '\.')[0..2] -join '.')
$Uri = $res.Get.Download.Uri[$Architecture.Key] -replace $res.Get.Download.ReplaceVersion, (($Version -split '\.')[0..2] -join '.')
Write-Verbose -Message "$($MyInvocation.MyCommand): Resolving: $Uri"

# The website/CDN checks the user agent, which means that the call from e.g. Azure Automation is only possible by overwriting it
$CdnUri = (Invoke-WebRequest $Uri -MaximumRedirection 0 -UserAgent "Curl/8" -SkipHttpErrorCheck -ErrorAction:SilentlyContinue).Headers.Location[0]
$params = @{
Uri = $Uri
UserAgent = "Curl/8"
}
$CdnUri = Resolve-SystemNetWebRequest @params

$PSObject = [PSCustomObject] @{
Version = $Version
Type = Get-FileType -File $Uri
Architecture = $Architecture.Name
URI = $CdnUri
Type = Get-FileType -File $CdnUri.ResponseUri.AbsoluteUri
URI = $CdnUri.ResponseUri.AbsoluteUri -replace "com//", "com/"
}
Write-Output -InputObject $PSObject
}
Expand Down
17 changes: 11 additions & 6 deletions Evergreen/Apps/Get-mySQLConnectorODBC.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,29 @@ function Get-mySQLConnectorODBC {
$Version = ($Tags | Sort-Object -Property @{ Expression = { [System.Version]$_.Tag }; Descending = $true } | Select-Object -First 1).Tag

# Build the output object
if ($Null -ne $Version) {
if ($null -ne $Version) {
foreach ($Architecture in $res.Get.Download.Uri.GetEnumerator()) {

# https://dev.mysql.com/get/Downloads/Connector-Net/mysql-connector-net-9.1.0.msi
# https://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-workbench-community-8.0.40-winx64.msi
# redirect to
# https://cdn.mysql.com//Downloads/Connector-Net/mysql-connector-net-9.1.0.msi
# https://cdn.mysql.com//Downloads/MySQLGUITools/mysql-workbench-community-8.0.40-winx64.msi
#
# The version ist major.minor.patch, while the tag can have also have major.minor.patch.build
$Uri = $res.Get.Download.Uri[$Architecture.Key] -replace $res.Get.Download.ReplaceVersion, (($Version -split '\.')[0..2] -join '.')
Write-Verbose -Message "$($MyInvocation.MyCommand): Resolving: $Uri"

# The website/CDN checks the user agent, which means that the call from e.g. Azure Automation is only possible by overwriting it
$CdnUri = (Invoke-WebRequest $Uri -MaximumRedirection 0 -UserAgent "Curl/8" -SkipHttpErrorCheck -ErrorAction:SilentlyContinue).Headers.Location[0]
$params = @{
Uri = $Uri
UserAgent = "Curl/8"
}
$CdnUri = Resolve-SystemNetWebRequest @params

$PSObject = [PSCustomObject] @{
Version = $Version
Type = Get-FileType -File $Uri
Architecture = $Architecture.Name
URI = $CdnUri
Type = Get-FileType -File $CdnUri.ResponseUri.AbsoluteUri
URI = $CdnUri.ResponseUri.AbsoluteUri -replace "com//", "com/"
}
Write-Output -InputObject $PSObject
}
Expand Down
13 changes: 9 additions & 4 deletions Evergreen/Apps/Get-mySQLWorkbench.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function Get-mySQLWorkbench {
$Version = ($Tags | Sort-Object -Property @{ Expression = { [System.Version]$_.Tag }; Descending = $true } | Select-Object -First 1).Tag

# Build the output object
if ($Null -ne $Version) {
if ($null -ne $Version) {
foreach ($Architecture in $res.Get.Download.Uri.GetEnumerator()) {

# https://dev.mysql.com/get/Downloads/MySQLGUITools/mysql-workbench-community-8.0.40-winx64.msi
Expand All @@ -29,15 +29,20 @@ function Get-mySQLWorkbench {
#
# The version ist major.minor.patch, while the tag can have also have major.minor.patch.build
$Uri = $res.Get.Download.Uri[$Architecture.Key] -replace $res.Get.Download.ReplaceVersion, (($Version -split '\.')[0..2] -join '.')
Write-Verbose -Message "$($MyInvocation.MyCommand): Resolving: $Uri"

# The website/CDN checks the user agent, which means that the call from e.g. Azure Automation is only possible by overwriting it
$CdnUri = (Invoke-WebRequest $Uri -MaximumRedirection 0 -UserAgent "Curl/8" -SkipHttpErrorCheck -ErrorAction:SilentlyContinue).Headers.Location[0]
$params = @{
Uri = $Uri
UserAgent = "Curl/8"
}
$CdnUri = Resolve-SystemNetWebRequest @params

$PSObject = [PSCustomObject] @{
Version = $Version
Type = Get-FileType -File $Uri
Architecture = $Architecture.Name
URI = $CdnUri
Type = Get-FileType -File $CdnUri.ResponseUri.AbsoluteUri
URI = $CdnUri.ResponseUri.AbsoluteUri -replace "com//", "com/"
}
Write-Output -InputObject $PSObject
}
Expand Down

0 comments on commit 9340dc0

Please sign in to comment.