Skip to content
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

Closed
wants to merge 14 commits into from

Conversation

ethanbergstrom
Copy link
Collaborator

No description provided.

ChocolateyGet.psd1 Outdated Show resolved Hide resolved

New-PackageSource $Name $location $isTrusted $isRegistered $isValidated
# If a user does specify -Source but not registered
if(-not $sourceFound)
Copy link
Owner

@jianyunt jianyunt Jan 28, 2019

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?

  1. find-package nodejs -provider chocolateyget (we should make sure we do not break today's scenario, right?)
  2. register-packagesource -name chocolatey ...,
    find-package nodejs -provider chocolateyGet -source chocolatey
  3. find-package nodejs -provider chocolateyGet -source "http://somewhere.org/api/v2

Copy link
Collaborator Author

@ethanbergstrom ethanbergstrom Feb 3, 2019

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.

Copy link
Owner

@jianyunt jianyunt Feb 4, 2019

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

Copy link
Collaborator Author

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}

Copy link
Collaborator Author

@ethanbergstrom ethanbergstrom Jul 4, 2019

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$script:PackageSource?

Copy link
Collaborator Author

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.

@ethanbergstrom
Copy link
Collaborator Author

Closing in favor of #15

ethanbergstrom added a commit to ethanbergstrom/ChocolateyGet that referenced this pull request Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants