Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update-DbaBuildReference - Add Parameter Proxy #9174

Open
wants to merge 14 commits into
base: development
Choose a base branch
from
3 changes: 3 additions & 0 deletions private/configurations/settings/network.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Set-DbatoolsConfig -FullName network.proxy.url -Value $null -Initialize -Validation string -Description "The URL of the network proxy."
Set-DbatoolsConfig -FullName network.proxy.username -Value $null -Initialize -Validation string -Description "The username for the network proxy."
Set-DbatoolsConfig -FullName network.proxy.securepassword -Value $null -Initialize -Validation securestring -Description "The secure password for the network proxy."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I've ever tried but is there any reason we couldn't just squash these two into a config that holds the credential object itself?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wsmelton i believe this is a limitation of the securestring type. fred said it was very complicated.

22 changes: 17 additions & 5 deletions public/Update-DbaBuildReference.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,28 @@ function Update-DbaBuildReference {
$EnableException
)
$url = Get-DbatoolsConfigValue -Name 'assets.sqlbuildreference'
$proxyUrl = Get-DbatoolsConfigValue -FullName network.proxy.url
$proxyUsername = Get-DbatoolsConfigValue -FullName network.proxy.username
$proxySecurePassword = Get-DbatoolsConfigValue -FullName network.proxy.securepassword
if ($proxyUsername) {
$proxyCredential = New-Object System.Management.Automation.PSCredential ($proxyUsername, $proxySecurePassword)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'm more for this being embedded into Invoke-TlsWebRequest instead of having to copy this everywhere

try {
$webContent = Invoke-TlsWebRequest $url -UseBasicParsing -ErrorAction Stop
} catch {
try {
Write-Message -Level Verbose -Message "Probably using a proxy for internet access, trying default proxy settings"
(New-Object System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$webContent = Invoke-TlsWebRequest $url -UseBasicParsing -ErrorAction Stop
Write-Message -Level Verbose -Message "Probably using a proxy for internet access, trying dbatools proxy settings"
$webContent = Invoke-TlsWebRequest $url -Proxy:$proxyUrl -ProxyCredential:$proxyCredential -UseBasicParsing -ErrorAction Stop
} catch {
Write-Message -Level Warning -Message "Couldn't download updated index from $url"
return
try {
Write-Message -Level Verbose -Message "Probably using a proxy for internet access, trying default proxy settings"
(New-Object System.Net.WebClient).Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$webContent = Invoke-TlsWebRequest $url -UseBasicParsing -ErrorAction Stop
} catch {
Write-Message -Level Warning -Message "Couldn't download updated index from $url"
return
}
}
}
return $webContent.Content
Expand Down
Loading