RamblingCookieMonster / PSDepend

PowerShell Dependency Handler
MIT License
285 stars 76 forks source link

Verifying installed depencies after initial install throws exceptions for Artifactory Source Repositories and PSGalleryNuget dependencies #128

Open ckolumbus opened 3 years ago

ckolumbus commented 3 years ago

|## Problem: I have a source repo on Articfactory that hosts my internal powershell modules but also serves as a proxy for the default PSGallery repository.

Configuration example

@{
    PSDependOptions = @{
        Target = '.\ps_modules'
        DependencyType = 'PSGalleryNuget'
        Source = 'https://artifactory.mylocal.domain/artifactory/api/nuget/myrepo/'
    }

    'InvokeBuild' = 'latest'
    'dotenv' = 'latest'

}

When I run two times behind each other

Invoke-PSDepend . -Install -Force -Verbose
Invoke-PSDepend . -Install -Force -Verbose

everything is fine with the first call, the dependencies get installed as expected. But the second time I get the following exception

VERBOSE: GET https://artifactory.mylocal.domain/artifactory/api/nuget/myrepo/Packages?$filter=Id eq 'InvokeBuild' and IsLatestVersion with 0-byte payload
Invoke-RestMethod : The remote server returned an error: (405) Method Not Allowed.
At C:\UserData\User\Documents\WindowsPowerShell\Modules\PSDepend\0.3.8\Private\Find-NugetPackage.ps1:47 char:5
+     Invoke-RestMethod $URI -Headers $headers |
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

VERBOSE: You have the latest version of [InvokeBuild], with installed version [5.7.1] and PSGallery version []

same error for dotenv. The same call works if I use the default PSGallery url as source.

Solution:

The query URI is created in Find-NugetPackages.ps1, e.g. like

 $URI = "${PackageSourceUrl}Packages?`$filter=Id eq '$name' and IsLatestVersion

The problem with this is that Artifactory expects the search uri to be

 $URI = "${PackageSourceUrl}Packages()?`$filter=Id eq '$name' and IsLatestVersion

mind the () behind Packages. AFAIK this is the define "standard" (if such a thing exists) but most of the nuget servers on the internet accept uris without the () as well. Not so artifactory.

Proposal

add () to the search URI creation. According to my tests this works with nuget.org and powershellgallery.com, so I assume that any other nuget server will bi accpting the braces, too. And Artifactory is also happy :-)

PR is on the way!