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

(MODULES-6697) Implement packageprovider type and provider #9

Merged
merged 1 commit into from
Apr 23, 2018
Merged

(MODULES-6697) Implement packageprovider type and provider #9

merged 1 commit into from
Apr 23, 2018

Conversation

jpogran
Copy link
Contributor

@jpogran jpogran commented Apr 3, 2018

This PR adds a new type and provider to correctly setup PowerShellGet PackageProviders.

Note, there is no official API to remove a PackageProvider, so this provider does not implement a destroy, only create and update.


newproperty(:ensure) do
newvalue(:present) do
provider.create
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We cannot delete packageproviders or modify them once created, as there is no external official API to do so

@jpogran
Copy link
Contributor Author

jpogran commented Apr 13, 2018

@RandomNoun7 @michaeltlombardi review plz thx

@jpogran
Copy link
Contributor Author

jpogran commented Apr 13, 2018

@hbuckle Are you ok with this implementation?

flush_command << " -#{key} '#{value}'"
end
end
require 'pry';binding.pry
Copy link
Contributor

Choose a reason for hiding this comment

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

:)

@jpogran
Copy link
Contributor Author

jpogran commented Apr 16, 2018

Should it be pspackageprovider to align with psrepository?

@michaeltlombardi
Copy link
Contributor

Tests pass on my machine. :)

@hbuckle
Copy link
Owner

hbuckle commented Apr 16, 2018

Hey all, sorry for the delay, github isn't sending me notifications on these for some reason. Will check this first thing tomorrow

@glennsarti
Copy link
Collaborator

@jpogran Needs a rebase

@hbuckle
Copy link
Owner

hbuckle commented Apr 17, 2018

Should the RequiredVersion parameter be exposed as well seeing as there are multiple versions of the nuget provider available?

Find-PackageProvider -Name nuget -AllVersions

Name                           Version          Source           Summary                                                                                                                                                                                  
----                           -------          ------           -------                                                                                                                                                                                  
nuget                          2.8.5.208        https://onege... NuGet provider for the OneGet meta-package manager                                                                                                                                       
nuget                          2.8.5.207        https://onege... NuGet provider for the OneGet meta-package manager                                                                                                                                       
nuget                          2.8.5.206        https://onege... NuGet provider for the OneGet meta-package manager                                                                                                                                       
nuget                          2.8.5.205        https://onege... NuGet provider for the OneGet meta-package manager                                                                                                                                       
nuget                          2.8.5.204        https://onege... NuGet provider for the OneGet meta-package manager                                                                                                                                       
nuget                          2.8.5.202        https://onege... NuGet provider for the OneGet meta-package manager                                                                                                                                       
nuget                          2.8.5.201        https://onege... NuGet provider for the OneGet meta-package manager                                                                                                                                       
nuget                          2.8.5.127        https://onege... NuGet provider for the OneGet meta-package manager                                                                                                                                       
nuget                          2.8.5.122        https://onege... NuGet provider for the OneGet meta-package manager                                                                                                                                       
nuget                          2.8.5.101        https://onege... NuGet provider for the OneGet meta-package manager                                                                                                                                       
nuget                          2.8.5.24         https://onege... NuGet provider for the OneGet meta-package manager   

@RandomNoun7
Copy link
Collaborator

@hbuckle I certainly don't have a problem with exposing it for the sake of completeness.

@jpogran
Copy link
Contributor Author

jpogran commented Apr 18, 2018

@hbuckle I added a version parameter. Good suggestion!

@jpogran
Copy link
Contributor Author

jpogran commented Apr 18, 2018

@RandomNoun7 I add more information to the readme. Can you see if is easier to understand?

README.md Outdated
In order to use this module to to get packages from a PSRepository like the `PSGallery`, you will have to ensure the `Nuget` provider is installed:

