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

(#1021) Use credentials for downloads #3283

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

we-mi
Copy link

@we-mi we-mi commented Jul 25, 2023

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:

  • Get-WebFile
  • Get-WebFileName
  • Get-WebHeaders
  • Get-ChocolateyWebFile
  • Install-ChocolateyPackage
  • Install-ChocolateyPowershellCommand
  • Install-ChocolateyVsixPackage
  • Install-ChocolateyZipPackage

Install-ChocolateyPackage, Install-ChocolateyPowershellCommand, Install-ChocolateyVsixPackage and Install-ChocolateyZipPackage all pass the credentials-parameter to Get-ChocolateyWebFile which in turn passes the parameter to Get-WebFile, Get-WebFileName and Get-WebHeaders.

The Get-Web*- functions utilize the System.Net.HttpWebRequest-Object and attach the credentials-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 to Get-ChocolateyWebFile, Install-ChocolateyPackage and Install-ChocolateyZipPackage.
The files were downloaded from a nextcloud-instance.

The credentials were created like this:

$password = ConvertTo-SecureString "password" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ("user", $password)

Operating Systems Testing

  • Windows 10 22H2
  • Windows 11 22H2

Change Types Made

  • Bug fix (non-breaking change).
  • Feature / Enhancement (non-breaking change).
  • Breaking change (fix or feature that could cause existing functionality to change).
  • Documentation changes.
  • PowerShell code changes.

Change Checklist

  • Requires a change to the documentation.
  • Documentation has been updated.
  • Tests to cover my changes, have been added.
  • All new and existing tests passed?
  • PowerShell code changes: PowerShell v2 compatibility checked?

Related Issue

Fixes #1021

Download-relevant Chocolatey Helper functions are extended with a
"Credentials" parameter to enable downloads over HTTP(S) that require
authentication.

The parameter is then attached to the Microsoft System.Net.HttpWebRequest
object to perform the download.

Before this change it was not possible to pass credentials for downloads
@pauby pauby requested a review from gep13 July 27, 2023 16:26
@norbertstoll
Copy link

Hi @gep13,

I recognized (and understood) this is marked as priority low and as an improvement, however we'd be really REALLY happy to get this implemented and I'm wondering if you've any information on how long this might take to be reviewed and published?

Kind regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Auth cred for downloads
2 participants