ruby-pwsh 0.6.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +48 -0
- data/CONTRIBUTING.md +1 -1
- data/README.md +4 -4
- data/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb +65 -11
- data/lib/pwsh/version.rb +1 -1
- data/metadata.json +2 -2
- 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: b70b1a0989c8bc3458422b67e0c328084f819067d60455b9504031106a6c78e6
|
4
|
+
data.tar.gz: 44c5f49c82db4a56e76d521e1b90a5434d3bfacd6a5fa242e4e6c5c90878d875
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80207ddfde5794a3e461c769fdb20983bbc0f601cc18c99a57bd6e2f37ee3158ca27efa1a176d1bb600090860f107b059816f6ec5c263bbbd3d6b21bf7cb11df
|
7
|
+
data.tar.gz: 41d7a31a3703e24e5e64944776eeb889ac01f7acd685e867211898e37a0478606e3728747779e1073cc1138619d51f7e9b2c872047a3754ffc38d061d14916d6
|
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.1](https://github.com/puppetlabs/ruby-pwsh/tree/0.7.1) (2021-02-01)
|
6
|
+
|
7
|
+
[Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.7.0...0.7.1)
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
|
11
|
+
- \(MAINT\) Correctly canonicalize enumerable values in dsc [\#92](https://github.com/puppetlabs/ruby-pwsh/pull/92) ([michaeltlombardi](https://github.com/michaeltlombardi))
|
12
|
+
- \(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))
|
13
|
+
- \(GH-84\) Fix empty array parameter check [\#90](https://github.com/puppetlabs/ruby-pwsh/pull/90) ([michaeltlombardi](https://github.com/michaeltlombardi))
|
14
|
+
- \(MAINT\) Minor fixes to CIM instance handling [\#89](https://github.com/puppetlabs/ruby-pwsh/pull/89) ([michaeltlombardi](https://github.com/michaeltlombardi))
|
15
|
+
|
16
|
+
## [0.7.0](https://github.com/puppetlabs/ruby-pwsh/tree/0.7.0) (2021-01-20)
|
17
|
+
|
18
|
+
[Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.6.3...0.7.0)
|
19
|
+
|
20
|
+
### Added
|
21
|
+
|
22
|
+
- \(GH-75\) Including module name in vendored module path [\#85](https://github.com/puppetlabs/ruby-pwsh/pull/85) ([pmcmaw](https://github.com/pmcmaw))
|
23
|
+
|
24
|
+
### Fixed
|
25
|
+
|
26
|
+
- Make root module path use puppetized module name [\#86](https://github.com/puppetlabs/ruby-pwsh/pull/86) ([michaeltlombardi](https://github.com/michaeltlombardi))
|
27
|
+
|
28
|
+
## [0.6.3](https://github.com/puppetlabs/ruby-pwsh/tree/0.6.3) (2020-12-16)
|
29
|
+
|
30
|
+
[Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.6.2...0.6.3)
|
31
|
+
|
32
|
+
### Fixed
|
33
|
+
|
34
|
+
- \(MAINT\) Add handling for when dsc\_ensure is stripped [\#78](https://github.com/puppetlabs/ruby-pwsh/pull/78) ([michaeltlombardi](https://github.com/michaeltlombardi))
|
35
|
+
|
36
|
+
## [0.6.2](https://github.com/puppetlabs/ruby-pwsh/tree/0.6.2) (2020-12-09)
|
37
|
+
|
38
|
+
[Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.6.1...0.6.2)
|
39
|
+
|
40
|
+
### Fixed
|
41
|
+
|
42
|
+
- \(MAINT\) Ensure parameters are canonicalized [\#75](https://github.com/puppetlabs/ruby-pwsh/pull/75) ([michaeltlombardi](https://github.com/michaeltlombardi))
|
43
|
+
|
44
|
+
## [0.6.1](https://github.com/puppetlabs/ruby-pwsh/tree/0.6.1) (2020-11-25)
|
45
|
+
|
46
|
+
[Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.6.0...0.6.1)
|
47
|
+
|
48
|
+
### Fixed
|
49
|
+
|
50
|
+
- \(maint\) - Removal of inappropriate terminology [\#70](https://github.com/puppetlabs/ruby-pwsh/pull/70) ([pmcmaw](https://github.com/pmcmaw))
|
51
|
+
- \(Maint\) Fix ensurability in the dsc base provider [\#69](https://github.com/puppetlabs/ruby-pwsh/pull/69) ([michaeltlombardi](https://github.com/michaeltlombardi))
|
52
|
+
|
5
53
|
## [0.6.0](https://github.com/puppetlabs/ruby-pwsh/tree/0.6.0) (2020-11-24)
|
6
54
|
|
7
55
|
[Full Changelog](https://github.com/puppetlabs/ruby-pwsh/compare/0.5.1...0.6.0)
|
data/CONTRIBUTING.md
CHANGED
@@ -79,7 +79,7 @@ process as easy as possible.
|
|
79
79
|
|
80
80
|
2. Sending your patches
|
81
81
|
|
82
|
-
To submit your changes via a GitHub pull request, we _highly_ recommend that you have them on a topic branch, instead of directly on "
|
82
|
+
To submit your changes via a GitHub pull request, we _highly_ recommend that you have them on a topic branch, instead of directly on "main".
|
83
83
|
It makes things much easier to keep track of, especially if you decide to work on another thing before your first change is merged in.
|
84
84
|
|
85
85
|
GitHub has some pretty good [general documentation](http://help.github.com/) on using their site.
|
data/README.md
CHANGED
@@ -74,9 +74,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
74
74
|
|
75
75
|
Steps to release an update to the gem and module include:
|
76
76
|
|
77
|
-
1. Ensure that the release branch is up to date with the
|
77
|
+
1. Ensure that the release branch is up to date with the main:
|
78
78
|
```bash
|
79
|
-
git push upstream upstream/
|
79
|
+
git push upstream upstream/main:release --force
|
80
80
|
```
|
81
81
|
1. Checkout a new working branch for the release prep (where xyz is the appropriate version, sans periods):
|
82
82
|
```bash
|
@@ -96,7 +96,7 @@ Steps to release an update to the gem and module include:
|
|
96
96
|
```
|
97
97
|
1. Push your changes and submit a pull request for review _against the **release** branch_:
|
98
98
|
```bash
|
99
|
-
git push -u origin maint/release
|
99
|
+
git push -u origin maint/release/prep-xyz
|
100
100
|
```
|
101
101
|
1. Ensure tests pass and the code is merged to `release`.
|
102
102
|
1. Grab the commit hash from the merge commit on release, use that as the tag for the version (replacing `x.y.z` with the appropriate version and `commithash` with the relevant one), then push the tags to upstream:
|
@@ -114,6 +114,6 @@ Steps to release an update to the gem and module include:
|
|
114
114
|
bundle exec rake build_module
|
115
115
|
```
|
116
116
|
1. Publish the updated module version (found in the `pkg` folder) to [the Forge](https://forge.puppet.com/puppetlabs/pwshlib).
|
117
|
-
1. Submit the [mergeback PR from the release branch to
|
117
|
+
1. Submit the [mergeback PR from the release branch to main](https://github.com/puppetlabs/ruby-pwsh/compare/main...release).
|
118
118
|
|
119
119
|
## Known Issues
|
@@ -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
|
-
|
64
|
+
is_same = value.is_a?(Enumerable) ? 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
|
@@ -134,14 +137,15 @@ class Puppet::Provider::DscBaseProvider
|
|
134
137
|
end
|
135
138
|
|
136
139
|
# for compatibility sake, we use dsc_ensure instead of ensure, so context.type.ensurable? does not work
|
137
|
-
if
|
140
|
+
if context.type.attributes.key?(:dsc_ensure)
|
138
141
|
is = create_absent(:name, name) if is.nil?
|
139
142
|
should = create_absent(:name, name) if should.nil?
|
140
143
|
|
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
|
-
|
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
|
@@ -280,6 +284,15 @@ class Puppet::Provider::DscBaseProvider
|
|
280
284
|
# If a resource is found, it's present, so refill this Puppet-only key
|
281
285
|
data.merge!({ name: name_hash[:name] })
|
282
286
|
|
287
|
+
# Have to check for this to avoid a weird canonicalization warning
|
288
|
+
# The Resource API calls canonicalize against the current state which
|
289
|
+
# will lead to dsc_ensure being set to absent in the name_hash even if
|
290
|
+
# it was set to present in the manifest
|
291
|
+
name_hash_has_nil_keys = name_hash.select { |_k, v| v.nil? }.count.positive?
|
292
|
+
# We want to throw away all of the empty keys if and only if the manifest
|
293
|
+
# declaration is for an absent resource and the resource is actually absent
|
294
|
+
data.reject! { |_k, v| v.nil? } if data[:dsc_ensure] == 'Absent' && name_hash[:dsc_ensure] == 'Absent' && !name_hash_has_nil_keys
|
295
|
+
|
283
296
|
# Cache the query to prevent a second lookup
|
284
297
|
@@cached_query_results << data.dup if fetch_cached_hashes(@@cached_query_results, [data]).empty?
|
285
298
|
context.debug("Returned to Puppet as #{data}")
|
@@ -346,17 +359,49 @@ class Puppet::Provider::DscBaseProvider
|
|
346
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;
|
347
360
|
# PROBLEM: This currently uses the downcased name, we need to capture the module name in the metadata I think.
|
348
361
|
# During a Puppet agent run, the code lives in the cache so we can use the file expansion to discover the correct folder.
|
349
|
-
|
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
|
350
367
|
resource[:vendored_modules_path] = if root_module_path.nil?
|
351
|
-
File.expand_path(Pathname.new(__FILE__).dirname + '../../../' +
|
368
|
+
File.expand_path(Pathname.new(__FILE__).dirname + '../../../' + "puppet_x/#{puppetize_name(resource[:dscmeta_module_name])}/dsc_resources") # rubocop:disable Style/StringConcatenation
|
352
369
|
else
|
353
|
-
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")
|
354
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
|
+
|
355
386
|
resource[:attributes] = nil
|
387
|
+
|
356
388
|
context.debug("should_to_resource: #{resource.inspect}")
|
357
389
|
resource
|
358
390
|
end
|
359
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
|
+
|
360
405
|
# Return a UUID with the dashes turned into underscores to enable the specifying of guaranteed-unique
|
361
406
|
# variables in the PowerShell script.
|
362
407
|
#
|
@@ -452,6 +497,14 @@ class Puppet::Provider::DscBaseProvider
|
|
452
497
|
context.type.attributes.select { |_attribute, properties| properties[:behaviour] == :namevar }.keys
|
453
498
|
end
|
454
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
|
+
|
455
508
|
# Look through a fully formatted string, replacing all instances where a value matches the formatted properties
|
456
509
|
# of an instantiated variable with references to the variable instead. This allows us to pass complex and nested
|
457
510
|
# CIM instances to the Invoke-DscResource parameter hash without constructing them *in* the hash.
|
@@ -485,8 +538,8 @@ class Puppet::Provider::DscBaseProvider
|
|
485
538
|
'user' => property_hash[:value]['user'],
|
486
539
|
'password' => escape_quotes(property_hash[:value]['password'].unwrap)
|
487
540
|
}
|
488
|
-
instantiated_variables.merge!(variable_name => credential_hash)
|
489
541
|
credentials_block << format_pscredential(variable_name, credential_hash)
|
542
|
+
instantiated_variables.merge!(variable_name => credential_hash)
|
490
543
|
end
|
491
544
|
credentials_block.join("\n")
|
492
545
|
credentials_block == [] ? '' : credentials_block
|
@@ -513,6 +566,7 @@ class Puppet::Provider::DscBaseProvider
|
|
513
566
|
cim_instances_block = []
|
514
567
|
resource[:parameters].each do |_property_name, property_hash|
|
515
568
|
next unless property_hash[:mof_is_embedded]
|
569
|
+
next if property_hash[:mof_type] == 'PSCredential' # Credentials are handled separately
|
516
570
|
|
517
571
|
# strip dsc_ from the beginning of the property name declaration
|
518
572
|
# name = property_name.to_s.gsub(/^dsc_/, '').to_sym
|
@@ -523,10 +577,10 @@ class Puppet::Provider::DscBaseProvider
|
|
523
577
|
unless cim_instance_hashes.count.zero?
|
524
578
|
cim_instance_hashes.each do |instance|
|
525
579
|
variable_name = random_variable_name
|
526
|
-
instantiated_variables.merge!(variable_name => instance)
|
527
580
|
class_name = instance['cim_instance_type']
|
528
581
|
properties = instance.reject { |k, _v| k == 'cim_instance_type' }
|
529
582
|
cim_instances_block << format_ciminstance(variable_name, class_name, properties)
|
583
|
+
instantiated_variables.merge!(variable_name => instance)
|
530
584
|
end
|
531
585
|
end
|
532
586
|
# We have to handle arrays of CIM instances slightly differently
|
@@ -534,14 +588,14 @@ class Puppet::Provider::DscBaseProvider
|
|
534
588
|
class_name = property_hash[:mof_type].gsub('[]', '')
|
535
589
|
property_hash[:value].each do |hash|
|
536
590
|
variable_name = random_variable_name
|
537
|
-
instantiated_variables.merge!(variable_name => hash)
|
538
591
|
cim_instances_block << format_ciminstance(variable_name, class_name, hash)
|
592
|
+
instantiated_variables.merge!(variable_name => hash)
|
539
593
|
end
|
540
594
|
else
|
541
595
|
variable_name = random_variable_name
|
542
|
-
instantiated_variables.merge!(variable_name => property_hash[:value])
|
543
596
|
class_name = property_hash[:mof_type]
|
544
597
|
cim_instances_block << format_ciminstance(variable_name, class_name, property_hash[:value])
|
598
|
+
instantiated_variables.merge!(variable_name => property_hash[:value])
|
545
599
|
end
|
546
600
|
end
|
547
601
|
cim_instances_block == [] ? '' : cim_instances_block.join("\n")
|
@@ -624,7 +678,7 @@ class Puppet::Provider::DscBaseProvider
|
|
624
678
|
params_block = params_block.gsub("'[DateTime]", "[DateTime]'")
|
625
679
|
# HACK: Handle intentionally empty arrays - need to strongly type them because
|
626
680
|
# CIM instances do not do a consistent job of casting an empty array properly.
|
627
|
-
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? }
|
628
682
|
empty_array_parameters.each do |name, properties|
|
629
683
|
param_block_name = name.to_s.gsub(/^dsc_/, '')
|
630
684
|
params_block = params_block.gsub("#{param_block_name} = @()", "#{param_block_name} = [#{properties[:mof_type]}]@()")
|
data/lib/pwsh/version.rb
CHANGED
data/metadata.json
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "puppetlabs-pwshlib",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.7.1",
|
4
4
|
"author": "puppetlabs",
|
5
5
|
"summary": "Provide library code for interoperating with PowerShell.",
|
6
6
|
"license": "MIT",
|
7
7
|
"source": "https://github.com/puppetlabs/ruby-pwsh",
|
8
|
-
"project_page": "https://github.com/puppetlabs/ruby-pwsh/blob/
|
8
|
+
"project_page": "https://github.com/puppetlabs/ruby-pwsh/blob/main/pwshlib.md",
|
9
9
|
"issues_url": "https://github.com/puppetlabs/ruby-pwsh/issues",
|
10
10
|
"dependencies": [
|
11
11
|
|
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.
|
4
|
+
version: 0.7.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:
|
11
|
+
date: 2021-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: PowerShell code manager for ruby.
|
14
14
|
email:
|