ruby-pwsh 1.2.0 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb +2 -2
- 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: df8360a152766169ee39b1a3e79909f5e75f1645194f22996eb09246c58d8a79
|
4
|
+
data.tar.gz: 9733619df523ed7c6d1af948fe2a75e35d24ac7b723cd610945a3c617c367685
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7e6afecbbe06c0a78509458e7e178295d57de9d5901b6a448c177a5be4f2ec1361015de97daf8db022a20dcddda3f50ea0dc326234fea71e068809c06c50f02
|
7
|
+
data.tar.gz: 964652929914f2aeb579835dec656d56cc8005218b64075daed3bad684a972c45079f00586a0df4f803a9c369431364163c9515542bc0be4ee58cfb07223f269
|
data/README.md
CHANGED
@@ -683,7 +683,7 @@ class Puppet::Provider::DscBaseProvider # rubocop:disable Metrics/ClassLength
|
|
683
683
|
end
|
684
684
|
|
685
685
|
# Parses the DSC resource type definition to retrieve the names of any attributes which are specified as required strings
|
686
|
-
# This is used to ensure that any nil values are converted to empty strings to match puppets
|
686
|
+
# This is used to ensure that any nil values are converted to empty strings to match puppets expeceted 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
|
@@ -691,7 +691,7 @@ class Puppet::Provider::DscBaseProvider # rubocop:disable Metrics/ClassLength
|
|
691
691
|
nil_attributes = data.select { |_name, value| value.nil? }.keys
|
692
692
|
nil_attributes.each do |nil_attr|
|
693
693
|
attribute_type = context.type.attributes[nil_attr][:type]
|
694
|
-
data[nil_attr] = '' if (attribute_type.
|
694
|
+
data[nil_attr] = '' if (attribute_type.start_with?('Optional[Enum[', 'Enum[') && enum_values(context, nil_attr).include?('')) || attribute_type == 'String'
|
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.2
|
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-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: PowerShell code manager for ruby.
|
14
14
|
email:
|