PowerShell / PSResourceGet

PSResourceGet is the package manager for PowerShell
https://www.powershellgallery.com/packages/Microsoft.PowerShell.PSResourceGet
MIT License
485 stars 92 forks source link

Make all functions use the default proxy(if the proxy was enabled) when no proxy specified #44

Open chucklu opened 6 years ago

chucklu commented 6 years ago

Expected Behavior

register the ps repository successfully

Current Behavior

nothing happened

Possible Solution

when no proxy specified, then invoke the default proxy (when the proxy was enabled) https://stackoverflow.com/questions/571429/powershell-web-requests-and-proxies

Steps to Reproduce (for bugs)

set the proxy on computer

Context

related to https://github.com/PowerShell/WindowsCompatibility/issues/45 I want to register ps repository

Your Environment


> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Microsoft Windows 10.0.16299
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
> Get-Module
ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.0        build                               {Clear-PSRepo, Compress-TestContent, Convert-TxtResourceToXml, ConvertFrom-PesterLog...}
Script     0.0        chuck                               Reset-FolderTime
Script     0.0        Get-PSGalleryApiAvailability
Manifest   6.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty...}
Manifest   6.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty...}
Manifest   6.1.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}
Manifest   6.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Manifest   6.1.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSSP...}
Script     1.1.7.2    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-PackageProvider...}
Script     1.0.0.0    posh-git                            {Add-PoshGitToProfile, Expand-GitCommand, Format-GitBranchName, Get-GitBranchStatusColor...}
Script     2.0.1      PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability...}
Script     2.0.0      PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler...}
> Get-Module -ListAvailable PowerShellGet,PackageManagement
ModuleType Version    Name                                PSEdition ExportedCommands
---------- -------    ----                                --------- ----------------
Script     1.1.7.2    PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}
Script     1.6.7      PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-Module, Find-RoleCapability...}
> Get-PackageProvider
Name                     Version          DynamicOptions
----                     -------          --------------
NuGet                    2.8.5.210        Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet            1.6.7.0          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, AllowPrereleaseVersions, Filter, Tag, Includes, DscResource, RoleCapability, Command, Ac...
> Get-PackageProvider -ListAvailable
Name                     Version          DynamicOptions
----                     -------          --------------
NuGet                    2.8.5.210        Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet            1.6.7.0          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, AllowPrereleaseVersions, Filter, Tag, Includes, DscResource, RoleCapability, Command, Ac...
chucklu commented 6 years ago

The same problem with Install-Module, I think you should make all function can work with the default proxy by default automatically(when the default proxy was enabled).

~\source\repos\GitHub\Other\PowerShellGet [development ≡]> ((Get-Command -Name Install-Module).Parameters).Keys
Name
InputObject
MinimumVersion
MaximumVersion
RequiredVersion
Repository
Credential
Scope
Proxy
ProxyCredential
AllowClobber
SkipPublisherCheck
Force
AllowPrerelease
AcceptLicense
Verbose
Debug
ErrorAction
WarningAction
InformationAction
ErrorVariable
WarningVariable
InformationVariable
OutVariable
OutBuffer
PipelineVariable
WhatIf
Confirm
chucklu commented 5 years ago

Hi @SydneyhSmith, Do you have any plan about this feature? use the default proxy automatically.

edyoung commented 5 years ago

I'm afraid we have no plan to implement. That doesn't mean it won't happen or we think it's a bad idea, just that everyone is working on other things at the moment (most bugs fall in to this category). Happy to consider PRs, or if this gets lots of upvotes or passionate comments it will move up the list.

chucklu commented 5 years ago

Hi @edyoung , I encounter the same problem again when I am using Publish-Script function, you can check more details in https://github.com/PowerShell/PowerShellGet/issues/458 . There is no Proxy parameter for Publish-Script, I did not have a chance to specify the proxy.

chucklu commented 5 years ago

I got the error info as following after waiting 5 minutes for Publish-Script

Publish-PSArtifactUtility : Failed to publish script 'chuck': 'info : Pushing chuck.1.0.0.nupkg to 'https://www.powershellgallery.com/api/v2/package/'...
info :   PUT https://www.powershellgallery.com/api/v2/package/
info : An error was encountered when fetching 'PUT https://www.powershellgallery.com/api/v2/package/'. The request will now be retried.
info : An error occurred while sending the request.
info :   The server returned an invalid or unrecognized response.
info :   PUT https://www.powershellgallery.com/api/v2/package/
info : An error was encountered when fetching 'PUT https://www.powershellgallery.com/api/v2/package/'. The request will now be retried.
info : An error occurred while sending the request.
info :   The server returned an invalid or unrecognized response.
info :   PUT https://www.powershellgallery.com/api/v2/package/
error: The operation was canceled.
error:   Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..
error:   The I/O operation has been aborted because of either a thread exit or an application request.
error:   Pushing took too long. You can change the default timeout of 300 seconds by using the --timeout <seconds> option with the push command.
'.
At C:\Program Files\PowerShell\Modules\PowerShellGet\2.1.2\PSModule.psm1:10952 char:17
+ ...             Publish-PSArtifactUtility @PublishPSArtifactUtility_Param ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : FailedToPublishTheScript,Publish-PSArtifactUtility
Benny1007 commented 5 years ago

@chucklu what happens if you update your nuget.config file with your proxy details?

chucklu commented 5 years ago

@Benny1007 As I mentioned here, the NuGet works fine with my default proxy. There is no need to add proxy to nuget.config.

chucklu commented 5 years ago

Hi @SteveL-MSFT , Would this issue be solved by https://github.com/PowerShell/PowerShell/issues/9495 ?

SydneyhSmith commented 5 years ago

@chucklu looking through this issue and wondering if you have had a chance to see if you are still hitting this issue on the latest versions of PowerShell(7 - preview 3) and PowerShellGet (2.2.1)?Thanks!

chucklu commented 5 years ago

I will try with Powershell7-preview3 later.

Find-Module WindowsCompatibility