-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for multiple Chocolatey sources #10
Conversation
|
||
New-PackageSource $Name $location $isTrusted $isRegistered $isValidated | ||
# If a user does specify -Source but not registered | ||
if(-not $sourceFound) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering you are enabling the -source, here are a few cases i think we should support, what do you think?
- find-package nodejs -provider chocolateyget (we should make sure we do not break today's scenario, right?)
- register-packagesource -name chocolatey ...,
find-package nodejs -provider chocolateyGet -source chocolatey - find-package nodejs -provider chocolateyGet -source "http://somewhere.org/api/v2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe case 1 still works (see tests) and case 2 already works with these changes with a default installation of chocolatey.
It continues to use the public repo by default if no source name is specified, so long as chocolatey knows about it. If someone intentionally de-registers the default public repo then tries to find or install a package without specifying a source, it will throw an error. Registering back the public repo with the default name restores basic functionality without having to specify a source name, though you can specify 'chocolatey' as a source if you want.
PS C:\> get-packagesource -ProviderName chocolateyget
Name ProviderName IsTrusted Location
---- ------------ --------- --------
chocolatey ChocolateyGet True https://chocolatey.org/api/v2/
PS C:\> find-package nodejs -ProviderName chocolateyget
Name Version Source Summary
---- ------- ------ -------
nodejs 11.9.0 Chocolatey
PS C:\> Get-PackageSource -ProviderName chocolateyget | unregister-packagesource
PS C:\> find-package nodejs -ProviderName chocolateyget
find-package : No match was found for the specified search criteria and package name 'nodejs'. Try Get-PackageSource
to see all available registered package sources.
At line:1 char:1
+ find-package nodejs -ProviderName chocolateyget
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exceptio
n
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage
PS C:\> Register-PackageSource -ProviderName chocolateyget -Name chocolatey -Location 'https://chocolatey.org/api/v2/'
WARNING: Package source not found
Name ProviderName IsTrusted Location
---- ------------ --------- --------
chocolatey ChocolateyGet True https://chocolatey.org/api/v2/
PS C:\> find-package nodejs -ProviderName chocolateyget
Name Version Source Summary
---- ------- ------ -------
nodejs 11.9.0 Chocolatey
PS C:\> find-package nodejs -ProviderName chocolateyget -Source chocolatey
Name Version Source Summary
---- ------- ------ -------
nodejs 11.9.0 chocolatey
Case 3 works, though a little different than you describe, if you first register the package source with chocolatey first (either through choco.exe or Register-PackageSource). Per https://docs.microsoft.com/en-us/powershell/module/packagemanagement/find-package, the -Source argument has to take in the name of a registered package source. It cant take in an arbitrary URL that hasn't first been registered with the package provider. This feature has test coverage as well.
PS C:\> Register-PackageSource -ProviderName chocolateyget -Name testRepo -Location "http://somewhere.org/api/v2"
Name ProviderName IsTrusted Location
---- ------------ --------- --------
testRepo ChocolateyGet True http://somewhere.org/api/v2
PS C:\> Get-PackageSource -ProviderName chocolateyget
Name ProviderName IsTrusted Location
---- ------------ --------- --------
Chocolatey ChocolateyGet True https://chocolatey.org/api/v2/
testRepo ChocolateyGet True http://somewhere.org/api/v2
PS C:\> choco source list
Chocolatey v0.10.8
Chocolatey - https://chocolatey.org/api/v2/ | Priority 0|Bypass Proxy - False|Self-Service - False|Admin Only - False.
testRepo - http://somewhere.org/api/v2 | Priority 0|Bypass Proxy - False|Self-Service - False|Admin Only - False.
PS C:\> Unregister-PackageSource -ProviderName chocolateyget -Name testRepo
PS C:\> Get-PackageSource -ProviderName chocolateyget
Name ProviderName IsTrusted Location
---- ------------ --------- --------
Chocolatey ChocolateyGet True https://chocolatey.org/api/v2/
PS C:\> choco source list
Chocolatey v0.10.8
Chocolatey - https://chocolatey.org/api/v2/ | Priority 0|Bypass Proxy - False|Self-Service - False|Admin Only - False.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comments. For case #1, if a user does not run register-package source, find-package nodejs will fail, which will break existing case. I think you may fall back to the default chocolateyget.org if a user does not register the source?
PS C:\WINDOWS\system32> Get-PackageSource -ProviderName chocolateyget
WARNING: Unable to find package sources.
PS C:\WINDOWS\system32> find-package nodejs -ProviderName chocolateyget -verbose
VERBOSE: Using the provider 'ChocolateyGet' for searching packages.
VERBOSE: Found choco.exe in 'C:\ProgramData\chocolatey\bin\choco.exe'.
VERBOSE: Found choco.exe in 'C:\ProgramData\chocolatey\bin\choco.exe'.
find-package : No match was found for the specified search criteria and package name 'nodejs'. Try Get-PackageSource to see all available registered package sources.
At line:1 char:1
+ find-package nodejs -ProviderName chocolateyget -verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the installation of choco on your test machine have anything listed when you run 'choco source'? A default installation of chocolatey puts chocolatey.org in c:\programdata\chocolatey\config\chocolatey.config, and the modified provider stores and retrieves information to it by calling 'choco source'.
PS C:\Users\WDAGUtilityAccount\Desktop\ChocolateyGet-master> choco source
Chocolatey v0.10.11
chocolatey - https://chocolatey.org/api/v2/ | Priority 0|Bypass Proxy - False|Self-Service - False|Admin Only - False.
The original Pester tests still seem to be working, and a fresh installation of both the modified module and chocolatey (that the module installs) on a Sandbox container seems to handle finding and installing packages from chocolatey.org without any packagesource changes.
PS C:\Users\WDAGUtilityAccount\Desktop\ChocolateyGet-master> Import-PackageProvider .\ChocolateyGet.psm1
Name : ChocolateyGet ProviderName : ChocolateyGet Features : {} Version : 0.0.0.0 ProviderPath : C:\Users\WDAGUtilityAccount\Desktop\ChocolateyGet-master\ChocolateyGet.psm1 SupportedFileExtensions : {}
SupportedUriSchemes : {}
DynamicOptions : {AdditionalArguments, AdditionalArguments}
FastPackageReference :
Source :
Status :
SearchKey :
FullPath :
PackageFilename :
FromTrustedSource : False
Summary :
SwidTags : {ChocolateyGet}
CanonicalId :
Metadata : {}
SwidTagText : <?xml version="1.0" encoding="utf-16" standalone="yes"?>
<SoftwareIdentity
version="0.0.0.0"
name="ChocolateyGet" xmlns="http://standards.iso.org/iso/19770/-2/2015/schema.xsd" />
Dependencies : {}
IsCorpus :
VersionScheme :
TagVersion :
TagId :
IsPatch :
IsSupplemental :
AppliesToMedia :
Meta : {}
Links : {}
Entities : {}
Payload :
Evidence :
Culture :
Attributes : {version,name}
PS C:\Users\WDAGUtilityAccount\Desktop\ChocolateyGet-master> Find-Package nodejs -ProviderName chocolateyget
Choco.exe is required to continue
ChocolateyGet is built on Choco.exe. Do you want ChocolateyGet to install Choco.exe from
'https://chocolatey.org/install.ps1' now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): y
WARNING: Cannot bind argument to parameter 'message' because it is an empty string.
FastPackageReference : nodejs#11.9.0#Chocolatey
ProviderName : ChocolateyGet
Source : Chocolatey
Status : Available
SearchKey :
FullPath :
PackageFilename :
FromTrustedSource : True
Summary :
SwidTags : {nodejs}
CanonicalId : chocolateyget:nodejs/11.9.0#Chocolatey
Metadata : {}
SwidTagText : <?xml version="1.0" encoding="utf-16" standalone="yes"?>
<SoftwareIdentity
name="nodejs"
version="11.9.0"
versionScheme="MultiPartNumeric"
xmlns="http://standards.iso.org/iso/19770/-2/2015/schema.xsd">
<Meta />
</SoftwareIdentity>
Dependencies : {}
IsCorpus :
Name : nodejs
Version : 11.9.0
VersionScheme : MultiPartNumeric
TagVersion :
TagId :
IsPatch :
IsSupplemental :
AppliesToMedia :
Meta : {{}}
Links : {}
Entities : {}
Payload :
Evidence :
Culture :
Attributes : {name,version,versionScheme}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checking in to see if you've had further chance to review this.
Wondering if perhaps the issue you saw in your last comment was due to the default chocolatey repository information getting wiped out if you happened to run the following command from my reply describing the existing support for the cases you described, as it will render both choco.exe and chocolateyget without any repository information, including it's defaults:
PS C:\> Get-PackageSource -ProviderName chocolateyget | unregister-packagesource
A good test would be a fresh install of chocolatey.
} | ||
} | ||
else { | ||
$selectedSource = $script:PackageSourceName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$script:PackageSource?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, PackageSourceName. Chocolatey's default package source name is 'chocolatey', so if no other source name is specified, it will try to use the default public repository name (unless someone has removed it from choco's configuration).
TBH, $script:PackageSource as a URL could be removed since it doesn't get used anywhere and is kind of redundant.
Closing in favor of #15 |
Use NuGet repo
No description provided.