ruby-pwsh 0.11.0 → 1.0.1

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: cc99d2fca1cd56446129475226f6912f702826d58f5c7e54a2f33d6dff254d50
4
- data.tar.gz: 2e5b9b3867d7c310d2bcbab34587703c66854c712fe40a20446fd1516b24d4a9
3
+ metadata.gz: dd8ad4546d9fbdc7bf62c17f8132adb9647e311e9e3319b22b5161f924fd94c3
4
+ data.tar.gz: c607771ae691c4593b839cc1134d3e0fcc15b0a454eef93a3b146301d13b3411
5
5
  SHA512:
6
- metadata.gz: bdfbe174c34e47676450894956a0902dc17ec7b2b034fb6f41339bbbe76f659f7722e44ea0a0ba452a98ca415b508d04da5a9d4c63cb08572b4d4a012f00734c
7
- data.tar.gz: 0cdebec313aa91df0b9b12b7adb133c6e626571c148c686c73a9f2b729759e118df8edfe48febf8b3e9939e5a2abdad64812a428830d07325ff9bcc2f0aeedfd
6
+ metadata.gz: e8efb9f23a1fe2302369938416d08e463c4c5e088712dac293b10f0e8abc09431f91057039f95f918382e4775b932da4ab270901591f58d834a01c1d784d4fe6
7
+ data.tar.gz: 788c3c601d46c37478b41abe5a068eac7da7c0912ec71f703841f4d462a3363d2c613bbeb8356b6a38b21a3870eec0d567e4bfa2d2892a40aadd1e4a62dc38e1
data/.rubocop.yml CHANGED
@@ -17,3 +17,11 @@ AllCops:
17
17
  # Disabled
18
18
  Style/ClassAndModuleChildren:
19
19
  Enabled: false
20
+
21
+ ####################################################
22
+ # Cops below here due for deprecation
23
+ ####################################################
24
+ # ``Rspec/FilePath`` is going to be deprecated in the next major release of rubocop >=3.0.0: see <https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/FilePath>
25
+ # As the new cops are already present, e.g., Rspec/SpecFilePathPathFormat, then disabling this in preparation
26
+ RSpec/FilePath:
27
+ Enabled: false
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # ruby-pwsh
2
2
 
