ruby-pwsh 1.2.2 → 1.2.3

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: df8360a152766169ee39b1a3e79909f5e75f1645194f22996eb09246c58d8a79
4
- data.tar.gz: 9733619df523ed7c6d1af948fe2a75e35d24ac7b723cd610945a3c617c367685
3
+ metadata.gz: 0fef17470ea141631393a6cac8223b5a8434b2eb635322c800dcb631b4346e23
4
+ data.tar.gz: '01540184072d233ea41bda8c83ad78206c109deaeabf993e58c0fc186c899148'
5
5
  SHA512:
6
- metadata.gz: f7e6afecbbe06c0a78509458e7e178295d57de9d5901b6a448c177a5be4f2ec1361015de97daf8db022a20dcddda3f50ea0dc326234fea71e068809c06c50f02
7
- data.tar.gz: 964652929914f2aeb579835dec656d56cc8005218b64075daed3bad684a972c45079f00586a0df4f803a9c369431364163c9515542bc0be4ee58cfb07223f269
6
+ metadata.gz: 7c6560622e733169f212d9d3b00a630f5f874442b9eee08fdd4d67353da19dd7a59b946c2936a771f49bce1e9e245b08a66182e4d437c405de77d1c73ef675bd
7
+ data.tar.gz: 8c249190c38f398499ed94296e76914cd0a7d0a7a12917c7063284cb0aed8a7251bcadceb753c1d20b213c361985cf78f66cc1d7471eae1e6fbe2f681426b01a
@@ -773,7 +773,7 @@ class Puppet::Provider::DscBaseProvider # rubocop:disable Metrics/ClassLength
773
773
  <<~MUNGE_PSMODULEPATH.strip
774
774
  $UnmungedPSModulePath = [System.Environment]::GetEnvironmentVariable('PSModulePath','machine')
775
775
  $MungedPSModulePath = $env:PSModulePath + ';#{vendor_path}'
776
- [System.Environment]::SetEnvironmentVariable('PSModulePath', $MungedPSModulePath, [System.EnvironmentVariableTarget]::Machine)
776
+ Set-ItemProperty -Path 'HKLM:\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment' -Name 'PSModulePath' -Value $MungedPSModulePath
777
777
  $env:PSModulePath = [System.Environment]::GetEnvironmentVariable('PSModulePath','machine')
778
778
  MUNGE_PSMODULEPATH
779
779
  end
@@ -794,7 +794,7 @@ class Puppet::Provider::DscBaseProvider # rubocop:disable Metrics/ClassLength
794
794
  variable_name = random_variable_name
795
795
  credential_hash = {
796
796
  'user' => property_hash[:value]['user'],
797
- 'password' => escape_quotes(property_hash[:value]['password'].unwrap)
797
+ 'password' => escape_quotes(unwrap_string(property_hash[:value]['password']))
798
798
  }
799
799
  credentials_block << format_pscredential(variable_name, credential_hash)
800
800
  instantiated_variables.merge!(variable_name => credential_hash)
@@ -899,7 +899,7 @@ class Puppet::Provider::DscBaseProvider # rubocop:disable Metrics/ClassLength
899
899
  #
900
900
  # @param resource [Hash] a hash with the information needed to run `Invoke-DscResource`
901
901
  # @return [String] A string representing the PowerShell definition of the InvokeParams hash
