ruby-pwsh 1.2.0 → 1.2.1
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 +4 -4
- data/README.md +1 -0
- data/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb +6 -6
- data/lib/puppet/provider/dsc_base_provider/invoke_dsc_resource_functions.ps1 +1 -1
- data/lib/pwsh/util.rb +7 -11
- data/lib/pwsh/version.rb +1 -1
- data/lib/pwsh.rb +1 -1
- data/spec/unit/pwsh/util_spec.rb +42 -7
- 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: 106716635e03eef49ab00c8dd35cf16a5674a27452968b16ba7756ba252b97be
|
4
|
+
data.tar.gz: 4bd6c34343347a1d705cea410346028bbb91446bf5983e75409f16c7730f1000
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8b6c0c4ff6eabbc9a842cc863d76128dbccca74fabfef02b4aea6ba54f3a01ffd3d97447df4ccc027a8f22cf6a7b430b0893e34d0de7989e742442cf56b5ef9
|
7
|
+
data.tar.gz: 2404be74308d1b80c5d8f775f49f0f0ac6ae7deab47fe7c38e25e79852aac42f87e16b5cea5e4a4617cdde6eac1236cc8407a0e10fe2c9198bcfd0d6e88a7548
|
data/README.md
CHANGED
@@ -682,16 +682,16 @@ class Puppet::Provider::DscBaseProvider # rubocop:disable Metrics/ClassLength
|
|
682
682
|
context.type.attributes.select { |_attribute, properties| properties[:mandatory_for_set] }.keys
|
683
683
|
end
|
684
684
|
|
685
|
-
# Parses the DSC resource type definition to retrieve the names of any attributes which are
|
686
|
-
# This is used to ensure that any nil values are converted to empty strings to match puppets
|
685
|
+
# Parses the DSC resource type definition to retrieve the names of any attributes which are specifed as required strings
|
686
|
+
# This is used to ensure that any nil values are converted to empty strings to match puppets expecetd value
|
687
687
|
# @param context [Object] the Puppet runtime context to operate in and send feedback to
|
688
688
|
# @param data [Hash] the hash of properties returned from the DSC resource
|
689
689
|
# @return [Hash] returns a data hash with any nil values converted to empty strings
|
690
690
|
def stringify_nil_attributes(context, data)
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
data[
|
691
|
+
nil_strings = data.select { |_name, value| value.nil? }.keys
|
692
|
+
string_attrs = context.type.attributes.select { |_name, properties| properties[:type] == 'String' }.keys
|
693
|
+
string_attrs.each do |attribute|
|
694
|
+
data[attribute] = '' if nil_strings.include?(attribute)
|
695
695
|
end
|
696
696
|
data
|
697
697
|
end
|
data/lib/pwsh/util.rb
CHANGED
@@ -15,20 +15,16 @@ module Pwsh
|
|
15
15
|
!!(host_os =~ /mswin|mingw/)
|
16
16
|
end
|
17
17
|
|
18
|
-
# Verify paths specified are valid directories
|
19
|
-
#
|
20
|
-
# @return [Bool] true if any
|
18
|
+
# Verify paths specified are valid directories.
|
19
|
+
# Skips paths which do not exist.
|
20
|
+
# @return [Bool] true if any paths specified are not valid directories
|
21
21
|
def invalid_directories?(path_collection)
|
22
|
-
|
23
|
-
|
24
|
-
return invalid_paths if path_collection.nil? || path_collection.empty?
|
22
|
+
return false if path_collection.nil? || path_collection.empty?
|
25
23
|
|
26
|
-
|
27
|
-
paths
|
28
|
-
invalid_paths = true unless File.directory?(path) || path.empty?
|
29
|
-
end
|
24
|
+
delimiter = on_windows? ? ';' : ':'
|
25
|
+
paths = path_collection.split(delimiter)
|
30
26
|
|
31
|
-
|
27
|
+
paths.any? { |path| !path.empty? && File.exist?(path) && !File.directory?(path) }
|
32
28
|
end
|
33
29
|
|
34
30
|
# Return a string or symbol converted to snake_case
|
data/lib/pwsh/version.rb
CHANGED
data/lib/pwsh.rb
CHANGED
@@ -108,7 +108,7 @@ module Pwsh
|
|
108
108
|
@powershell_command = cmd
|
109
109
|
@powershell_arguments = args
|
110
110
|
|
111
|
-
|
111
|
+
warn "Bad configuration for ENV['lib']=#{ENV['lib']} - invalid path" if Pwsh::Util.invalid_directories?(ENV['lib'])
|
112
112
|
|
113
113
|
if Pwsh::Util.on_windows?
|
114
114
|
# Named pipes under Windows will automatically be mounted in \\.\pipe\...
|
data/spec/unit/pwsh/util_spec.rb
CHANGED
@@ -87,13 +87,15 @@ RSpec.describe Pwsh::Util do
|
|
87
87
|
end
|
88
88
|
|
89
89
|
describe '.invalid_directories?' do
|
90
|
-
let(:valid_path_a)
|
91
|
-
let(:valid_path_b)
|
92
|
-
let(:valid_paths)
|
93
|
-
let(:invalid_path)
|
94
|
-
let(:mixed_paths)
|
95
|
-
let(:empty_string)
|
96
|
-
let(:
|
90
|
+
let(:valid_path_a) { 'C:/some/folder' }
|
91
|
+
let(:valid_path_b) { 'C:/another/folder' }
|
92
|
+
let(:valid_paths) { 'C:/some/folder;C:/another/folder' }
|
93
|
+
let(:invalid_path) { 'C:/invalid/path' }
|
94
|
+
let(:mixed_paths) { 'C:/some/folder;C:/another/folder;C:/invalid/path' }
|
95
|
+
let(:empty_string) { '' }
|
96
|
+
let(:file_path) { 'C:/some/folder/file.txt' }
|
97
|
+
let(:non_existent_dir) { 'C:/some/dir/that/doesnt/exist' }
|
98
|
+
let(:empty_members) { 'C:/some/folder;;C:/another/folder' }
|
97
99
|
|
98
100
|
it 'returns false if passed nil' do
|
99
101
|
expect(described_class.invalid_directories?(nil)).to be false
|
@@ -103,8 +105,16 @@ RSpec.describe Pwsh::Util do
|
|
103
105
|
expect(described_class.invalid_directories?('')).to be false
|
104
106
|
end
|
105
107
|
|
108
|
+
it 'returns true if a file path is provided' do
|
109
|
+
expect(described_class).to receive(:on_windows?).and_return(true)
|
110
|
+
expect(File).to receive(:exist?).with(file_path).and_return(true)
|
111
|
+
expect(File).to receive(:directory?).with(file_path).and_return(false)
|
112
|
+
expect(described_class.invalid_directories?(file_path)).to be true
|
113
|
+
end
|
114
|
+
|
106
115
|
it 'returns false if one valid path is provided' do
|
107
116
|
expect(described_class).to receive(:on_windows?).and_return(true)
|
117
|
+
expect(File).to receive(:exist?).with(valid_path_a).and_return(true)
|
108
118
|
expect(File).to receive(:directory?).with(valid_path_a).and_return(true)
|
109
119
|
expect(described_class.invalid_directories?(valid_path_a)).to be false
|
110
120
|
end
|
@@ -112,31 +122,56 @@ RSpec.describe Pwsh::Util do
|
|
112
122
|
it 'returns false if a collection of valid paths is provided' do
|
113
123
|
expect(described_class).to receive(:on_windows?).and_return(true)
|
114
124
|
expect(File).to receive(:directory?).with(valid_path_a).and_return(true)
|
125
|
+
expect(File).to receive(:exist?).with(valid_path_a).and_return(true)
|
115
126
|
expect(File).to receive(:directory?).with(valid_path_b).and_return(true)
|
127
|
+
expect(File).to receive(:exist?).with(valid_path_b).and_return(true)
|
116
128
|
expect(described_class.invalid_directories?(valid_paths)).to be false
|
117
129
|
end
|
118
130
|
|
119
131
|
it 'returns true if there is only one path and it is invalid' do
|
120
132
|
expect(described_class).to receive(:on_windows?).and_return(true)
|
133
|
+
expect(File).to receive(:exist?).with(invalid_path).and_return(true)
|
121
134
|
expect(File).to receive(:directory?).with(invalid_path).and_return(false)
|
122
135
|
expect(described_class.invalid_directories?(invalid_path)).to be true
|
123
136
|
end
|
124
137
|
|
125
138
|
it 'returns true if the collection has on valid and one invalid member' do
|
126
139
|
expect(described_class).to receive(:on_windows?).and_return(true)
|
140
|
+
expect(File).to receive(:exist?).with(valid_path_a).and_return(true)
|
127
141
|
expect(File).to receive(:directory?).with(valid_path_a).and_return(true)
|
142
|
+
expect(File).to receive(:exist?).with(valid_path_b).and_return(true)
|
128
143
|
expect(File).to receive(:directory?).with(valid_path_b).and_return(true)
|
144
|
+
expect(File).to receive(:exist?).with(invalid_path).and_return(true)
|
129
145
|
expect(File).to receive(:directory?).with(invalid_path).and_return(false)
|
130
146
|
expect(described_class.invalid_directories?(mixed_paths)).to be true
|
131
147
|
end
|
132
148
|
|
133
149
|
it 'returns false if collection has empty members but other entries are valid' do
|
134
150
|
expect(described_class).to receive(:on_windows?).and_return(true)
|
151
|
+
expect(File).to receive(:exist?).with(valid_path_a).and_return(true)
|
135
152
|
expect(File).to receive(:directory?).with(valid_path_a).and_return(true)
|
153
|
+
expect(File).to receive(:exist?).with(valid_path_b).and_return(true)
|
136
154
|
expect(File).to receive(:directory?).with(valid_path_b).and_return(true)
|
137
155
|
allow(File).to receive(:directory?).with('')
|
138
156
|
expect(described_class.invalid_directories?(empty_members)).to be false
|
139
157
|
end
|
158
|
+
|
159
|
+
it 'returns true if a collection has valid members but also contains a file path' do
|
160
|
+
expect(described_class).to receive(:on_windows?).and_return(true)
|
161
|
+
expect(File).to receive(:exist?).with(valid_path_a).and_return(true)
|
162
|
+
expect(File).to receive(:directory?).with(valid_path_a).and_return(true)
|
163
|
+
expect(File).to receive(:exist?).with(file_path).and_return(true)
|
164
|
+
expect(File).to receive(:directory?).with(file_path).and_return(false)
|
165
|
+
expect(described_class.invalid_directories?("#{valid_path_a};#{file_path}")).to be true
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'returns false if a collection has valid members but contains a non-existent dir path' do
|
169
|
+
expect(described_class).to receive(:on_windows?).and_return(true)
|
170
|
+
expect(File).to receive(:exist?).with(valid_path_a).and_return(true)
|
171
|
+
expect(File).to receive(:directory?).with(valid_path_a).and_return(true)
|
172
|
+
expect(File).to receive(:exist?).with(non_existent_dir).and_return(false)
|
173
|
+
expect(described_class.invalid_directories?("#{valid_path_a};#{non_existent_dir}")).to be false
|
174
|
+
end
|
140
175
|
end
|
141
176
|
|
142
177
|
describe '.snake_case' do
|
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.
|
4
|
+
version: 1.2.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: 2024-
|
11
|
+
date: 2024-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: PowerShell code manager for ruby.
|
14
14
|
email:
|