ruby-pwsh 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4290cf1b35c8aa2ca227d4db7dd4adc437f7e40b060ea88a233cf3fe33ddff98
4
- data.tar.gz: ebc560396873912932449a51a694b4d0e03b007f8311cc385bb4e03f368f0d4a
3
+ metadata.gz: 350652f7e3803a522f6ad56512a75778277bef24bb3963fa9713522517f511cc
4
+ data.tar.gz: '02500121972f8b43463d6e3db9d37ab7324bcecb521b0fc482a9540d1c7bb88b'
5
5
  SHA512:
6
- metadata.gz: a6f766d3740eda4d7046f0c0c20bca5c5569433a05c463fd8bee31da759a20ad050ff0c5e7701b46449bc9a50b2f0c3258769f4bec89e7496809d9be001fe2f7
7
- data.tar.gz: 1a3fbe17709118963af1a278868910db76996185bca5b76200df6d3864cfb6c41a794a4f741163cd29542a70c5a371d436d2331f52e670bfa53277f89a830a83
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
- [{ name: 'powershellget', version: '2.2.5-0-1' }].each do |puppet_module|
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] = "#{resource[:vendored_modules_path]}/#{resource[:dscmeta_module_name]}/#{resource[:dscmeta_module_name]}.psd1"
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Pwsh
4
4
  # The version of the ruby-pwsh gem
5
- VERSION = '0.9.0'
5
+ VERSION = '0.10.0'
6
6
  end
data/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "puppetlabs-pwshlib",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "author": "puppetlabs",
5
5
  "summary": "Provide library code for interoperating with PowerShell.",
6
6
  "license": "MIT",
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.9.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-06-28 00:00:00.000000000 Z
11
+ date: 2021-07-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: PowerShell code manager for ruby.
14
14
  email: