Skip to content

Commit 6411ee3

Browse files
authored
Merge pull request #9 from KMI-Learning/fix_#8
Fix #8
2 parents ed91b29 + 457023a commit 6411ee3

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ Metrics/PerceivedComplexity:
2121
Max: 10
2222
Metrics/AbcSize:
2323
Max: 29
24+
Style/MethodMissing:
25+
Exclude:
26+
- 'libraries/process_env_var.rb'

controls/1_4_master_node_configuration_files.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
throw :stop
211211
end
212212

213-
if (data_dir = file("/proc/#{etcd_process.pids.first}/environ").content.split("\0").select { |i| i[/^ETCD_DATA_DIR/] }.first.split('=').last)
213+
if (data_dir = file("/proc/#{etcd_process.pids.first}/environ").content.split("\0").select { |i| i[/^ETCD_DATA_DIR/] }.first.to_s.split('=', 2).last.to_s)
214214
throw :stop
215215
end
216216
end
@@ -245,7 +245,7 @@
245245
throw :stop
246246
end
247247

248-
if (data_dir = file("/proc/#{etcd_process.pids.first}/environ").content.split("\0").select { |i| i[/^ETCD_DATA_DIR/] }.first.split('=').last)
248+
if (data_dir = file("/proc/#{etcd_process.pids.first}/environ").content.split("\0").select { |i| i[/^ETCD_DATA_DIR/] }.first.to_s.split('=', 2).last.to_s)
249249
throw :stop
250250
end
251251
end

libraries/process_env_var.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ def initialize(process)
2929
end
3030

3131
def method_missing(name)
32-
read_params[name.to_s]
32+
read_params[name.to_s] || ''
3333
end
3434

3535
def read_params
3636
return @params if defined?(@params)
3737

38-
proc_environ = inspec.file("/proc/#{@process.pids.first}/environ")
39-
unless file.file?
38+
@file = inspec.file("/proc/#{@process.pids.first}/environ")
39+
unless @file.file?
4040
skip_resource "Can't find environ file for #{@process}"
4141
return @params = {}
4242
end
4343

44-
environ_content = proc_environ.content
45-
if content.empty? && !file.empty?
44+
@content = @file.content
45+
if @content.empty? && !@file.empty?
4646
skip_resource "Can't read environ file for #{@process}"
4747
return @params = {}
4848
end
4949

50-
@params = environ_content.split("\0").map { |i| i.split('=') }.to_h
50+
@params = @content.split("\0").map { |i| i.split('=', 2) }.to_h
5151
end
5252

5353
def to_s

0 commit comments

Comments
 (0)