(#1021) Use credentials for downloads #3283
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description Of Changes
This is a fairly simple change, which adds an optional
credentials
-parameter to some of the powershell-helper-functions for downloading files from web-servers which require authentication.The changed helper-functions are:
Install-ChocolateyPackage
,Install-ChocolateyPowershellCommand
,Install-ChocolateyVsixPackage
andInstall-ChocolateyZipPackage
all pass thecredentials
-parameter toGet-ChocolateyWebFile
which in turn passes the parameter toGet-WebFile
,Get-WebFileName
andGet-WebHeaders
.The
Get-Web*
- functions utilize theSystem.Net.HttpWebRequest
-Object and attach thecredentials
-Parameter to it, if it was specified at all.The new parameter is completly optional. If you do not specify it,
$null
is passed down the functions and no credentials are used for downloading files.Motivation and Context
It is currently not possible to pass credentials to the helper-functions to download files from servers which require authentication.
An almost identical pull-request was made some years ago (#1031) by @apteryx but was closed some days ago due to inactivity, hence this new pull-request for this feature.
I'm not sure if the documentation for the helper functions are updated automatically from the powershell-code, so I made no changes to any documentation so far. Please let me know if this is required/desired.
Testing
I replaced the powershell helper-functions in a test environment directly in
C:\ProgramData\chocolatey\helpers\functions
, created a custom package and passed credentials toGet-ChocolateyWebFile
,Install-ChocolateyPackage
andInstall-ChocolateyZipPackage
.The files were downloaded from a nextcloud-instance.
The credentials were created like this:
Operating Systems Testing
Change Types Made
Change Checklist
Related Issue
Fixes #1021