ruby-pwsh 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 350652f7e3803a522f6ad56512a75778277bef24bb3963fa9713522517f511cc
|
4
|
+
data.tar.gz: '02500121972f8b43463d6e3db9d37ab7324bcecb521b0fc482a9540d1c7bb88b'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f3e181119fc56713f3f326081ec0f84540308f8918425afc7b10e89baa6813456b3e369b98b7c7ae255484ba425dee0e00239cce5d98683b013d8971ad5d27a
|
7
|
+
data.tar.gz: 0eaa28aeb753b121d46cd83127ff0dffdaa4cbf8bb0463b07b069fea0a339461a71d1746232e9cc3ad49413daa07b315c0a11b55eb85700f54bcda5667606db4
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).
|
4
4
|
|
5
|
+
## [0.10.0](https://github.com/puppetlabs/ruby-pwsh/tree/0.10.0) (2021-07-01)
|
6
|
+
|
7
|
+
[Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.9.0...0.10.0)
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- \(GH-172\) Enable use of class-based DSC Resources by munging PSModulePath [\#173](https://github.com/puppetlabs/ruby-pwsh/pull/173) ([michaeltlombardi](https://github.com/michaeltlombardi))
|
12
|
+
|
5
13
|
## [0.9.0](https://github.com/puppetlabs/ruby-pwsh/tree/0.9.0) (2021-06-28)
|
6
14
|
|
7
15
|
[Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.8.0...0.9.0)
|
data/Rakefile
CHANGED
@@ -110,7 +110,11 @@ namespace :dsc do
|
|
110
110
|
File.symlink(File.dirname(__FILE__), File.expand_path('pwshlib', modules_folder))
|
111
111
|
# Install each of the required modules for acceptance testing
|
112
112
|
# Note: This only works for modules in the dsc namespace on the forge.
|
113
|
-
|
113
|
+
puppetized_dsc_modules = [
|
114
|
+
{ name: 'powershellget', version: '2.2.5-0-1' },
|
115
|
+
{ name: 'jeadsc', version: '0.7.2-0-2' } # update to 0.7.2-0-3 on release
|
116
|
+
]
|
117
|
+
puppetized_dsc_modules.each do |puppet_module|
|
114
118
|
next if Dir.exist?(File.expand_path(puppet_module[:name], modules_folder))
|
115
119
|
|
116
120
|
install_command = [
|
@@ -416,7 +416,7 @@ class Puppet::Provider::DscBaseProvider
|
|
416
416
|
def invocable_resource(should, context, dsc_invoke_method)
|
417
417
|
resource = {}
|
418
418
|
resource[:parameters] = {}
|
419
|
-
%i[name dscmeta_resource_friendly_name dscmeta_resource_name dscmeta_module_name dscmeta_module_version].each do |k|
|
419
|
+
%i[name dscmeta_resource_friendly_name dscmeta_resource_name dscmeta_resource_implementation dscmeta_module_name dscmeta_module_version].each do |k|
|
420
420
|
resource[k] = context.type.definition[k]
|
421
421
|
end
|
422
422
|
should.each do |k, v|
|
@@ -655,6 +655,27 @@ class Puppet::Provider::DscBaseProvider
|
|
655
655
|
modified_string
|
656
656
|
end
|
657
657
|
|
658
|
+
# Parses a resource definition (as from `invocable_resource`) and, if the resource is implemented
|
659
|
+
# as a PowerShell class, ensures the System environment variable for PSModulePath is munged to
|
660
|
+
# include the vendored PowerShell modules. Due to a bug in PSDesiredStateConfiguration, class-based
|
661
|
+
# DSC Resources cannot be called via Invoke-DscResource by path, only by module name, *and* the
|
662
|
+
# module must be discoverable in the system-level PSModulePath. The postscript for invocation has
|
663
|
+
# logic to reset the system PSModulePath as stored in the script lines returned by this method.
|
664
|
+
#
|
665
|
+
# @param resource [Hash] a hash with the information needed to run `Invoke-DscResource`
|
666
|
+
# @return [String] A multi-line string which sets the PSModulePath at the system level
|
667
|
+
def munge_psmodulepath(resource)
|
668
|
+
return unless resource[:dscmeta_resource_implementation] == 'Class'
|
669
|
+
|
670
|
+
vendor_path = resource[:vendored_modules_path].gsub('/', '\\')
|
671
|
+
<<~MUNGE_PSMODULEPATH.strip
|
672
|
+
$UnmungedPSModulePath = [System.Environment]::GetEnvironmentVariable('PSModulePath','machine')
|
673
|
+
$MungedPSModulePath = $env:PSModulePath + ';#{vendor_path}'
|
674
|
+
[System.Environment]::SetEnvironmentVariable('PSModulePath', $MungedPSModulePath, [System.EnvironmentVariableTarget]::Machine)
|
675
|
+
$env:PSModulePath = [System.Environment]::GetEnvironmentVariable('PSModulePath','machine')
|
676
|
+
MUNGE_PSMODULEPATH
|
677
|
+
end
|
678
|
+
|
658
679
|
# Parses a resource definition (as from `invocable_resource`) for any properties which are PowerShell
|
659
680
|
# Credentials. As these values need to be serialized into PSCredential objects, return an array of
|
660
681
|
# PowerShell lines, each of which instantiates a variable which holds the value as a PSCredential.
|
@@ -784,7 +805,11 @@ class Puppet::Provider::DscBaseProvider
|
|
784
805
|
}
|
785
806
|
if resource.key?(:dscmeta_module_version)
|
786
807
|
params[:ModuleName] = {}
|
787
|
-
params[:ModuleName][:ModuleName] =
|
808
|
+
params[:ModuleName][:ModuleName] = if resource[:dscmeta_resource_implementation] == 'Class'
|
809
|
+
resource[:dscmeta_module_name]
|
810
|
+
else
|
811
|
+
"#{resource[:vendored_modules_path]}/#{resource[:dscmeta_module_name]}/#{resource[:dscmeta_module_name]}.psd1"
|
812
|
+
end
|
788
813
|
params[:ModuleName][:RequiredVersion] = resource[:dscmeta_module_version]
|
789
814
|
else
|
790
815
|
params[:ModuleName] = resource[:dscmeta_module_name]
|
@@ -841,13 +866,14 @@ class Puppet::Provider::DscBaseProvider
|
|
841
866
|
# The postscript defines the invocation error and result handling; expects `$InvokeParams` to be defined
|
842
867
|
postscript = File.new("#{template_path}/invoke_dsc_resource_postscript.ps1").read
|
843
868
|
# The blocks define the variables to define for the postscript.
|
869
|
+
module_path_block = munge_psmodulepath(resource)
|
844
870
|
credential_block = prepare_credentials(resource)
|
845
871
|
cim_instances_block = prepare_cim_instances(resource)
|
846
872
|
parameters_block = invoke_params(resource)
|
847
873
|
# clean them out of the temporary cache now that they're not needed; failure to do so can goof up future executions in this run
|
848
874
|
clear_instantiated_variables!
|
849
875
|
|
850
|
-
[functions, preamble, credential_block, cim_instances_block, parameters_block, postscript].join("\n")
|
876
|
+
[functions, preamble, module_path_block, credential_block, cim_instances_block, parameters_block, postscript].join("\n")
|
851
877
|
end
|
852
878
|
|
853
879
|
# Convert a Puppet/Ruby value into a PowerShell representation. Requires some slight additional
|
@@ -3,6 +3,12 @@ Try {
|
|
3
3
|
} catch {
|
4
4
|
$Response.errormessage = $_.Exception.Message
|
5
5
|
return ($Response | ConvertTo-Json -Compress)
|
6
|
+
} Finally {
|
7
|
+
If (![string]::IsNullOrEmpty($UnmungedPSModulePath)) {
|
8
|
+
# Reset the PSModulePath
|
9
|
+
[System.Environment]::SetEnvironmentVariable('PSModulePath', $UnmungedPSModulePath, [System.EnvironmentVariableTarget]::Machine)
|
10
|
+
$env:PSModulePath = [System.Environment]::GetEnvironmentVariable('PSModulePath', 'machine')
|
11
|
+
}
|
6
12
|
}
|
7
13
|
|
8
14
|
# keep the switch for when Test passes back changed properties
|
data/lib/pwsh/version.rb
CHANGED
data/metadata.json
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-pwsh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: PowerShell code manager for ruby.
|
14
14
|
email:
|