902
- def invoke_params(resource)
902
+ def invoke_params(resource) # rubocop:disable Metrics/MethodLength
903
903
  params = {
904
904
  Name: resource[:dscmeta_resource_friendly_name],
905
905
  Method: resource[:dsc_invoke_method],
@@ -917,6 +917,10 @@ class Puppet::Provider::DscBaseProvider # rubocop:disable Metrics/ClassLength
917
917
  params[:ModuleName] = resource[:dscmeta_module_name]
918
918
  end
919
919
  resource[:parameters].each do |property_name, property_hash|
920
+ # ignore dsc_timeout, since it is only used to specify the powershell command timeout
921
+ # and timeout itself is not a parameter to the DSC resource
922
+ next if property_name == :dsc_timeout
923
+
920
924
  # strip dsc_ from the beginning of the property name declaration
921
925
  name = property_name.to_s.gsub(/^dsc_/, '').to_sym
922
926
  params[:Property][name] = case property_hash[:mof_type]
@@ -925,7 +929,7 @@ class Puppet::Provider::DscBaseProvider # rubocop:disable Metrics/ClassLength
925
929
  # the Credential hash interpolable as it will be replaced by a variable reference.
926
930
  {
927
931
  'user' => property_hash[:value]['user'],
928
- 'password' => escape_quotes(property_hash[:value]['password'].unwrap)
932
+ 'password' => escape_quotes(unwrap_string(property_hash[:value]['password']))
929
933
  }
930
934
  when 'DateTime'
931
935
  # These have to be handled specifically because they rely on the *Puppet* DateTime,
@@ -1018,6 +1022,31 @@ class Puppet::Provider::DscBaseProvider # rubocop:disable Metrics/ClassLength
1018
1022
  end
1019
1023
  end
1020
1024
 
1025
+ # Unwrap sensitive strings and handle string
1026
+ #
1027
+ # @param value [Object] The object to unwrap sensitive data inside of
1028
+ # @return [Object] The object with any sensitive strings unwrapped
1029
+ def unwrap_string(value)
1030
+ case value
1031
+ when Puppet::Pops::Types::PSensitiveType::Sensitive
1032
+ value.unwrap
1033
+ when Hash
1034
+ unwrapped = {}
1035
+ value.each do |k, v|
1036
+ unwrapped[k] = unwrap_string(v)
1037
+ end
1038
+ unwrapped
1039
+ when Array
1040
+ unwrapped = []
1041
+ value.each do |v|
1042
+ unwrapped << unwrap_string(v)
1043
+ end
1044
+ unwrapped
1045
+ else
1046
+ value
1047
+ end
1048
+ end
1049
+
1021
1050
  # Escape any nested single quotes in a Sensitive string
1022
1051
  #
1023
1052
  # @param text [String] the text to escape
@@ -6,7 +6,7 @@ Try {
6
6
  } Finally {
7
7
  If (![string]::IsNullOrEmpty($UnmungedPSModulePath)) {
8
8
  # Reset the PSModulePath
9
- [System.Environment]::SetEnvironmentVariable('PSModulePath', $UnmungedPSModulePath, [System.EnvironmentVariableTarget]::Machine)
9
+ Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' -Name 'PSModulePath' -Value $UnmungedPSModulePath
10
10
  $env:PSModulePath = [System.Environment]::GetEnvironmentVariable('PSModulePath', 'machine')
11
11
  }
12
12
  }
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 = '1.2.2'
5
+ VERSION = '1.2.3'
6
6
  end
@@ -152,7 +152,7 @@ function Invoke-PowerShellUserCode {
152
152
  # Set any provided environment variables
153
153
  if ($AdditionalEnvironmentVariables -ne $null) {
154
154
  $AdditionalEnvironmentVariables.GetEnumerator() |
155
- ForEach-Object -Process { Set-Item -Path "Env:\$($_.Name)" -Value $_.Value }
155
+ ForEach-Object -Process { Set-Item -Path "Env:\$($_.Name)" -Value "$($_.Value)" }
156
156
  }
157
157
 
158
158
  # We clear the commands before each new command to avoid command pollution This does not need
@@ -439,7 +439,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
439
439
  mof_is_embedded: false
440
440
  },
441
441
  dsc_psdscrunascredential: {
442
- type: 'Optional[Struct[{ user => String[1], password => Sensitive[String[1]] }]]',
442
+ type: 'Optional[Struct[{ user => String[1], password => Variant[String[1], Sensitive[String[1]]] }]]',
443
443
  behaviour: :parameter,
444
444
  mandatory_for_get: false,
445
445
  mandatory_for_set: false,
@@ -906,7 +906,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
906
906
  mof_is_embedded: false
907
907
  },
908
908
  dsc_psdscrunascredential: {
909
- type: 'Optional[Struct[{ user => String[1], password => Sensitive[String[1]] }]]',
909
+ type: 'Optional[Struct[{ user => String[1], password => Variant[String[1], Sensitive[String[1]]] }]]',
910
910
  desc: 'The Credential to run DSC under',
911
911
  behaviour: :parameter,
912
912
  mandatory_for_get: false,
@@ -1529,7 +1529,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
1529
1529
  end
1530
1530
 
1531
1531
  it 'updates the system PSModulePath to $MungedPSModulePath' do
1532
- expect(result).to match(/SetEnvironmentVariable\('PSModulePath', \$MungedPSModulePath/)
1532
+ expect(result).to match(/-Name 'PSModulePath' -Value \$MungedPSModulePath/)
1533
1533
  end
1534
1534
 
1535
1535
  it 'sets the process level PSModulePath to the modified system PSModulePath' do
@@ -1572,6 +1572,8 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
1572
1572
  let(:test_resource) { base_resource.merge(additional_parameters) }
1573
1573
 
1574
1574
  before do
1575
+ allow(Puppet::Pops::Types::PSensitiveType::Sensitive).to receive(:===).with(foo_password).and_return(true)
1576
+ allow(Puppet::Pops::Types::PSensitiveType::Sensitive).to receive(:===).with(bar_password).and_return(true)
1575
1577
  allow(foo_password).to receive(:unwrap).and_return('foo')
1576
1578
  allow(bar_password).to receive(:unwrap).and_return('bar')
1577
1579
  end
@@ -1811,6 +1813,11 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
1811
1813
  "$InvokeParams = @{Name = 'Foo'; Method = 'Get'; Property = @{credential = $SomeCredential}; ModuleName = 'PuppetDsc'}"
1812
1814
  end
1813
1815
 
1816
+ before do
1817
+ allow(Puppet::Pops::Types::PSensitiveType::Sensitive).to receive(:===).with(password).and_return(true)
1818
+ allow(password).to receive(:unwrap).and_return('bar')
1819
+ end
1820
+
1814
1821
  it 'unwraps the credential hash and interpolates the appropriate variable' do
1815
1822
  expect(password).to receive(:unwrap).and_return('FooPassword')
1816
1823
  expect(provider).to receive(:interpolate_variables).with(formatted_param_hash).and_return(variable_interpolated_param_hash)
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: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet, Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-25 00:00:00.000000000 Z
11
+ date: 2025-03-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: PowerShell code manager for ruby.
14
14
  email:
@@ -51,7 +51,7 @@ metadata:
51
51
  homepage_uri: https://github.com/puppetlabs/ruby-pwsh
52
52
  source_code_uri: https://github.com/puppetlabs/ruby-pwsh
53
53
  changelog_uri: https://github.com/puppetlabs/ruby-pwsh
54
- post_install_message:
54
+ post_install_message:
55
55
  rdoc_options: []
56
56
  require_paths:
57
57
  - lib
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  version: '0'
68
68
  requirements: []
69
69
  rubygems_version: 3.1.6
70
- signing_key:
70
+ signing_key:
71
71
  specification_version: 4
72
72
  summary: PowerShell code manager for ruby.
73
73
  test_files: []