ruby-pwsh 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +11 -0
- data/README.md +8 -0
- data/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb +49 -6
- data/lib/pwsh/version.rb +1 -1
- data/spec/spec_helper.rb +25 -0
- data/spec/unit/puppet/provider/dsc_base_provider/dsc_base_provider_spec.rb +83 -39
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb7a2c9a103865f74de54ae3a977a70382a2b18ff2e1f8f830b25ef50f4ba1d2
|
4
|
+
data.tar.gz: 7ca9acbd7478367673a8f761a0b51ddf5f0359246b3ca72f7fe9b8e4c3da34a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 830c6e92076e50675f1ce02445f9fd9952545987af24e152bb164b11223d35d47d3619c997bf51b9b09293b22d69d2c832e689f59cfbad1118663203af374046
|
7
|
+
data.tar.gz: 5e107bcb95cc294f2c421d565c3376b21a7272b4bd4e4c32684f4481577398e2fa54c5005f8e6d990a7d9ffebf2db5eca5dbdb7eba2b2c7ddb2660ca65315f04
|
data/.rubocop.yml
CHANGED
@@ -17,3 +17,14 @@ AllCops:
|
|
17
17
|
# Disabled
|
18
18
|
Style/ClassAndModuleChildren:
|
19
19
|
Enabled: false
|
20
|
+
|
21
|
+
Layout/LineLength:
|
22
|
+
Max: 196
|
23
|
+
|
24
|
+
####################################################
|
25
|
+
# Cops below here due for deprecation
|
26
|
+
####################################################
|
27
|
+
# ``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>
|
28
|
+
# As the new cops are already present, e.g., Rspec/SpecFilePathPathFormat, then disabling this in preparation
|
29
|
+
RSpec/FilePath:
|
30
|
+
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.
|
@@ -81,3 +85,7 @@ The following platforms are supported:
|
|
81
85
|
- OSX
|
82
86
|
- RedHat
|
83
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.
|
@@ -5,7 +5,7 @@ require 'ruby-pwsh'
|
|
5
5
|
require 'pathname'
|
6
6
|
require 'json'
|
7
7
|
|
8
|
-
class Puppet::Provider::DscBaseProvider
|
8
|
+
class Puppet::Provider::DscBaseProvider # rubocop:disable Metrics/ClassLength
|
9
9
|
# Initializes the provider, preparing the instance variables which cache:
|
10
10
|
# - the canonicalized resources across calls
|
11
11
|
# - query results
|
@@ -244,6 +244,7 @@ class Puppet::Provider::DscBaseProvider
|
|
244
244
|
script_content = ps_script_content(resource)
|
245
245
|
context.debug("Script:\n #{redact_secrets(script_content)}")
|
246
246
|
output = ps_manager.execute(remove_secret_identifiers(script_content))[:stdout]
|
247
|
+
|
247
248
|
if output.nil?
|
248
249
|
context.err('Nothing returned')
|
249
250
|
return nil
|
@@ -256,8 +257,10 @@ class Puppet::Provider::DscBaseProvider
|
|
256
257
|
return nil
|
257
258
|
end
|
258
259
|
context.debug("raw data received: #{data.inspect}")
|
260
|
+
collision_error_matcher = /The Invoke-DscResource cmdlet is in progress and must return before Invoke-DscResource can be invoked/
|
259
261
|
|
260
262
|
error = data['errormessage']
|
263
|
+
|
261
264
|
unless error.nil? || error.empty?
|
262
265
|
# NB: We should have a way to stop processing this resource *now* without blowing up the whole Puppet run
|
263
266
|
# Raising an error stops processing but blows things up while context.err alerts but continues to process
|
@@ -267,6 +270,11 @@ class Puppet::Provider::DscBaseProvider
|
|
267
270
|
@logon_failures << name_hash[:dsc_psdscrunascredential].dup
|
268
271
|
# This is a hack to handle the query cache to prevent a second lookup
|
269
272
|
@cached_query_results << name_hash # if fetch_cached_hashes(@cached_query_results, [data]).empty?
|
273
|
+
elsif error.match?(collision_error_matcher)
|
274
|
+
context.notice('Invoke-DscResource collision detected: Please stagger the timing of your Puppet runs as this can lead to unexpected behaviour.')
|
275
|
+
retry_invoke_dsc_resource(context, 5, 60, collision_error_matcher) do
|
276
|
+
data = ps_manager.execute(remove_secret_identifiers(script_content))[:stdout]
|
277
|
+
end
|
270
278
|
else
|
271
279
|
context.err(error)
|
272
280
|
end
|
@@ -276,6 +284,43 @@ class Puppet::Provider::DscBaseProvider
|
|
276
284
|
data
|
277
285
|
end
|
278
286
|
|
287
|
+
# Retries Invoke-DscResource when returned error matches error regex supplied as param.
|
288
|
+
# @param context [Object] the Puppet runtime context to operate in and send feedback to
|
289
|
+
# @param max_retry_count [Int] max number of times to retry Invoke-DscResource
|
290
|
+
# @param retry_wait_interval_secs [Int] Time delay between retries
|
291
|
+
# @param error_matcher [String] the regex pattern to match with error
|
292
|
+
def retry_invoke_dsc_resource(context, max_retry_count, retry_wait_interval_secs, error_matcher)
|
293
|
+
try = 0
|
294
|
+
while try < max_retry_count
|
295
|
+
try += 1
|
296
|
+
# notify and wait for retry interval
|
297
|
+
context.notice("Sleeping for #{retry_wait_interval_secs} seconds.")
|
298
|
+
sleep retry_wait_interval_secs
|
299
|
+
# notify and retry
|
300
|
+
context.notice("Retrying: attempt #{try} of #{max_retry_count}.")
|
301
|
+
data = JSON.parse(yield)
|
302
|
+
# if no error, break
|
303
|
+
if data['errormessage'].nil?
|
304
|
+
break
|
305
|
+
# check if error matches error matcher supplied
|
306
|
+
elsif data['errormessage'].match?(error_matcher)
|
307
|
+
# if last attempt, return error
|
308
|
+
if try == max_retry_count
|
309
|
+
context.notice("Attempt #{try} of #{max_retry_count} failed. No more retries.")
|
310
|
+
# all attempts failed, raise error
|
311
|
+
return context.err(data['errormessage'])
|
312
|
+
end
|
313
|
+
# if not last attempt, notify, continue and retry
|
314
|
+
context.notice("Attempt #{try} of #{max_retry_count} failed.")
|
315
|
+
next
|
316
|
+
else
|
317
|
+
# if we get an unexpected error, return
|
318
|
+
return context.err(data['errormessage'])
|
319
|
+
end
|
320
|
+
end
|
321
|
+
data
|
322
|
+
end
|
323
|
+
|
279
324
|
# Determine if the DSC Resource is in the desired state, invoking the `Test` method unless it's
|
280
325
|
# already been run for the resource, in which case reuse the result instead of checking for each
|
281
326
|
# property. This behavior is only triggered if the validation_mode is set to resource; by default
|
@@ -656,8 +701,8 @@ class Puppet::Provider::DscBaseProvider
|
|
656
701
|
modified_string
|
657
702
|
end
|
658
703
|
|
659
|
-
# Parses a resource definition (as from `invocable_resource`) and
|
660
|
-
#
|
704
|
+
# Parses a resource definition (as from `invocable_resource`) and
|
705
|
+
# ensures the System environment variable for PSModulePath is munged to
|
661
706
|
# include the vendored PowerShell modules. Due to a bug in PSDesiredStateConfiguration, class-based
|
662
707
|
# DSC Resources cannot be called via Invoke-DscResource by path, only by module name, *and* the
|
663
708
|
# module must be discoverable in the system-level PSModulePath. The postscript for invocation has
|
@@ -666,9 +711,7 @@ class Puppet::Provider::DscBaseProvider
|
|
666
711
|
# @param resource [Hash] a hash with the information needed to run `Invoke-DscResource`
|
667
712
|
# @return [String] A multi-line string which sets the PSModulePath at the system level
|
668
713
|
def munge_psmodulepath(resource)
|
669
|
-
|
670
|
-
|
671
|
-
vendor_path = resource[:vendored_modules_path].tr('/', '\\')
|
714
|
+
vendor_path = resource[:vendored_modules_path]&.tr('/', '\\')
|
672
715
|
<<~MUNGE_PSMODULEPATH.strip
|
673
716
|
$UnmungedPSModulePath = [System.Environment]::GetEnvironmentVariable('PSModulePath','machine')
|
674
717
|
$MungedPSModulePath = $env:PSModulePath + ';#{vendor_path}'
|
data/lib/pwsh/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
if ENV['COVERAGE'] == 'yes'
|
4
|
+
begin
|
5
|
+
require 'simplecov'
|
6
|
+
require 'simplecov-console'
|
7
|
+
|
8
|
+
SimpleCov.formatters = [
|
9
|
+
SimpleCov::Formatter::HTMLFormatter,
|
10
|
+
SimpleCov::Formatter::Console
|
11
|
+
]
|
12
|
+
|
13
|
+
SimpleCov.start do
|
14
|
+
track_files 'lib/**/*.rb'
|
15
|
+
|
16
|
+
add_filter '/spec'
|
17
|
+
add_filter 'lib/pwsh/version.rb'
|
18
|
+
|
19
|
+
# do not track vendored files
|
20
|
+
add_filter '/vendor'
|
21
|
+
add_filter '/.vendor'
|
22
|
+
end
|
23
|
+
rescue LoadError
|
24
|
+
raise 'Add the simplecov & simplecov-console gems to Gemfile to enable this task'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
3
28
|
require 'bundler/setup'
|
4
29
|
require 'ruby-pwsh'
|
5
30
|
|
@@ -2,23 +2,24 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
require 'puppet/type'
|
5
|
+
require 'puppet/resource_api'
|
5
6
|
require 'puppet/provider/dsc_base_provider/dsc_base_provider'
|
6
7
|
require 'json'
|
7
8
|
|
8
9
|
RSpec.describe Puppet::Provider::DscBaseProvider do
|
9
10
|
subject(:provider) { described_class.new }
|
10
11
|
|
11
|
-
let(:context) { instance_double(Puppet::ResourceApi::
|
12
|
-
let(:type) { instance_double(Puppet::ResourceApi::TypeDefinition) }
|
12
|
+
let(:context) { instance_double(Puppet::ResourceApi::BaseContext, 'context') }
|
13
|
+
let(:type) { instance_double(Puppet::ResourceApi::TypeDefinition, 'typedef') }
|
13
14
|
let(:ps_manager) { instance_double(Pwsh::Manager) }
|
14
15
|
let(:execute_response) { { stdout: nil, stderr: nil, exitcode: 0 } }
|
15
16
|
|
16
17
|
# Reset the caches after each run
|
17
18
|
after do
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
provider.instance_variable_set(:@cached_canonicalized_resource, [])
|
20
|
+
provider.instance_variable_set(:@cached_query_results, [])
|
21
|
+
provider.instance_variable_set(:@cached_test_results, [])
|
22
|
+
provider.instance_variable_set(:@logon_failures, [])
|
22
23
|
end
|
23
24
|
|
24
25
|
describe '.initialize' do
|
@@ -28,27 +29,30 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
28
29
|
end
|
29
30
|
|
30
31
|
it 'initializes the cached_canonicalized_resource instance variable' do
|
31
|
-
expect(
|
32
|
+
expect(provider.instance_variable_get(:@cached_canonicalized_resource)).to eq([])
|
32
33
|
end
|
33
34
|
|
34
35
|
it 'initializes the cached_query_results instance variable' do
|
35
|
-
expect(
|
36
|
+
expect(provider.instance_variable_get(:@cached_query_results)).to eq([])
|
36
37
|
end
|
37
38
|
|
38
39
|
it 'initializes the cached_test_results instance variable' do
|
39
|
-
expect(
|
40
|
+
expect(provider.instance_variable_get(:@cached_test_results)).to eq([])
|
40
41
|
end
|
41
42
|
|
42
43
|
it 'initializes the logon_failures instance variable' do
|
43
|
-
expect(
|
44
|
+
expect(provider.instance_variable_get(:@logon_failures)).to eq([])
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
47
48
|
describe '.cached_test_results' do
|
48
49
|
let(:cache_value) { %w[foo bar] }
|
49
50
|
|
51
|
+
before do
|
52
|
+
provider.instance_variable_set(:@cached_test_results, cache_value)
|
53
|
+
end
|
54
|
+
|
50
55
|
it 'returns the value of the @cached_test_results instance variable' do
|
51
|
-
described_class.instance_variable_set(:@cached_test_results, cache_value)
|
52
56
|
expect(provider.cached_test_results).to eq(cache_value)
|
53
57
|
end
|
54
58
|
end
|
@@ -237,11 +241,11 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
237
241
|
|
238
242
|
describe '.get' do
|
239
243
|
after do
|
240
|
-
|
244
|
+
provider.instance_variable_set(:@cached_canonicalized_resource, [])
|
241
245
|
end
|
242
246
|
|
243
247
|
it 'checks the cached results, returning if one exists for the specified names' do
|
244
|
-
|
248
|
+
provider.instance_variable_set(:@cached_canonicalized_resource, [])
|
245
249
|
allow(context).to receive(:debug)
|
246
250
|
expect(provider).to receive(:fetch_cached_hashes).with([], [{ name: 'foo' }]).and_return([{ name: 'foo', property: 'bar' }])
|
247
251
|
expect(provider).not_to receive(:invoke_get_method)
|
@@ -249,7 +253,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
249
253
|
end
|
250
254
|
|
251
255
|
it 'adds mandatory properties to the name hash when calling invoke_get_method' do
|
252
|
-
|
256
|
+
provider.instance_variable_set(:@cached_canonicalized_resource, [{ name: 'foo', property: 'bar', dsc_some_parameter: 'baz' }])
|
253
257
|
allow(context).to receive(:debug)
|
254
258
|
expect(provider).to receive(:fetch_cached_hashes).with([], [{ name: 'foo' }]).and_return([])
|
255
259
|
expect(provider).to receive(:namevar_attributes).and_return([:name]).exactly(3).times
|
@@ -530,7 +534,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
530
534
|
end
|
531
535
|
|
532
536
|
after do
|
533
|
-
|
537
|
+
provider.instance_variable_set(:@cached_query_results, [])
|
534
538
|
end
|
535
539
|
|
536
540
|
context 'when the invocation script returns data without errors' do
|
@@ -557,7 +561,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
557
561
|
|
558
562
|
it 'caches the result' do
|
559
563
|
expect { result }.not_to raise_error
|
560
|
-
expect(
|
564
|
+
expect(provider.instance_variable_get(:@cached_query_results)).to eq([result])
|
561
565
|
end
|
562
566
|
|
563
567
|
it 'removes unrelated properties from the result' do
|
@@ -719,7 +723,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
719
723
|
end
|
720
724
|
|
721
725
|
after do
|
722
|
-
|
726
|
+
provider.instance_variable_set(:@logon_failures, [])
|
723
727
|
end
|
724
728
|
|
725
729
|
it 'errors specifically for a logon failure and returns nil' do
|
@@ -728,12 +732,12 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
728
732
|
|
729
733
|
it 'caches the logon failure' do
|
730
734
|
expect { result }.not_to raise_error
|
731
|
-
expect(
|
735
|
+
expect(provider.instance_variable_get(:@logon_failures)).to eq([credential_hash])
|
732
736
|
end
|
733
737
|
|
734
738
|
it 'caches the query results' do
|
735
739
|
expect { result }.not_to raise_error
|
736
|
-
expect(
|
740
|
+
expect(provider.instance_variable_get(:@cached_query_results)).to eq([name_hash])
|
737
741
|
end
|
738
742
|
end
|
739
743
|
|
@@ -790,6 +794,44 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
790
794
|
end
|
791
795
|
end
|
792
796
|
|
797
|
+
context 'when the invocation script errors with a collision' do
|
798
|
+
it 'writes a notice via context and applies successfully on retry' do
|
799
|
+
expect(ps_manager).to receive(:execute).and_return({ stdout: '{"errormessage": "The Invoke-DscResource cmdlet is in progress and must return before Invoke-DscResource can be invoked"}' })
|
800
|
+
expect(context).to receive(:notice).with(/Invoke-DscResource collision detected: Please stagger the timing of your Puppet runs as this can lead to unexpected behaviour./).once
|
801
|
+
expect(context).to receive(:notice).with('Sleeping for 60 seconds.').twice
|
802
|
+
expect(context).to receive(:notice).with(/Retrying: attempt [1-2] of 5/).twice
|
803
|
+
expect(ps_manager).to receive(:execute).and_return({ stdout: '{"errormessage": "The Invoke-DscResource cmdlet is in progress and must return before Invoke-DscResource can be invoked"}' })
|
804
|
+
expect(context).to receive(:notice).with('Attempt 1 of 5 failed.')
|
805
|
+
allow(provider).to receive(:sleep)
|
806
|
+
expect(ps_manager).to receive(:execute).and_return({ stdout: '{"errormessage": null}' })
|
807
|
+
expect { result }.not_to raise_error
|
808
|
+
end
|
809
|
+
|
810
|
+
it 'writes a error via context and fails to apply when all retry attempts used' do
|
811
|
+
expect(ps_manager).to receive(:execute).and_return({ stdout: '{"errormessage": "The Invoke-DscResource cmdlet is in progress and must return before Invoke-DscResource can be invoked"}' })
|
812
|
+
.exactly(5).times
|
813
|
+
expect(context).to receive(:notice).with(/Invoke-DscResource collision detected: Please stagger the timing of your Puppet runs as this can lead to unexpected behaviour./).once
|
814
|
+
expect(context).to receive(:notice).with('Sleeping for 60 seconds.').exactly(5).times
|
815
|
+
expect(context).to receive(:notice).with(/Retrying: attempt [1-6] of 5/).exactly(5).times
|
816
|
+
expect(ps_manager).to receive(:execute).and_return({ stdout: '{"errormessage": "The Invoke-DscResource cmdlet is in progress and must return before Invoke-DscResource can be invoked"}' })
|
817
|
+
expect(context).to receive(:notice).with(/Attempt [1-6] of 5 failed/).exactly(5).times
|
818
|
+
expect(context).to receive(:err).with(/The Invoke-DscResource cmdlet is in progress and must return before Invoke-DscResource can be invoked/)
|
819
|
+
allow(provider).to receive(:sleep)
|
820
|
+
expect(result).to be_nil
|
821
|
+
end
|
822
|
+
|
823
|
+
it 'writes an error via context and fails to apply when encountering an unexpected error' do
|
824
|
+
expect(ps_manager).to receive(:execute).and_return({ stdout: '{"errormessage": "The Invoke-DscResource cmdlet is in progress and must return before Invoke-DscResource can be invoked"}' })
|
825
|
+
expect(context).to receive(:notice).with(/Invoke-DscResource collision detected: Please stagger the timing of your Puppet runs as this can lead to unexpected behaviour./).once
|
826
|
+
expect(context).to receive(:notice).with('Sleeping for 60 seconds.').once
|
827
|
+
expect(context).to receive(:notice).with(/Retrying: attempt 1 of 5/).once
|
828
|
+
allow(provider).to receive(:sleep)
|
829
|
+
expect(ps_manager).to receive(:execute).and_return({ stdout: '{"errormessage": "Some unexpected error"}' }).once
|
830
|
+
expect(context).to receive(:err).with(/Some unexpected error/)
|
831
|
+
expect(result).to be_nil
|
832
|
+
end
|
833
|
+
end
|
834
|
+
|
793
835
|
context 'when the invocation script returns data without errors' do
|
794
836
|
it 'filters for the correct properties to invoke and returns the results' do
|
795
837
|
expect(ps_manager).to receive(:execute).with("Script: #{apply_props}").and_return({ stdout: '{"in_desired_state": true, "errormessage": null}' })
|
@@ -981,11 +1023,11 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
981
1023
|
end
|
982
1024
|
|
983
1025
|
describe '.invoke_test_method' do
|
984
|
-
subject(:result) { provider.invoke_test_method(context, name,
|
1026
|
+
subject(:result) { provider.invoke_test_method(context, name, should_hash) }
|
985
1027
|
|
986
1028
|
let(:name) { { name: 'foo', dsc_name: 'bar' } }
|
987
|
-
let(:
|
988
|
-
let(:test_properties) {
|
1029
|
+
let(:should_hash) { name.merge(dsc_ensure: 'present') }
|
1030
|
+
let(:test_properties) { should_hash.reject { |k, _v| k == :name } }
|
989
1031
|
let(:invoke_dsc_resource_data) { nil }
|
990
1032
|
|
991
1033
|
before do
|
@@ -995,7 +1037,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
995
1037
|
end
|
996
1038
|
|
997
1039
|
after do
|
998
|
-
|
1040
|
+
provider.instance_variable_set(:@cached_test_results, [])
|
999
1041
|
end
|
1000
1042
|
|
1001
1043
|
context 'when something went wrong calling Invoke-DscResource' do
|
@@ -1043,7 +1085,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
1043
1085
|
|
1044
1086
|
describe '.instantiated_variables' do
|
1045
1087
|
after do
|
1046
|
-
|
1088
|
+
provider.instance_variable_set(:@instantiated_variables, [])
|
1047
1089
|
end
|
1048
1090
|
|
1049
1091
|
it 'sets the instantiated_variables instance variable to {} if not initialized' do
|
@@ -1051,20 +1093,20 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
1051
1093
|
end
|
1052
1094
|
|
1053
1095
|
it 'returns the instantiated_variables instance variable if already initialized' do
|
1054
|
-
|
1096
|
+
provider.instance_variable_set(:@instantiated_variables, { foo: 'bar' })
|
1055
1097
|
expect(provider.instantiated_variables).to eq({ foo: 'bar' })
|
1056
1098
|
end
|
1057
1099
|
end
|
1058
1100
|
|
1059
1101
|
describe '.clear_instantiated_variables!' do
|
1060
1102
|
after do
|
1061
|
-
|
1103
|
+
provider.instance_variable_set(:@instantiated_variables, [])
|
1062
1104
|
end
|
1063
1105
|
|
1064
1106
|
it 'sets the instantiated_variables instance variable to {}' do
|
1065
|
-
|
1107
|
+
provider.instance_variable_set(:@instantiated_variables, { foo: 'bar' })
|
1066
1108
|
expect { provider.clear_instantiated_variables! }.not_to raise_error
|
1067
|
-
expect(
|
1109
|
+
expect(provider.instance_variable_get(:@instantiated_variables)).to eq({})
|
1068
1110
|
end
|
1069
1111
|
end
|
1070
1112
|
|
@@ -1087,16 +1129,16 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
1087
1129
|
end
|
1088
1130
|
|
1089
1131
|
after do
|
1090
|
-
|
1132
|
+
provider.instance_variable_set(:@logon_failures, [])
|
1091
1133
|
end
|
1092
1134
|
|
1093
1135
|
it 'returns false if there have been no failed logons with the username/password combination' do
|
1094
|
-
|
1136
|
+
provider.instance_variable_set(:@logon_failures, [bad_credential_hash])
|
1095
1137
|
expect(provider.logon_failed_already?(good_credential_hash)).to be(false)
|
1096
1138
|
end
|
1097
1139
|
|
1098
1140
|
it 'returns true if the username/password specified are found in the logon_failures instance variable' do
|
1099
|
-
|
1141
|
+
provider.instance_variable_set(:@logon_failures, [good_credential_hash, bad_credential_hash])
|
1100
1142
|
expect(provider.logon_failed_already?(bad_credential_hash)).to be(true)
|
1101
1143
|
end
|
1102
1144
|
end
|
@@ -1437,16 +1479,18 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
1437
1479
|
context 'when the resource does not have the dscmeta_resource_implementation key' do
|
1438
1480
|
let(:test_resource) { {} }
|
1439
1481
|
|
1440
|
-
it '
|
1441
|
-
|
1482
|
+
it 'sets $UnmungedPSModulePath to the current PSModulePath' do
|
1483
|
+
# since https://github.com/puppetlabs/ruby-pwsh/pull/261 we load vendored path for MOF resources as well
|
1484
|
+
expect(result).to match(/\$UnmungedPSModulePath = .+GetEnvironmentVariable.+PSModulePath.+machine/)
|
1442
1485
|
end
|
1443
1486
|
end
|
1444
1487
|
|
1445
1488
|
context "when the resource's dscmeta_resource_implementation is not 'Class'" do
|
1446
1489
|
let(:test_resource) { { dscmeta_resource_implementation: 'MOF' } }
|
1447
1490
|
|
1448
|
-
|
1449
|
-
|
1491
|
+
# since https://github.com/puppetlabs/ruby-pwsh/pull/261 we load vendored path for MOF resources as well
|
1492
|
+
it 'sets $UnmungedPSModulePath to the current PSModulePath' do
|
1493
|
+
expect(result).to match(/\$UnmungedPSModulePath = .+GetEnvironmentVariable.+PSModulePath.+machine/)
|
1450
1494
|
end
|
1451
1495
|
end
|
1452
1496
|
|
@@ -1510,7 +1554,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
1510
1554
|
end
|
1511
1555
|
|
1512
1556
|
after do
|
1513
|
-
|
1557
|
+
provider.instance_variable_set(:@instantiated_variables, [])
|
1514
1558
|
end
|
1515
1559
|
|
1516
1560
|
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
|
@@ -1543,7 +1587,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
1543
1587
|
subject(:result) { provider.prepare_cim_instances(test_resource) }
|
1544
1588
|
|
1545
1589
|
after do
|
1546
|
-
|
1590
|
+
provider.instance_variable_set(:@instantiated_variables, [])
|
1547
1591
|
end
|
1548
1592
|
|
1549
1593
|
context 'when a cim instance is passed without nested cim instances' do
|
@@ -1652,7 +1696,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
1652
1696
|
|
1653
1697
|
describe '.format_ciminstance' do
|
1654
1698
|
after do
|
1655
|
-
|
1699
|
+
provider.instance_variable_set(:@instantiated_variables, [])
|
1656
1700
|
end
|
1657
1701
|
|
1658
1702
|
it 'defines and returns a new cim instance as a PowerShell variable, passing the class name and property hash' do
|
@@ -1668,7 +1712,7 @@ RSpec.describe Puppet::Provider::DscBaseProvider do
|
|
1668
1712
|
end
|
1669
1713
|
|
1670
1714
|
it 'interpolates variables in the case of a cim instance containing a nested instance' do
|
1671
|
-
|
1715
|
+
provider.instance_variable_set(:@instantiated_variables, { 'SomeVariable' => { 'bar' => 'ope' } })
|
1672
1716
|
property_hash = { 'foo' => { 'bar' => 'ope' } }
|
1673
1717
|
expect(provider.format_ciminstance('foo', 'SomeClass', property_hash)).to match(/@\{'foo' = \$SomeVariable\}/)
|
1674
1718
|
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: 1.
|
4
|
+
version: 1.1.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:
|
11
|
+
date: 2024-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: PowerShell code manager for ruby.
|
14
14
|
email:
|