ruby-pwsh 0.6.1 → 0.7.2

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: 2986a999feb45efb7f137175c7ba987423410fa62ec525f15b877c225d566a05
4
- data.tar.gz: e966eeca3f8d8eb089016250e7029cdf98290dedd6beff21208e031f5d28dc0b
3
+ metadata.gz: 01ea31b0b9ccabe461c1e51ba916f674e93658dcc82ce618e23066ba4d3273bb
4
+ data.tar.gz: 407cae60f748c60584668f52f7354e59a3c1d8012ec0494c017f7e9da49e6cee
5
5
  SHA512:
6
- metadata.gz: 7f74605239b19db0740f36480507f2a4fe009d7bd566dfa5bfe460e2211c42a7738eb8714d78231e5067163f8257c1d9e45262d1c54ca6d7b37b849681c4108d
7
- data.tar.gz: ee4a0cfbe10784b763dfb3c4eabbe4b09de537bdf78b2e2e06028afbab9f72b78b3fc4f3960ac3ce979ce2212fd0b5762704b990f8b1a6fb2e230641e4270343
6
+ metadata.gz: 209ac4aafdc2717285ad637217e99e6a469b286e10fcb1d0ba6b13759f04b2f94f0ce69fd813984f581eb27a35ba8cb6ea41eb50ecb7a2c2f4cfffa5469a23f4
7
+ data.tar.gz: fc99b84247299879dffb1c41b89beaa4a23eddfd3d61ad605d3aa8568f98fc1acf2f072bc264e17b9d91df3be3f59ffffa7fe9981270f61fc0adcdf0048e10ab
data/CHANGELOG.md CHANGED
@@ -2,6 +2,54 @@
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.7.2](https://github.com/puppetlabs/ruby-pwsh/tree/0.7.2) (2021-02-03)
6
+
7
+ [Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.7.1...0.7.2)
8
+
9
+ ### Fixed
10
+
11
+ - \(GH-97\) Memoize class variables in initialize [\#98](https://github.com/puppetlabs/ruby-pwsh/pull/98) ([michaeltlombardi](https://github.com/michaeltlombardi))
12
+ - \(MAINT\) Ensure is\_same check works for nil manifest values [\#96](https://github.com/puppetlabs/ruby-pwsh/pull/96) ([bwilcox](https://github.com/bwilcox))
13
+
14
+ ## [0.7.1](https://github.com/puppetlabs/ruby-pwsh/tree/0.7.1) (2021-02-02)
15
+
16
+ [Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.7.0...0.7.1)
17
+
18
+ ### Fixed
19
+
20
+ - \(MAINT\) Correctly canonicalize enumerable values in dsc [\#92](https://github.com/puppetlabs/ruby-pwsh/pull/92) ([michaeltlombardi](https://github.com/michaeltlombardi))
21
+ - \(MAINT\) Ensure vendored path check works with mix of module builds [\#91](https://github.com/puppetlabs/ruby-pwsh/pull/91) ([michaeltlombardi](https://github.com/michaeltlombardi))
22
+ - \(GH-84\) Fix empty array parameter check [\#90](https://github.com/puppetlabs/ruby-pwsh/pull/90) ([michaeltlombardi](https://github.com/michaeltlombardi))
23
+ - \(MAINT\) Minor fixes to CIM instance handling [\#89](https://github.com/puppetlabs/ruby-pwsh/pull/89) ([michaeltlombardi](https://github.com/michaeltlombardi))
24
+
25
+ ## [0.7.0](https://github.com/puppetlabs/ruby-pwsh/tree/0.7.0) (2021-01-20)
26
+
27
+ [Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.6.3...0.7.0)
28
+
29
+ ### Added
30
+
31
+ - \(GH-75\) Including module name in vendored module path [\#85](https://github.com/puppetlabs/ruby-pwsh/pull/85) ([pmcmaw](https://github.com/pmcmaw))
32
+
33
+ ### Fixed
34
+
35
+ - Make root module path use puppetized module name [\#86](https://github.com/puppetlabs/ruby-pwsh/pull/86) ([michaeltlombardi](https://github.com/michaeltlombardi))
36
+
37
+ ## [0.6.3](https://github.com/puppetlabs/ruby-pwsh/tree/0.6.3) (2020-12-16)
38
+
39
+ [Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.6.2...0.6.3)
40
+
41
+ ### Fixed
42
+
43
+ - \(MAINT\) Add handling for when dsc\_ensure is stripped [\#78](https://github.com/puppetlabs/ruby-pwsh/pull/78) ([michaeltlombardi](https://github.com/michaeltlombardi))
44
+
45
+ ## [0.6.2](https://github.com/puppetlabs/ruby-pwsh/tree/0.6.2) (2020-12-09)
46
+
47
+ [Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.6.1...0.6.2)
48
+
49
+ ### Fixed
50
+
51
+ - \(MAINT\) Ensure parameters are canonicalized [\#75](https://github.com/puppetlabs/ruby-pwsh/pull/75) ([michaeltlombardi](https://github.com/michaeltlombardi))
52
+
5
53
  ## [0.6.1](https://github.com/puppetlabs/ruby-pwsh/tree/0.6.1) (2020-11-25)
6
54
 
7
55
  [Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.6.0...0.6.1)
@@ -11,9 +11,9 @@ class Puppet::Provider::DscBaseProvider
11
11
  # - query results
12
12
  # - logon failures
13
13
  def initialize
14
- @@cached_canonicalized_resource = []
15
- @@cached_query_results = []
16
- @@logon_failures = []
14
+ @@cached_canonicalized_resource ||= []
15
+ @@cached_query_results ||= []
16
+ @@logon_failures ||= []
17
17
  super
18
18
  end
19
19
 
@@ -50,6 +50,8 @@ class Puppet::Provider::DscBaseProvider
50
50
  canonicalized = r.dup
51
51
  @@cached_canonicalized_resource << r.dup
52
52
  else
53
+ parameters = r.select { |name, _properties| parameter_attributes(context).include?(name) }
54
+ canonicalized.merge!(parameters)
53
55
  canonicalized[:name] = r[:name]
54
56
  if r[:dsc_psdscrunascredential].nil?
55
57
  canonicalized.delete(:dsc_psdscrunascredential)
@@ -59,7 +61,8 @@ class Puppet::Provider::DscBaseProvider
59
61
  downcased_result = recursively_downcase(canonicalized)
60
62
  downcased_resource = recursively_downcase(r)
61
63
  downcased_result.each do |key, value|
62
- canonicalized[key] = r[key] unless downcased_resource[key] == value
64
+ is_same = value.is_a?(Enumerable) & !downcased_resource[key] ? downcased_resource[key].sort == value.sort : downcased_resource[key] == value
65
+ canonicalized[key] = r[key] unless is_same
63
66
  canonicalized.delete(key) unless downcased_resource.keys.include?(key)
64
67
  end
65
68
  # Cache the actually canonicalized resource separately
@@ -141,7 +144,8 @@ class Puppet::Provider::DscBaseProvider
141
144
  # HACK: If the DSC Resource is ensurable but doesn't report a default value
142
145
  # for ensure, we assume it to be `Present` - this is the most common pattern.
143
146
  should_ensure = should[:dsc_ensure].nil? ? 'Present' : should[:dsc_ensure].to_s
144
- is_ensure = is[:dsc_ensure].to_s
147
+ # HACK: Sometimes dsc_ensure is removed???? If it's gone, pretend it's absent??
148
+ is_ensure = is[:dsc_ensure].nil? ? 'Absent' : is[:dsc_ensure].to_s
145
149
 
146
150
  if is_ensure == 'Absent' && should_ensure == 'Present'
147
151
  context.creating(name) do
@@ -355,17 +359,49 @@ class Puppet::Provider::DscBaseProvider
355
359
  # Because Puppet adds all of the modules to the LOAD_PATH we can be sure that the appropriate module lives here during an apply;
356
360
  # PROBLEM: This currently uses the downcased name, we need to capture the module name in the metadata I think.
357
361
  # During a Puppet agent run, the code lives in the cache so we can use the file expansion to discover the correct folder.
358
- root_module_path = $LOAD_PATH.select { |path| path.match?(%r{#{resource[:dscmeta_module_name].downcase}/lib}) }.first
362
+ # This handles setting the vendored_modules_path to include the puppet module name; we now add the puppet module name into the
363
+ # path to allow multiple modules to with shared dsc_resources to be installed side by side
364
+ # The old vendored_modules_path: puppet_x/dsc_resources
365
+ # The new vendored_modules_path: puppet_x/<module_name>/dsc_resources
366
+ root_module_path = $LOAD_PATH.select { |path| path.match?(%r{#{puppetize_name(resource[:dscmeta_module_name])}/lib}) }.first
359
367
  resource[:vendored_modules_path] = if root_module_path.nil?
360
- File.expand_path(Pathname.new(__FILE__).dirname + '../../../' + 'puppet_x/dsc_resources') # rubocop:disable Style/StringConcatenation
368
+ File.expand_path(Pathname.new(__FILE__).dirname + '../../../' + "puppet_x/#{puppetize_name(resource[:dscmeta_module_name])}/dsc_resources") # rubocop:disable Style/StringConcatenation
361
369
  else
362
- File.expand_path("#{root_module_path}/puppet_x/dsc_resources")
370
+ File.expand_path("#{root_module_path}/puppet_x/#{puppetize_name(resource[:dscmeta_module_name])}/dsc_resources")
363
371
  end
372
+
373
+ # Check for the old vendored_modules_path second - if there is a mix of modules with the old and new pathing,
374
+ # checking for this first will always work and so the more specific search will never run.
375
+ unless File.exist? resource[:vendored_modules_path]
376
+ resource[:vendored_modules_path] = if root_module_path.nil?
377
+ File.expand_path(Pathname.new(__FILE__).dirname + '../../../' + 'puppet_x/dsc_resources') # rubocop:disable Style/StringConcatenation
378
+ else
379
+ File.expand_path("#{root_module_path}/puppet_x/dsc_resources")
380
+ end
381
+ end
382
+
383
+ # A warning is thrown if the something went wrong and the file was not created
384
+ raise "Unable to find expected vendored DSC Resource #{resource[:vendored_modules_path]}" unless File.exist? resource[:vendored_modules_path]
385
+
364
386
  resource[:attributes] = nil
387
+
365
388
  context.debug("should_to_resource: #{resource.inspect}")
366
389
  resource
367
390
  end
368
391
 
392
+ # Return a String containing a puppetized name. A puppetized name is a string that only
393
+ # includes lowercase letters, digits, underscores and cannot start with a digit.
394
+ #
395
+ # @return [String] with a puppeized module name
396
+ def puppetize_name(name)
397
+ # Puppet module names must be lower case
398
+ name = name.downcase
399
+ # Puppet module names must only include lowercase letters, digits and underscores
400
+ name = name.gsub(/[^a-z0-9_]/, '_')
401
+ # Puppet module names must not start with a number so if it does, append the letter 'a' to the name. Eg: '7zip' becomes 'a7zip'
402
+ name = name.match?(/^\d/) ? "a#{name}" : name # rubocop:disable Lint/UselessAssignment
403
+ end
404
+
369
405
  # Return a UUID with the dashes turned into underscores to enable the specifying of guaranteed-unique
370
406
  # variables in the PowerShell script.
371
407
  #
@@ -461,6 +497,14 @@ class Puppet::Provider::DscBaseProvider
461
497
  context.type.attributes.select { |_attribute, properties| properties[:behaviour] == :namevar }.keys
462
498
  end
463
499
 
500
+ # Parses the DSC resource type definition to retrieve the names of any attributes which are specified as parameters
501
+ #
502
+ # @param context [Object] the Puppet runtime context to operate in and send feedback to
503
+ # @return [Array] returns an array of attribute names as symbols which are parameters
504
+ def parameter_attributes(context)
505
+ context.type.attributes.select { |_name, properties| properties[:behaviour] == :parameter }.keys
506
+ end
507
+
464
508
  # Look through a fully formatted string, replacing all instances where a value matches the formatted properties
465
509
  # of an instantiated variable with references to the variable instead. This allows us to pass complex and nested
466
510
  # CIM instances to the Invoke-DscResource parameter hash without constructing them *in* the hash.
@@ -494,8 +538,8 @@ class Puppet::Provider::DscBaseProvider
494
538
  'user' => property_hash[:value]['user'],
495
539
  'password' => escape_quotes(property_hash[:value]['password'].unwrap)
496
540
  }
497
- instantiated_variables.merge!(variable_name => credential_hash)
498
541
  credentials_block << format_pscredential(variable_name, credential_hash)
542
+ instantiated_variables.merge!(variable_name => credential_hash)
499
543
  end
500
544
  credentials_block.join("\n")
501
545
  credentials_block == [] ? '' : credentials_block
@@ -522,6 +566,7 @@ class Puppet::Provider::DscBaseProvider
522
566
  cim_instances_block = []
523
567
  resource[:parameters].each do |_property_name, property_hash|
524
568
  next unless property_hash[:mof_is_embedded]
569
+ next if property_hash[:mof_type] == 'PSCredential' # Credentials are handled separately
525
570
 
526
571
  # strip dsc_ from the beginning of the property name declaration
527
572
  # name = property_name.to_s.gsub(/^dsc_/, '').to_sym
@@ -532,10 +577,10 @@ class Puppet::Provider::DscBaseProvider
532
577
  unless cim_instance_hashes.count.zero?
533
578
  cim_instance_hashes.each do |instance|
534
579
  variable_name = random_variable_name
535
- instantiated_variables.merge!(variable_name => instance)
536
580
  class_name = instance['cim_instance_type']
537
581
  properties = instance.reject { |k, _v| k == 'cim_instance_type' }
538
582
  cim_instances_block << format_ciminstance(variable_name, class_name, properties)
583
+ instantiated_variables.merge!(variable_name => instance)
539
584
  end
540
585
  end
541
586
  # We have to handle arrays of CIM instances slightly differently
@@ -543,14 +588,14 @@ class Puppet::Provider::DscBaseProvider
543
588
  class_name = property_hash[:mof_type].gsub('[]', '')
544
589
  property_hash[:value].each do |hash|
545
590
  variable_name = random_variable_name
546
- instantiated_variables.merge!(variable_name => hash)
547
591
  cim_instances_block << format_ciminstance(variable_name, class_name, hash)
592
+ instantiated_variables.merge!(variable_name => hash)
548
593
  end
549
594
  else
550
595
  variable_name = random_variable_name
551
- instantiated_variables.merge!(variable_name => property_hash[:value])
552
596
  class_name = property_hash[:mof_type]
553
597
  cim_instances_block << format_ciminstance(variable_name, class_name, property_hash[:value])
598
+ instantiated_variables.merge!(variable_name => property_hash[:value])
554
599
  end
555
600
  end
556
601
  cim_instances_block == [] ? '' : cim_instances_block.join("\n")
@@ -633,7 +678,7 @@ class Puppet::Provider::DscBaseProvider
633
678
  params_block = params_block.gsub("'[DateTime]", "[DateTime]'")
634
679
  # HACK: Handle intentionally empty arrays - need to strongly type them because
635
680
  # CIM instances do not do a consistent job of casting an empty array properly.
636
- empty_array_parameters = resource[:parameters].select { |_k, v| v[:value].empty? }
681
+ empty_array_parameters = resource[:parameters].select { |_k, v| v[:value].is_a?(Array) && v[:value].empty? }
637
682
  empty_array_parameters.each do |name, properties|
638
683
  param_block_name = name.to_s.gsub(/^dsc_/, '')
639
684
  params_block = params_block.gsub("#{param_block_name} = @()", "#{param_block_name} = [#{properties[:mof_type]}]@()")
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.6.1'
5
+ VERSION = '0.7.2'
6
6
  end
data/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "puppetlabs-pwshlib",
3
- "version": "0.6.1",
3
+ "version": "0.7.2",
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.6.1
4
+ version: 0.7.2
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: 2020-11-25 00:00:00.000000000 Z
11
+ date: 2021-02-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: PowerShell code manager for ruby.
14
14
  email:
@@ -54,7 +54,7 @@ metadata:
54
54
  homepage_uri: https://github.com/puppetlabs/ruby-pwsh
55
55
  source_code_uri: https://github.com/puppetlabs/ruby-pwsh
56
56
  changelog_uri: https://github.com/puppetlabs/ruby-pwsh
57
- post_install_message:
57
+ post_install_message:
58
58
  rdoc_options: []
59
59
  require_paths:
60
60
  - lib
@@ -69,8 +69,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  requirements: []
72
- rubygems_version: 3.1.4
73
- signing_key:
72
+ rubyforge_project:
73
+ rubygems_version: 2.7.6
74
+ signing_key:
74
75
  specification_version: 4
75
76
  summary: PowerShell code manager for ruby.
76
77
  test_files: []