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

3.0.20 404 for Azure Artifacts #1042

Closed hbuckle closed 1 year ago

hbuckle commented 1 year ago

Prerequisites

Steps to reproduce

Register-PSResourceRepository -Name powershell-test -Uri "https://pkgs.dev.azure.com/xxx/_packaging/powershell-test/nuget/v3/index.json" -Trusted
$cred = Get-Credential 'pat'
Find-PSResource -Name Pester -Repository powershell-test -Credential $cred

Expected behavior

Module is found

Actual behavior

Find-PSResource: SendV3RequestAsync(): Error occured while trying to retrieve response: Response status code does not indicate success: 404 (Not Found).

Error details

Exception             :
    Type       : System.Net.Http.HttpRequestException
    TargetSite :
        Name          : MoveNext
        DeclaringType : Microsoft.PowerShell.PowerShellGet.Cmdlets.V3ServerAPICalls+<SendV3RequestAsync>d__39, PowerShellGet, Version=3.0.20.0, Culture=neutral, PublicKeyToken=null
        MemberType    : Method
        Module        : PowerShellGet.dll
    Message    : SendV3RequestAsync(): Error occured while trying to retrieve response: Response status code does not indicate success: 404 (Not Found).
    Source     : PowerShellGet
    HResult    : -2146233088
    StackTrace :
   at Microsoft.PowerShell.PowerShellGet.Cmdlets.V3ServerAPICalls.SendV3RequestAsync(HttpRequestMessage message, HttpClient s_client)
   at Microsoft.PowerShell.PowerShellGet.Cmdlets.V3ServerAPICalls.HttpRequestCall(String requestUrlV3, ExceptionDispatchInfo& edi)
TargetObject          : Microsoft.PowerShell.PowerShellGet.Cmdlets.FindHelper
CategoryInfo          : InvalidOperation: (Microsoft.PowerShel….Cmdlets.FindHelper:FindHelper) [Find-PSResource], HttpRequestException
FullyQualifiedErrorId : FindNameFail,Microsoft.PowerShell.PowerShellGet.Cmdlets.FindPSResource
InvocationInfo        :
    MyCommand        : Find-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 14
    Line             : Find-PSResource -Name Pester -Repository powershell-test -Credential $cred
    PositionMessage  : At line:1 char:1
                       + Find-PSResource -Name Pester -Repository powershell-test -Credential  …
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Find-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Environment data

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     3.0.20     beta20     PowerShellGet                       {Find-PSResource, Get-PSResource, Get-PSResourceRepository, Get-PSScriptFileInfo…}

Name                           Value
----                           -----
PSVersion                      7.3.3
PSEdition                      Core
GitCommitId                    7.3.3
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

SydneyhSmith commented 1 year ago

Thanks @hbuckle look at this blog post for more information on how to use credentials with PowerShellGet 3 https://devblogs.microsoft.com/powershell/powershellget-3-0-preview-14/ we need to better document this scenario

hbuckle commented 1 year ago

@SydneyhSmith - I should still be able to pass credentials on the command line though? It was working fine in beta19.

SydneyhSmith commented 1 year ago

Yes you should, we will investigate this

GSDragoon commented 1 year ago

Hello, @SydneyhSmith I'm running into the same problem. I'm getting the 404 error when using Find-PSResource and Install-PSResource when the module and version exist in the repository. This is working with beta19, but not beta20 or beta21.

Using Fiddler to intercept the HTTPS requests, I believe to have figured out why. The server is indeed returning a 404, because the request URL is formatted incorrectly.

Here is an example: https://github.com/PowerShell/PowerShellGet/blob/f41ee9c9583ba26b982008d943a54eb73d4a68da/src/code/V3ServerAPICalls.cs#LL922C47-L922C47 // https://api.nuget.org/v3/registration5-gz-semver2/newtonsoft.json/13.0.2.json var requestPkgMapping = $"{registrationsBaseUrl}{packageName.ToLower()}/{version}.json";

Even from the comment above it, there should be a / between {registrationsBaseUrl} and {packageName.ToLower()}. The request before the one that fails (GET /[feed]/v3/index.json) is returning URLs that do not end in /. Can anyone confirm if the server needs to end these URLs with / or if this is a bug in PowerShellGet beta20? I'm guessing a bug since this works in beta19.

EDIT: From this documentation it seems like there should be a / between id (registrationsBaseUrl) and LOWER_ID (packageName).

GET {@id}/{LOWER_ID}/index.json

https://learn.microsoft.com/en-us/nuget/api/package-base-address-resource

hbuckle commented 1 year ago

Out of interest how did you get it going through Fiddler? I thought proxies weren't supported yet?

GSDragoon commented 1 year ago

Out of interest how did you get it going through Fiddler? I thought proxies weren't supported yet?

Nothing special outside configuring Fiddler to capture and decrypt HTTPS traffic. The Fiddler CA needs trusted on the system and you need to make sure tls1.2 is in the list of protocols Fiddler uses.

hbuckle commented 1 year ago

@SydneyhSmith @alerickson - looks like an easy fix, can it go in the next beta? I can't test anything above 3.0.19 because they doesn't work with Azure Devops

SydneyhSmith commented 1 year ago

@hbuckle we made a bunch of fixes for ADO feeds and added more tests so for the next release so I am hoping this is resolved...adding @anamnavi as she did most of that work and may be able to test

alerickson commented 1 year ago

This should be resolved with PR #1167