3
+ [![Code Owners](https://img.shields.io/badge/owners-DevX--team-blue)](https://github.com/puppetlabs/ruby-pwsh/blob/main/CODEOWNERS)
4
+ [![ci](https://github.com/puppetlabs/ruby-pwsh/actions/workflows/ci.yml/badge.svg)](https://github.com/puppetlabs/ruby-pwsh/actions/workflows/ci.yml)
5
+ ![GitHub release (latest by date)](https://img.shields.io/github/v/release/puppetlabs/ruby-pwsh)
6
+
3
7
  > _The PowerShell gem._
4
8
 
5
9
  This gem enables you to execute PowerShell from within ruby without having to instantiate and tear down a PowerShell process for each command called.
@@ -70,58 +74,6 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
70
74
 
71
75
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). -->
72
76
 
73
- ## Releasing the Gem and Puppet Module
74
-
75
- Steps to release an update to the gem and module include:
76
-
77
- 1. From main, checkout a new working branch for the release prep (where xyz is the appropriate version, sans periods):
78
- ```bash
79
- git checkout -b maint-release_prep_xyz
80
- ```
81
-
82
- 2. Update the version in `lib/pwsh/version.rb` and `metadata.json` to the appropriate version for the new release.
83
-
84
- 3. Run the changelog update task (make sure to verify the changelog, correctly tagging PRs as needed):
85
- ```bash
86
- bundle exec rake changelog
87
- ```
88
-
89
- 4. Commit your changes with a short, sensible commit message, like:
90
- ```bash
91
- git add lib/pwsh/version.rb
92
- git add metadata.json
93
- git add CHANGELOG.md
94
- git commit -m '(MAINT) Prep for x.y.z release'
95
- ```
96
-
97
- 5. Push your changes and submit a pull request for review _against main:
98
- ```bash
99
- git push -u origin maint_release_prep_xyz
100
- ```
101
-
102
- 6. Ensure tests pass and the code is merged to `main`.
103
-
104
- 7. Once the release_prep PR has been merged, checkout main and pull down the latests changes.
105
- ```bash
106
- git checkout main
107
- git pull
108
- ```
109
-
110
- 8. Assuming that the release_prep merge commit is at the HEAD of main we can simply create and push a tag as follows (replacing xyz with the appropriate version).
111
- ```bash
112
- git tag -a xyx -m "Release xyz"
113
- git push --follow-tags
114
- ```
115
-
116
- 9. Execute the publish workflow. This will:
117
- - Create a GitHub release
118
- - Build and publish the Gem
119
- - Build and publish the Puppet module
120
-
121
- 10. Finally check that the expected versions are present on rubygems.org and the Forge.
122
-
123
- ## Known Issues
124
-
125
77
  ## Supported Operating Systems
126
78
 
127
79
  The following platforms are supported:
@@ -133,3 +85,7 @@ The following platforms are supported:
133
85
  - OSX
134
86
  - RedHat
135
87
  - Ubuntu
88
+
89
+ ## License
90
+
91
+ This codebase is licensed under Apache 2.0. However, the open source dependencies included in this codebase might be subject to other software licenses such as AGPL, GPL2.0, and MIT.
@@ -6,27 +6,25 @@ require 'pathname'
6
6
  require 'json'
7
7
 
8
8
  class Puppet::Provider::DscBaseProvider
9
- # Initializes the provider, preparing the class variables which cache:
9
+ # Initializes the provider, preparing the instance variables which cache:
10
10
  # - the canonicalized resources across calls
11
11
  # - query results
12
12
  # - logon failures
13
13
  def initialize
14
- @@cached_canonicalized_resource ||= []
15
- @@cached_query_results ||= []
16
- @@cached_test_results ||= []
17
- @@logon_failures ||= []
14
+ @cached_canonicalized_resource = []
15
+ @cached_query_results = []
16
+ @cached_test_results = []
17
+ @logon_failures = []
18
18
  super
19
19
  end
20
20
 
21
- def cached_test_results
22
- @@cached_test_results
23
- end
21
+ attr_reader :cached_test_results
24
22
 
25
23
  # Look through a cache to retrieve the hashes specified, if they have been cached.
26
24
  # Does so by seeing if each of the specified hashes is a subset of any of the hashes
27
25
  # in the cache, so {foo: 1, bar: 2} would return if {foo: 1} was the search hash.
28
26
  #
29
- # @param cache [Array] the class variable containing cached hashes to search through
27
+ # @param cache [Array] the instance variable containing cached hashes to search through
30
28
  # @param hashes [Array] the list of hashes to search the cache for
31
29
  # @return [Array] an array containing the matching hashes for the search condition, if any
32
30
  def fetch_cached_hashes(cache, hashes)
@@ -52,14 +50,14 @@ class Puppet::Provider::DscBaseProvider
52
50
  # During RSAPI refresh runs mandatory parameters are stripped and not available;
53
51
  # Instead of checking again and failing, search the cache for a namevar match.
54
52
  namevarized_r = r.select { |k, _v| namevar_attributes(context).include?(k) }
55
- cached_result = fetch_cached_hashes(@@cached_canonicalized_resource, [namevarized_r]).first
53
+ cached_result = fetch_cached_hashes(@cached_canonicalized_resource, [namevarized_r]).first
56
54
  if cached_result.nil?
57
55
  # If the resource is meant to be absent, skip canonicalization and rely on the manifest
58
56
  # value; there's no reason to compare system state to desired state for casing if the
59
57
  # resource is being removed.
60
58
  if r[:dsc_ensure] == 'absent'
61
59
  canonicalized = r.dup
62
- @@cached_canonicalized_resource << r.dup
60
+ @cached_canonicalized_resource << r.dup
63
61
  else
64
62
  canonicalized = invoke_get_method(context, r)
65
63
  # If the resource could not be found or was returned as absent, skip case munging and
@@ -67,7 +65,7 @@ class Puppet::Provider::DscBaseProvider
67
65
  # rubocop:disable Metrics/BlockNesting
68
66
  if canonicalized.nil? || canonicalized[:dsc_ensure] == 'absent'
69
67
  canonicalized = r.dup
70
- @@cached_canonicalized_resource << r.dup
68
+ @cached_canonicalized_resource << r.dup
71
69
  else
72
70
  parameters = r.select { |name, _properties| parameter_attributes(context).include?(name) }
73
71
  canonicalized.merge!(parameters)
@@ -91,7 +89,7 @@ class Puppet::Provider::DscBaseProvider
91
89
  canonicalized.delete(key) unless downcased_resource.key?(key)
92
90
  end
93
91
  # Cache the actually canonicalized resource separately
94
- @@cached_canonicalized_resource << canonicalized.dup
92
+ @cached_canonicalized_resource << canonicalized.dup
95
93
  end
96
94
  # rubocop:enable Metrics/BlockNesting
97
95
  end
@@ -123,13 +121,13 @@ class Puppet::Provider::DscBaseProvider
123
121
  context.debug('Collecting data from the DSC Resource')
124
122
 
125
123
  # If the resource has already been queried, do not bother querying for it again
126
- cached_results = fetch_cached_hashes(@@cached_query_results, names)
124
+ cached_results = fetch_cached_hashes(@cached_query_results, names)
127
125
  return cached_results unless cached_results.empty?
128
126
 
129
- if @@cached_canonicalized_resource.empty?
127
+ if @cached_canonicalized_resource.empty?
130
128
  mandatory_properties = {}
131
129
  else
132
- canonicalized_resource = @@cached_canonicalized_resource[0].dup
130
+ canonicalized_resource = @cached_canonicalized_resource[0].dup
133
131
  mandatory_properties = canonicalized_resource.select do |attribute, _value|
134
132
  (mandatory_get_attributes(context) - namevar_attributes(context)).include?(attribute)
135
133
  end
@@ -266,9 +264,9 @@ class Puppet::Provider::DscBaseProvider
266
264
  if error.include?('Logon failure: the user has not been granted the requested logon type at this computer')
267
265
  logon_error = "PSDscRunAsCredential account specified (#{name_hash[:dsc_psdscrunascredential]['user']}) does not have appropriate logon rights; are they an administrator?"
268
266
  name_hash[:name].nil? ? context.err(logon_error) : context.err(name_hash[:name], logon_error)
269
- @@logon_failures << name_hash[:dsc_psdscrunascredential].dup
267
+ @logon_failures << name_hash[:dsc_psdscrunascredential].dup
270
268
  # This is a hack to handle the query cache to prevent a second lookup
271
- @@cached_query_results << name_hash # if fetch_cached_hashes(@@cached_query_results, [data]).empty?
269
+ @cached_query_results << name_hash # if fetch_cached_hashes(@cached_query_results, [data]).empty?
272
270
  else
273
271
  context.err(error)
274
272
  end
@@ -292,7 +290,7 @@ class Puppet::Provider::DscBaseProvider
292
290
  def insync?(context, name, _property_name, _is_hash, should_hash)
293
291
  return nil if should_hash[:validation_mode] != 'resource'
294
292
 
295
- prior_result = fetch_cached_hashes(@@cached_test_results, [name])
293
+ prior_result = fetch_cached_hashes(@cached_test_results, [name])
296
294
  prior_result.empty? ? invoke_test_method(context, name, should_hash) : prior_result.first[:in_desired_state]
297
295
  end
298
296
 
@@ -361,7 +359,7 @@ class Puppet::Provider::DscBaseProvider
361
359
  data = recursively_sort(data)
362
360
 
363
361
  # Cache the query to prevent a second lookup
364
- @@cached_query_results << data.dup if fetch_cached_hashes(@@cached_query_results, [data]).empty?
362
+ @cached_query_results << data.dup if fetch_cached_hashes(@cached_query_results, [data]).empty?
365
363
  context.debug("Returned to Puppet as #{data}")
366
364
  data
367
365
  end
@@ -400,7 +398,7 @@ class Puppet::Provider::DscBaseProvider
400
398
  return nil if data.nil?
401
399
 
402
400
  in_desired_state = data['indesiredstate']
403
- @@cached_test_results << name.merge({ in_desired_state: in_desired_state })
401
+ @cached_test_results << name.merge({ in_desired_state: in_desired_state })
404
402
 
405
403
  return in_desired_state if in_desired_state
406
404
 
@@ -451,7 +449,7 @@ class Puppet::Provider::DscBaseProvider
451
449
  # path to allow multiple modules to with shared dsc_resources to be installed side by side
452
450
  # The old vendored_modules_path: puppet_x/dsc_resources
453
451
  # The new vendored_modules_path: puppet_x/<module_name>/dsc_resources
454
- root_module_path = load_path.find { |path| path.match?(%r{#{puppetize_name(module_name)}/lib}) }
452
+ root_module_path = load_path.grep(%r{#{puppetize_name(module_name)}/lib}).first
455
453
  vendored_path = if root_module_path.nil?
456
454
  File.expand_path(Pathname.new(__FILE__).dirname + '../../../' + "puppet_x/#{puppetize_name(module_name)}/dsc_resources") # rubocop:disable Style/StringConcatenation
457
455
  else
@@ -509,12 +507,12 @@ class Puppet::Provider::DscBaseProvider
509
507
  #
510
508
  # @return [Hash] containing all instantiated variables and the properties that they define
511
509
  def instantiated_variables
512
- @@instantiated_variables ||= {}
510
+ @instantiated_variables ||= {}
513
511
  end
514
512
 
515
513
  # Clear the instantiated variables hash to be ready for the next run
516
514
  def clear_instantiated_variables!
517
- @@instantiated_variables = {}
515
+ @instantiated_variables = {}
518
516
  end
519
517
 
520
518
  # Return true if the specified credential hash has already failed to execute a DSC resource due to
@@ -523,7 +521,7 @@ class Puppet::Provider::DscBaseProvider
523
521
  # @param [Hash] a credential hash with a user and password keys where the password is a sensitive string
524
522
  # @return [Bool] true if the credential_hash has already failed logon, false otherwise
525
523
  def logon_failed_already?(credential_hash)
526
- @@logon_failures.any? do |failure_hash|
524
+ @logon_failures.any? do |failure_hash|
527
525
  failure_hash['user'] == credential_hash['user'] && failure_hash['password'].unwrap == credential_hash['password'].unwrap
528
526
  end
529
527
  end
@@ -658,8 +656,8 @@ class Puppet::Provider::DscBaseProvider
658
656
  modified_string
659
657
  end
660
658
 
661
- # Parses a resource definition (as from `invocable_resource`) and, if the resource is implemented
662
- # as a PowerShell class, ensures the System environment variable for PSModulePath is munged to
659
+ # Parses a resource definition (as from `invocable_resource`) and
660
+ # ensures the System environment variable for PSModulePath is munged to
663
661
  # include the vendored PowerShell modules. Due to a bug in PSDesiredStateConfiguration, class-based
664
662
  # DSC Resources cannot be called via Invoke-DscResource by path, only by module name, *and* the
665
663
  # module must be discoverable in the system-level PSModulePath. The postscript for invocation has
@@ -668,8 +666,6 @@ class Puppet::Provider::DscBaseProvider
668
666
  # @param resource [Hash] a hash with the information needed to run `Invoke-DscResource`
669
667
  # @return [String] A multi-line string which sets the PSModulePath at the system level
670
668
  def munge_psmodulepath(resource)
671
- return unless resource[:dscmeta_resource_implementation] == 'Class'
672
-
673
669
  vendor_path = resource[:vendored_modules_path].tr('/', '\\')
674
670
  <<~MUNGE_PSMODULEPATH.strip
675
671
  $UnmungedPSModulePath = [System.Environment]::GetEnvironmentVariable('PSModulePath','machine')
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.11.0'
5
+ VERSION = '1.0.1'
6
6
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'spec_helper'
4
- require 'puppet/resource_api'
5
4
  require 'puppet/type'
6
5
  require 'puppet/provider/dsc_base_provider/dsc_base_provider'
7
6
  require 'json'
@@ -16,40 +15,40 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
16
15
 
17
16
  # Reset the caches after each run
18
17
  after do
19
- described_class.class_variable_set(:@@cached_canonicalized_resource, nil) # rubocop:disable Style/ClassVars
20
- described_class.class_variable_set(:@@cached_query_results, nil) # rubocop:disable Style/ClassVars
21
- described_class.class_variable_set(:@@cached_test_results, nil) # rubocop:disable Style/ClassVars
22
- described_class.class_variable_set(:@@logon_failures, nil) # rubocop:disable Style/ClassVars
18
+ described_class.instance_variable_set(:@cached_canonicalized_resource, [])
19
+ described_class.instance_variable_set(:@cached_query_results, [])
20
+ described_class.instance_variable_set(:@cached_test_results, [])
21
+ described_class.instance_variable_set(:@logon_failures, [])
23
22
  end
24
23
 
25
24
  describe '.initialize' do
26
25
  before do
27
- # Need to initialize the provider to load the class variables
26
+ # Need to initialize the provider to load the instance variables
28
27
  provider
29
28
  end
30
29
 
31
- it 'initializes the cached_canonicalized_resource class variable' do
32
- expect(described_class.class_variable_get(:@@cached_canonicalized_resource)).to eq([])
30
+ it 'initializes the cached_canonicalized_resource instance variable' do
31
+ expect(described_class.instance_variable_get(:@cached_canonicalized_resource)).to eq([])
33
32
  end
34
33
 
35
- it 'initializes the cached_query_results class variable' do
36
- expect(described_class.class_variable_get(:@@cached_query_results)).to eq([])
34
+ it 'initializes the cached_query_results instance variable' do
35
+ expect(described_class.instance_variable_get(:@cached_query_results)).to eq([])
37
36
  end
38
37
 
39
- it 'initializes the cached_test_results class variable' do
40
- expect(described_class.class_variable_get(:@@cached_test_results)).to eq([])
38
+ it 'initializes the cached_test_results instance variable' do
39
+ expect(described_class.instance_variable_get(:@cached_test_results)).to eq([])
41
40
  end
42
41
 
43
- it 'initializes the logon_failures class variable' do
44
- expect(described_class.class_variable_get(:@@logon_failures)).to eq([])
42
+ it 'initializes the logon_failures instance variable' do
43
+ expect(described_class.instance_variable_get(:@logon_failures)).to eq([])
45
44
  end
46
45
  end
47
46
 
48
47
  describe '.cached_test_results' do
49
48
  let(:cache_value) { %w[foo bar] }
50
49
 
51
- it 'returns the value of the @@cached_test_results class variable' do
52
- described_class.class_variable_set(:@@cached_test_results, cache_value) # rubocop:disable Style/ClassVars
50
+ it 'returns the value of the @cached_test_results instance variable' do
51
+ described_class.instance_variable_set(:@cached_test_results, cache_value)
53
52
  expect(provider.cached_test_results).to eq(cache_value)
54
53
  end
55
54
  end
@@ -238,11 +237,11 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
238
237
 
239
238
  describe '.get' do
240
239
  after do
241
- described_class.class_variable_set(:@@cached_canonicalized_resource, []) # rubocop:disable Style/ClassVars
240
+ described_class.instance_variable_set(:@cached_canonicalized_resource, [])
242
241
  end
243
242
 
244
243
  it 'checks the cached results, returning if one exists for the specified names' do
245
- described_class.class_variable_set(:@@cached_canonicalized_resource, []) # rubocop:disable Style/ClassVars
244
+ described_class.instance_variable_set(:@cached_canonicalized_resource, [])
246
245
  allow(context).to receive(:debug)
247
246
  expect(provider).to receive(:fetch_cached_hashes).with([], [{ name: 'foo' }]).and_return([{ name: 'foo', property: 'bar' }])
248
247
  expect(provider).not_to receive(:invoke_get_method)
@@ -250,7 +249,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
250
249
  end
251
250
 
252
251
  it 'adds mandatory properties to the name hash when calling invoke_get_method' do
253
- described_class.class_variable_set(:@@cached_canonicalized_resource, [{ name: 'foo', property: 'bar', dsc_some_parameter: 'baz' }]) # rubocop:disable Style/ClassVars
252
+ described_class.instance_variable_set(:@cached_canonicalized_resource, [{ name: 'foo', property: 'bar', dsc_some_parameter: 'baz' }])
254
253
  allow(context).to receive(:debug)
255
254
  expect(provider).to receive(:fetch_cached_hashes).with([], [{ name: 'foo' }]).and_return([])
256
255
  expect(provider).to receive(:namevar_attributes).and_return([:name]).exactly(3).times
@@ -531,7 +530,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
531
530
  end
532
531
 
533
532
  after do
534
- described_class.class_variable_set(:@@cached_query_results, nil) # rubocop:disable Style/ClassVars
533
+ described_class.instance_variable_set(:@cached_query_results, nil)
535
534
  end
536
535
 
537
536
  context 'when the invocation script returns data without errors' do
@@ -558,7 +557,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
558
557
 
559
558
  it 'caches the result' do
560
559
  expect { result }.not_to raise_error
561
- expect(described_class.class_variable_get(:@@cached_query_results)).to eq([result])
560
+ expect(described_class.instance_variable_get(:@cached_query_results)).to eq([result])
562
561
  end
563
562
 
564
563
  it 'removes unrelated properties from the result' do
@@ -720,7 +719,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
720
719
  end
721
720
 
722
721
  after do
723
- described_class.class_variable_set(:@@logon_failures, nil) # rubocop:disable Style/ClassVars
722
+ described_class.instance_variable_set(:@logon_failures, [])
724
723
  end
725
724
 
726
725
  it 'errors specifically for a logon failure and returns nil' do
@@ -729,12 +728,12 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
729
728
 
730
729
  it 'caches the logon failure' do
731
730
  expect { result }.not_to raise_error
732
- expect(described_class.class_variable_get(:@@logon_failures)).to eq([credential_hash])
731
+ expect(described_class.instance_variable_get(:@logon_failures)).to eq([credential_hash])
733
732
  end
734
733
 
735
734
  it 'caches the query results' do
736
735
  expect { result }.not_to raise_error
737
- expect(described_class.class_variable_get(:@@cached_query_results)).to eq([name_hash])
736
+ expect(described_class.instance_variable_get(:@cached_query_results)).to eq([name_hash])
738
737
  end
739
738
  end
740
739
 
@@ -982,11 +981,11 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
982
981
  end
983
982
 
984
983
  describe '.invoke_test_method' do
985
- subject(:result) { provider.invoke_test_method(context, name, test_should) }
984
+ subject(:result) { provider.invoke_test_method(context, name, expect(subject).to) }
986
985
 
987
986
  let(:name) { { name: 'foo', dsc_name: 'bar' } }
988
- let(:test_should) { name.merge(dsc_ensure: 'present') }
989
- let(:test_properties) { test_should.reject { |k, _v| k == :name } }
987
+ let(:should) { name.merge(dsc_ensure: 'present') }
988
+ let(:test_properties) { expect(subject).to.reject { |k, _v| k == :name } }
990
989
  let(:invoke_dsc_resource_data) { nil }
991
990
 
992
991
  before do
@@ -996,7 +995,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
996
995
  end
997
996
 
998
997
  after do
999
- described_class.class_variable_set(:@@cached_test_results, []) # rubocop:disable Style/ClassVars
998
+ described_class.instance_variable_set(:@cached_test_results, [])
1000
999
  end
1001
1000
 
1002
1001
  context 'when something went wrong calling Invoke-DscResource' do
@@ -1044,28 +1043,28 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
1044
1043
 
1045
1044
  describe '.instantiated_variables' do
1046
1045
  after do
1047
- described_class.class_variable_set(:@@instantiated_variables, nil) # rubocop:disable Style/ClassVars
1046
+ described_class.instance_variable_set(:@instantiated_variables, [])
1048
1047
  end
1049
1048
 
1050
- it 'sets the instantiated_variables class variable to {} if not initialized' do
1049
+ it 'sets the instantiated_variables instance variable to {} if not initialized' do
1051
1050
  expect(provider.instantiated_variables).to eq({})
1052
1051
  end
1053
1052
 
1054
- it 'returns the instantiated_variables class variable if already initialized' do
1055
- described_class.class_variable_set(:@@instantiated_variables, { foo: 'bar' }) # rubocop:disable Style/ClassVars
1053
+ it 'returns the instantiated_variables instance variable if already initialized' do
1054
+ described_class.instance_variable_set(:@instantiated_variables, { foo: 'bar' })
1056
1055
  expect(provider.instantiated_variables).to eq({ foo: 'bar' })
1057
1056
  end
1058
1057
  end
1059
1058
 
1060
1059
  describe '.clear_instantiated_variables!' do
1061
1060
  after do
1062
- described_class.class_variable_set(:@@instantiated_variables, nil) # rubocop:disable Style/ClassVars
1061
+ described_class.instance_variable_set(:@instantiated_variables, [])
1063
1062
  end
1064
1063
 
1065
- it 'sets the instantiated_variables class variable to {}' do
1066
- described_class.class_variable_set(:@@instantiated_variables, { foo: 'bar' }) # rubocop:disable Style/ClassVars
1064
+ it 'sets the instantiated_variables instance variable to {}' do
1065
+ described_class.instance_variable_set(:@instantiated_variables, { foo: 'bar' })
1067
1066
  expect { provider.clear_instantiated_variables! }.not_to raise_error
1068
- expect(described_class.class_variable_get(:@@instantiated_variables)).to eq({})
1067
+ expect(described_class.instance_variable_get(:@instantiated_variables)).to eq({})
1069
1068
  end
1070
1069
  end
1071
1070
 
@@ -1088,16 +1087,16 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
1088
1087
  end
1089
1088
 
1090
1089
  after do
1091
- described_class.class_variable_set(:@@logon_failures, nil) # rubocop:disable Style/ClassVars
1090
+ described_class.instance_variable_set(:@logon_failures, [])
1092
1091
  end
1093
1092
 
1094
1093
  it 'returns false if there have been no failed logons with the username/password combination' do
1095
- described_class.class_variable_set(:@@logon_failures, [bad_credential_hash]) # rubocop:disable Style/ClassVars
1094
+ described_class.instance_variable_set(:@logon_failures, [bad_credential_hash])
1096
1095
  expect(provider.logon_failed_already?(good_credential_hash)).to be(false)
1097
1096
  end
1098
1097
 
1099
- it 'returns true if the username/password specified are found in the logon_failures class variable' do
1100
- described_class.class_variable_set(:@@logon_failures, [good_credential_hash, bad_credential_hash]) # rubocop:disable Style/ClassVars
1098
+ it 'returns true if the username/password specified are found in the logon_failures instance variable' do
1099
+ described_class.instance_variable_set(:@logon_failures, [good_credential_hash, bad_credential_hash])
1101
1100
  expect(provider.logon_failed_already?(bad_credential_hash)).to be(true)
1102
1101
  end
1103
1102
  end
@@ -1511,7 +1510,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
1511
1510
  end
1512
1511
 
1513
1512
  after do
1514
- described_class.class_variable_set(:@@instantiated_variables, nil) # rubocop:disable Style/ClassVars
1513
+ described_class.instance_variable_set(:@instantiated_variables, [])
1515
1514
  end
1516
1515
 
1517
1516
  it 'writes the ruby representation of the credentials as the value of a key named for the new variable into the instantiated_variables cache' do
@@ -1544,7 +1543,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
1544
1543
  subject(:result) { provider.prepare_cim_instances(test_resource) }
1545
1544
 
1546
1545
  after do
1547
- described_class.class_variable_set(:@@instantiated_variables, nil) # rubocop:disable Style/ClassVars
1546
+ described_class.instance_variable_set(:@instantiated_variables, [])
1548
1547
  end
1549
1548
 
1550
1549
  context 'when a cim instance is passed without nested cim instances' do
@@ -1653,7 +1652,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
1653
1652
 
1654
1653
  describe '.format_ciminstance' do
1655
1654
  after do
1656
- described_class.class_variable_set(:@@instantiated_variables, nil) # rubocop:disable Style/ClassVars
1655
+ described_class.instance_variable_set(:@instantiated_variables, [])
1657
1656
  end
1658
1657
 
1659
1658
  it 'defines and returns a new cim instance as a PowerShell variable, passing the class name and property hash' do
@@ -1669,7 +1668,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
1669
1668
  end
1670
1669
 
1671
1670
  it 'interpolates variables in the case of a cim instance containing a nested instance' do
1672
- described_class.class_variable_set(:@@instantiated_variables, { 'SomeVariable' => { 'bar' => 'ope' } }) # rubocop:disable Style/ClassVars
1671
+ described_class.instance_variable_set(:@instantiated_variables, { 'SomeVariable' => { 'bar' => 'ope' } })
1673
1672
  property_hash = { 'foo' => { 'bar' => 'ope' } }
1674
1673
  expect(provider.format_ciminstance('foo', 'SomeClass', property_hash)).to match(/@\{'foo' = \$SomeVariable\}/)
1675
1674
  end
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.11.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-16 00:00:00.000000000 Z
11
+ date: 2023-12-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: PowerShell code manager for ruby.
14
14
  email: