PowerShell / PSResourceGet

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

Artifactory nuget repositories not supported #1404

Open bateskevin opened 9 months ago

bateskevin commented 9 months ago

Prerequisites

Steps to reproduce

Hi,

In order to test the module I have installed it and wanted to try to register some repositories and install some modules from our company internal artifactory. We have multiple repositories and I tried with our dev one.

I used the following code to register the ResourceRepository:

Register-PSResourceRepository -name dev -Uri https://companyxyzinternalartifactory.com/artifactory/api/nuget/DevRepository/ -Trusted -Priority 1

The module does not give any feedback when registering the repository:

2023-09-13_07-25-34

When I then try to find a module that is listed on our internal repository I get the following error:

Find-PSResource -Name PSHTML -Repository dev
2023-09-13_07-27-26

Expected behavior

It should find the PSResource just like it finds it on the Powershell Gallery:

PS /Users/kevinbates/Code> Find-PSResource -Name PSHTML -Repository PSGallery

Name   Version Prerelease Repository Description
----   ------- ---------- ---------- -----------
PSHTML 0.8.2              PSGallery  Cross platform PowerShell module to generate HTML markup language and create awesome web pages!

### Actual behavior

```console
It does not find the PSResource because the repositorytype is not supported:

PS /Users/kevinbates/Code> Find-PSResource -Name PSHTML -Repository dev                                                                                Find-PSResource: Repository 'dev' is not a known repository type that is supported. Please file an issue for support at https://github.com/PowerShell/PSResourceGet/issues

### Error details

```console
PS /Users/kevinbates/Code> get-error               

Exception             : 
    Type        : System.Management.Automation.PSInvalidOperationException
    ErrorRecord : 
        Exception             : 
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Repository 'dev' is not a known repository type that is supported. Please file an issue for support at 
https://github.com/PowerShell/PSResourceGet/issues
            HResult : -2146233087
        CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : InvalidOperation
    Message     : Repository 'dev' is not a known repository type that is supported. Please file an issue for support at 
https://github.com/PowerShell/PSResourceGet/issues
    HResult     : -2146233079
TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.FindHelper
CategoryInfo          : InvalidArgument: (Microsoft.PowerShel….Cmdlets.FindHelper:FindHelper) [Find-PSResource], PSInvalidOperationException
FullyQualifiedErrorId : RepositoryApiVersionUnknown,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource
InvocationInfo        : 
    MyCommand        : Find-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 47
    Line             : Find-PSResource -Name PSHTML -Repository dev
    PositionMessage  : At line:1 char:1
                       + Find-PSResource -Name PSHTML -Repository dev
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Find-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : 

### Environment data

```powershell
Get-Module Microsoft.PowerShell.PSResourceGet; $PSVersionTable

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     0.9.0      rc1        Microsoft.PowerShell.PSResourceGet  {Find-PSResource, Get-InstalledPSResource, Get-PSResourceRepository, Get-PSScriptFi…

Key   : PSVersion
Value : 7.3.6
Name  : PSVersion

Key   : PSEdition
Value : Core
Name  : PSEdition

Key   : GitCommitId
Value : 7.3.6
Name  : GitCommitId

Key   : OS
Value : Darwin 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:39:46 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6020
Name  : OS

Key   : Platform
Value : Unix
Name  : Platform

Key   : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0…}
Name  : PSCompatibleVersions

Key   : PSRemotingProtocolVersion
Value : 2.3
Name  : PSRemotingProtocolVersion

Key   : SerializationVersion
Value : 1.1.0.1
Name  : SerializationVersion

Key   : WSManStackVersion
Value : 3.0
Name  : WSManStackVersion


### Visuals

_No response_
LaurentDardenne commented 9 months ago

Maybe we need to force the repository type:

Set-psresourceRepository -name escdev2 -ApiVersion 'nugetServer'
SydneyhSmith commented 9 months ago

Thanks @bateskevin does your repository have a uri that you can provide with an index.json? something like this https://learn.microsoft.com/en-us/powershell/gallery/powershellget/supported-repositories?view=powershellget-3.x#jfrog-artifactory

bateskevin commented 9 months ago

Hey @SydneyhSmith, thanks for the response. I believe our repositories are not reachable via that link structure. We are using an on-premise artifactory instance and we use the following structure:

https://artifactory.company.com/artifactory/api/nuget/repositoryname/

With PowershellGet this works without any issues.

I just read the docs you linked and I have to say I think it will be difficult to move on towards PowershellResourceGet until basic functionality that was present in PowershellGet is supported in PowershellResourceGet. For example searching a repository with wildcards is not supported in the new version, or as it seems searching for DSCResources by name.

I would have thought that PowershellResourceGet is mostly a "syntax" change regarding the userexpirience. It seems though that we did loose quite a lot of flexibility on the Userend.

Btw. I love the changes you guys did. i think the commandlets of the new Module are more intuitive to use, but details like wildcard search and these things matter a lot if you work with this on a daily basis.

Are you guys planning on fixing these open points? Gotta give it to you, you have everything documented which is nice :)

bateskevin commented 9 months ago

Short update from my side, in case somebody else faces the same issue.

I had contact with the team who manages our on premise artifactory instances and they could provide me with the link I needed to use.

For me the structure of the link that is working looks like this:

https://artifactory.company.com/artifactory/api/nuget/v3/repositoryname/index.json

Like this I can list/install modules after registering the PSResourceRepository.

I imagine there is a reason why you guys excluded wildcard searches from this repository type (Most likely something on artifactory side?). I think this would give a lot of value again tho, since this for me is core functionality of PowershellGet that I believe should be taken over to PSResourceGet.

DavidRadoorHummel commented 8 months ago

I ran into the same issue as described here, while following this guide:

https://devblogs.microsoft.com/powershell/psresourceget-is-generally-available/

changing to https://artifactory.company.com/artifactory/api/nuget/v3/repositoryname/index.json works, to some degree, however, it seems that dependency resolution is not working for this:

Install-PSResource -Name "PSDemoNoDep"
WARNING: Installing dependencies is not currently supported for V3 server protocol repositories. The package will be installed without installing dependencies.

Is there a way to set it up using protocol V2? (Does V2 even support installing dependencies?)

Best regards, David

michaelgwelch commented 3 weeks ago

I've tried the url that was mentioned above (adding index.json to the end of the path) and now I just get a 405

Find-PSResource: 'Response status code does not indicate success: 405.' Request sent: 'https://ses-artifactory.{company name}.com/artifactory/api/nuget/v3/g4-nuget/index.json'

I'm really new to use artifactory as a package repo for powershell and don't understand anything about the history (PowerShellGet, PSResourceGet, etc). I'm just wondering is there a guide somewhere that discusses how any of this is supposed to work with non-PSGallery repos?

I've tried v2 paths, v3 paths, updated various modules (the two mentioned above) and can't find anyway to get powershell to recognize and work with an artifctory nuget feed.

UPDATE: It finally dawned on me to uninstall the forced latest prerelease of PSResourceGet and uninstall PowerShellGet (it appears PowerShell core comes with an older version of PowerShellGet). These were things I installed as I read other issues say how to get this all to work.

Based on comments in this issue and other issues that state it used to work to be able to use artifactory as a ps repository. And JFrog has a support document on how to set it up (that seems old). So I decided I just need to get back to the old versions of everything and and old URL in artifactory (not a v3 url)

So using 2.2.5 of PowerShellGEt, and this support document https://jfrog.com/help/r/how-to-work-with-powershell-modules-and-nuget-repository/how-to-work-with-powershell-modules-and-a-nuget-repository I was able get it to work.