PowerShell / PowerShellGetv2

PowerShellGet is the Package Manager for PowerShell
https://www.PowerShellGallery.com
MIT License
430 stars 138 forks source link

Register-PSRepository not able to register HTTPS Source #649

Open varunmankal opened 3 years ago

varunmankal commented 3 years ago

Ran the following commands in RHEL 7

Steps to reproduce

sudo yum install https://github.com/PowerShell/PowerShell/releases/download/v7.1.0/powershell-7.1.0-1.rhel.7.x86_64.rpm
pwsh
Register-PSRepository -Name testing -Source https://internal.server/api/nuget/mods

Expected behavior

Register the repository without error

Actual behavior

Register-PSRepository: The specified Uri 'https://internal.server/api/nuget/mods' for parameter 'SourceLocation' is an invalid Web Uri. Please ensure that it meets the Web Uri requirements.

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.0
PSEdition                      Core
GitCommitId                    7.1.0
OS                             Linux 5.4.17-2036.100.6.1.el7uek.x86_64 PowerShell/PowerShell#2 SMP Thu Oct 29 17:04:48 PDT 2020
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
jborean93 commented 3 years ago

The Register-PSRepository cmdlet is part of the PowerShellGet module and isn't managed in this repo. This bug should be reported to https://github.com/PowerShell/PowerShellGetv2.

While the message is misleading, this error can also be shown if the URI is not reachable as per this check. I recommend you try out this code to see what happens

# Change to your actual `-Source` value
$endpoint = 'https://internal.server/api/nuget/mods'

$handler = [Net.Http.HttpClientHandler]::new()
$handler.UseDefaultCredentials = $true
$httpClient = [Net.Http.HttpClient]::new($handler)
$response = $httpClient.GetAsync($endpoint)

"{0:d} {0}" -f $response.Result.StatusCode

There's a good chance this is due to either an unreachable host or potentially certificate validation problems.

GitHub
PowerShell/PowerShellGetv2
PowerShellGet is the Package Manager for PowerShell - PowerShell/PowerShellGetv2
peppekerstens commented 3 years ago

In addition to @jborean93: use Nuget explorer NUGet explorer or equivalent RHEL GUI tool to validate your nuget source.

Also, check if NuGet is present as a provider in PowerShell https://docs.microsoft.com/en-us/powershell/module/packagemanagement/get-packageprovider?view=powershell-7.1

Get-PackageProvider (PackageManagement) - PowerShell
The Get-PackageProvider cmdlet returns a list of package providers that are connected to Package Management. Examples of these providers include PSModule, NuGet, and Chocolatey. You can filter the results based on all or part of one or more provider names.