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

Add support for AWS CodeArtifact #1650

Open austoonz opened 2 months ago

austoonz commented 2 months ago

Summary of the new feature / enhancement

As a user I want to use AWS CodeArtifact as a NuGet v3 PSResourceGet repository.

Proposed technical implementation details (optional)

AWS CodeArtifact supports NuGet v3. Accordingly, it works as a repository when using PSResourceGet (using this guidance for obtaining nuget credentials), however there are some capabilities that should be unblocked in the PSResourceGet source.

I have made changes to the source locally to trial a few capabilities. FindNameGlobbing and FindNameGlobbingWithTag both seem to work as expected.

Additionally, FindAll should be possible with AWS CodeArtifact as well. Some test code is below that I've used with Invoke-RestMethod to retrieve the the list of all available published packages (with my AccountId hidden). Based on this, the ability to retrieve all resources from an AWS CodeArtifact NuGet v3 feed may also need to be unblocked.

In terms of identifying an AWS CodeArtifact repository, a domain name could be used (similar to identifying JFrog feeds, etc), however it might be more appropriate to have a different method of marking a repository for CodeArtifact. Not all AWS Regions or partitions use the same domain name (eg AWS GovCloud), and using only domain name would prevent this from working in those other partitions.

# Given a CodeArtifact Domain `psrepo`, and a CodeArtifact Repository `psrepo` in the AWS Region `us-west-`:
$domain = 'psrepo'
$region = 'us-west-2'
$accountId = '<hidden>'

$token = Get-CAAuthorizationToken -Domain $domain -Region $region
$cred = [PSCredential]::new('aws', (ConvertTo-SecureString -String $token.AuthorizationToken -AsPlainText -Force))

$baseUri = "https://$domain-$accountId.d.codeartifact.$region.amazonaws.com"

# Find the available resources
(Invoke-RestMethod -Credential $cred -Uri "$baseUri/nuget/psrepo/v3/index.json").Resources

# Perform a base query
(Invoke-RestMethod -Credential $cred -Uri "$baseUri/nuget/psrepo/v3/query").data