```puppet
pspackageprovider {'ExampleProvider':
Copy link
Owner

Choose a reason for hiding this comment

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

Should this be Nuget rather than ExampleProvider ?

README.md Outdated
```puppet
pspackageprovider {'Nuget':
ensure => 'present',
sourece_location => 'C:\some\location',
Copy link
Owner

Choose a reason for hiding this comment

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

Minor - spelling of source

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch

flush_command << " -#{key} '#{value}'"
end
end
self.class.invoke_ps_command flush_command
Copy link
Owner

Choose a reason for hiding this comment

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

The flush_command will need a -Force on it otherwise you get a prompt when installing a new version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

D'oh! Good catch again!

@(Get-PackageProvider).foreach({
[ordered]@{
'name' = $_.Name.ToLower()
'source_location' = $_.ProviderPath
Copy link
Owner

Choose a reason for hiding this comment

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

The provider path is where the packageprovider is installed to not where it is installed from so this will always be different. There is a Source property, although I haven't checked if it is populated when installing from a custom source.
It might make more sense to have source_location as a parameter rather than a property.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(tableflip). Need to think on this more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, after trying things out manually, I can't get this to work regardless. OneGet/oneget#308 details the problem and that there hasn't been a resolution.

A workaround is to file copy the DLL yourself to the expected location, which we could add as a README.

I am going to remove source paramter, update the ticket with this information and create a new ticket to discuss adding the source parameter as a later date

<<-COMMAND
@(Get-PackageProvider).foreach({
[ordered]@{
'name' = $_.Name.ToLower()
Copy link
Owner

Choose a reason for hiding this comment

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

If the name is always ToLower I think you need a corresponding munge(&:downcase) in the type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Munge added

README.md Outdated
## Limitations

Note that PowerShell modules can be installed side by side so installing a newer
version of a module will not remove any previous versions.

- As detailed in https://github.com/OneGet/oneget/issues/308, installing PackageProviders from a offline location instead of online is currently not working. A workaround is to use the Puppet file resource to ensure the prescence of the file before attempting to use the NuGet PackageProvider.

The following is an incompe
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo

README.md Outdated
### Install PowerShellGet PackageProviders


You can install PackageProviders for PowerShelLGet using the `pspackageprovieder` type.
Copy link
Collaborator

@RandomNoun7 RandomNoun7 Apr 23, 2018

Choose a reason for hiding this comment

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

typo in pspackageprovider

@RandomNoun7
Copy link
Collaborator

Manual verification of changes complete on a Windows 2008r2 WMF5 machine. Output pasted below. These changes look good to go to me.

PS C:\modules\puppet-powershellmodule> bundle exec puppet apply bill.pp --debug --modulepath .\spec\fixtures\modules
<snip... blah blah blah>
Debug: /Package[xPSDesiredStateConfiguration]: Provider windowspowershell does not support features virtual_packages; no
t managing attribute allow_virtual
Debug: /Package[Pester]: Provider powershellcore does not support features virtual_packages; not managing attribute allo
w_virtual
Debug: Creating default schedules
Info: Applying configuration version '1524498376'
Debug: Prefetching windowspowershell resources for pspackageprovider
Debug: Executing: 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.EXE -NoProfile -ExecutionPolicy Bypass -NonInte
ractive -NoLogo -Command $ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'Stop'; @(Get-PackagePro
vider).foreach({
[ordered]@{
'name' = $.Name.ToLower()
'version' = $
.Version.ToString()
} | ConvertTo-Json -Depth 99 -Compress
})
'
Debug: Executing: 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.EXE -NoProfile -ExecutionPolicy Bypass -NonInte
ractive -NoLogo -Command $ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'Stop'; PackageManagement\In
stall-PackageProvider -Name nuget -Force'
Notice: /Stage[main]/Main/Pspackageprovider[Nuget]/ensure: defined 'ensure' as 'present'
Debug: /Stage[main]/Main/Pspackageprovider[Nuget]: The container Class[Main] will propagate my refresh event
Debug: Prefetching windowspowershell resources for psrepository
Debug: Executing: 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.EXE -noprofile -executionpolicy bypass -command
@(Get-PSRepository).foreach({
[ordered]@{
'name' = $.Name
'source_location' = $
.SourceLocation.ToLower()
'installation_policy' = $.InstallationPolicy.ToLower()
} | ConvertTo-Json -Depth 99 -Compress
})
'
Notice: /Stage[main]/Main/Psrepository[PSGallery]/installation_policy: installation_policy changed 'untrusted' to 'trust
ed'
Debug: Executing: 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.EXE -noprofile -executionpolicy bypass -command
Set-PSRepository PSGallery -installationpolicy 'trusted''
Debug: /Stage[main]/Main/Psrepository[PSGallery]: The container Class[Main] will propagate my refresh event
Debug: Prefetching windowspowershell resources for package
Debug: Executing: 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.EXE -NoProfile -ExecutionPolicy Bypass -NonInte
ractive -NoLogo -Command $ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'Stop'; Get-Package -All
Versions -ProviderName PowerShellGet -Scope AllUsers -Type Module |
Group-Object -Property Name | % {
[ordered]@{
'name' = $
.Name
'ensure' = @(($.Group).Version)
'provider' = 'windowspowershell'
} | ConvertTo-Json -Depth 99 -Compress
}
'
Debug: Executing: 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.EXE -NoProfile -ExecutionPolicy Bypass -NonInte
ractive -NoLogo -Command $ProgressPreference = 'SilentlyContinue'; $ErrorActionPreference = 'Stop'; Install-Module xPSDe
siredStateConfiguration -Scope AllUsers -Force -Repository PSGallery'
Notice: /Stage[main]/Main/Package[xPSDesiredStateConfiguration]/ensure: created
Debug: /Package[xPSDesiredStateConfiguration]: The container Class[Main] will propagate my refresh event
Debug: Prefetching powershellcore resources for package
Debug: Executing: 'pwsh -NoProfile -NonInteractive -NoLogo -Command $ProgressPreference = 'SilentlyContinue'; $ErrorActi
onPreference = 'Stop'; Get-Package -AllVersions -ProviderName PowerShellGet -Scope AllUsers -Type Module |
Group-Object -Property Name | % {
[ordered]@{
'name' = $
.Name
'ensure' = @(($_.Group).Version)
'provider' = 'powershellcore'
} | ConvertTo-Json -Depth 99 -Compress
}
'
Debug: Executing: 'pwsh -NoProfile -NonInteractive -NoLogo -Command $ProgressPreference = 'SilentlyContinue'; $ErrorActi
onPreference = 'Stop'; Install-Module Pester -Scope AllUsers -Force -Repository PSGallery'
Notice: /Stage[main]/Main/Package[Pester]/ensure: created
Debug: /Package[Pester]: The container Class[Main] will propagate my refresh event
Debug: Class[Main]: The container Stage[main] will propagate my refresh event
Debug: Finishing transaction 54237960
Debug: Storing state
Info: Creating state file C:/ProgramData/PuppetLabs/puppet/cache/state/state.yaml
Debug: Stored state in 0.02 seconds
Notice: Applied catalog in 62.82 seconds
Debug: Applying settings catalog for sections reporting, metrics
Debug: Finishing transaction 54285980
Debug: Received report to process from win-2012r2-wmf5-x86-64
Debug: Evicting cache entry for environment 'production'
Debug: Caching environment 'production' (ttl = 0 sec)
Debug: Processing report from win-2012r2-wmf5-x86-64 with processor Puppet::Reports::Store
PS C:\modules\puppet-powershellmodule>

This commit adds a new type and provider for managing the PowerShellGet
package providers. **Note** The official API at this time does not allow
removing PowerShellGet PackageProviders. There is a way to delete the
source_location to remove a PackageProvider, but this is an unsupported
method that may cause side effects. Thus this provider only implements
create and update.
@RandomNoun7 RandomNoun7 merged commit a91a6d4 into hbuckle:master Apr 23, 2018
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.

6 participants