Skip to content

Commit 121ed91

Browse files
(PUP-11767) Enable Style/FetchEnvVar
1 parent 8988a6c commit 121ed91

File tree

18 files changed

+41
-39
lines changed

18 files changed

+41
-39
lines changed

.rubocop.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,6 @@ Style/EvenOdd:
268268

269269
Style/ExpandPathArguments:
270270
Enabled: true
271+
272+
Style/FetchEnvVar:
273+
Enabled: true

ext/windows/service/daemon.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class WindowsDaemon < Puppet::Util::Windows::Daemon
1818
@run_thread = nil
1919
@LOG_TO_FILE = false
2020
@loglevel = 0
21-
LOG_FILE = File.expand_path(File.join(ENV['ALLUSERSPROFILE'], 'PuppetLabs', 'puppet', 'var', 'log', 'windows.log'))
21+
LOG_FILE = File.expand_path(File.join(ENV.fetch('ALLUSERSPROFILE', nil), 'PuppetLabs', 'puppet', 'var', 'log', 'windows.log'))
2222
LEVELS = [:debug, :info, :notice, :warning, :err, :alert, :emerg, :crit]
2323
LEVELS.each do |level|
2424
define_method("log_#{level}") do |msg|
@@ -203,10 +203,10 @@ def load_env(base_dir)
203203
ENV['Path'] = [
204204
File.join(base_dir, 'puppet', 'bin'),
205205
File.join(base_dir, 'bin'),
206-
].join(';').tr('/', '\\') + ';' + ENV['Path']
206+
].join(';').tr('/', '\\') + ';' + ENV.fetch('Path', nil)
207207

208208
# ENV that uses forward slashes
209-
ENV['RUBYLIB'] = "#{File.join(base_dir, 'puppet', 'lib')};#{ENV['RUBYLIB']}"
209+
ENV['RUBYLIB'] = "#{File.join(base_dir, 'puppet', 'lib')};#{ENV.fetch('RUBYLIB', nil)}"
210210
rescue => e
211211
log_exception(e)
212212
end

lib/puppet/application/resource.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def handle_editing(text)
188188
tmpfile.puts text
189189

190190
# edit the content
191-
system(ENV["EDITOR"] || 'vi', tmpfile.path)
191+
system(ENV.fetch("EDITOR", nil) || 'vi', tmpfile.path)
192192

193193
# ...and, now, pass that file to puppet to apply. Because
194194
# many editors rename or replace the original file we need to

lib/puppet/defaults.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def self.default_cadir
4949
def self.default_basemodulepath
5050
if Puppet::Util::Platform.windows?
5151
path = ['$codedir/modules']
52-
installdir = ENV["FACTER_env_windows_installdir"]
52+
installdir = ENV.fetch("FACTER_env_windows_installdir", nil)
5353
if installdir
5454
path << "#{installdir}/puppet/modules"
5555
end
@@ -61,7 +61,7 @@ def self.default_basemodulepath
6161

6262
def self.default_vendormoduledir
6363
if Puppet::Util::Platform.windows?
64-
installdir = ENV["FACTER_env_windows_installdir"]
64+
installdir = ENV.fetch("FACTER_env_windows_installdir", nil)
6565
if installdir
6666
"#{installdir}\\puppet\\vendor_modules"
6767
else
@@ -373,7 +373,7 @@ def self.initialize_default_settings!(settings)
373373
Puppet::Util::Platform.default_paths.each do |path|
374374
next if paths.include?(path)
375375

376-
ENV['PATH'] = ENV['PATH'] + File::PATH_SEPARATOR + path
376+
ENV['PATH'] = ENV.fetch('PATH', nil) + File::PATH_SEPARATOR + path
377377
end
378378
value
379379
end

lib/puppet/file_system/uniquefile.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def try_convert_to_hash(h)
153153

154154
def tmpdir
155155
tmp = '.'
156-
for dir in [ENV['TMPDIR'], ENV['TMP'], ENV['TEMP'], @@systmpdir, '/tmp']
156+
for dir in [ENV.fetch('TMPDIR', nil), ENV.fetch('TMP', nil), ENV.fetch('TEMP', nil), @@systmpdir, '/tmp']
157157
stat = File.stat(dir) if dir
158158
if stat && stat.directory? && stat.writable?
159159
tmp = dir

lib/puppet/http/proxy.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def self.proxy(uri)
1818

1919
def self.http_proxy_env
2020
# Returns a URI object if proxy is set, or nil
21-
proxy_env = ENV["http_proxy"] || ENV["HTTP_PROXY"]
21+
proxy_env = ENV.fetch("http_proxy", nil) || ENV.fetch("HTTP_PROXY", nil)
2222
begin
2323
return URI.parse(proxy_env) if proxy_env
2424
rescue URI::InvalidURIError
@@ -124,7 +124,7 @@ def self.http_proxy_password
124124
end
125125

126126
def self.no_proxy
127-
no_proxy_env = ENV["no_proxy"] || ENV["NO_PROXY"]
127+
no_proxy_env = ENV.fetch("no_proxy", nil) || ENV.fetch("NO_PROXY", nil)
128128

129129
if no_proxy_env
130130
return no_proxy_env

lib/puppet/node/environment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ def hash
554554
# not private so it can be called in tests
555555
def self.extralibs
556556
if ENV['PUPPETLIB']
557-
split_path(ENV['PUPPETLIB'])
557+
split_path(ENV.fetch('PUPPETLIB', nil))
558558
else
559559
[]
560560
end

lib/puppet/provider/package/gem.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def self.execute_gem_command(command, command_options, custom_environment = {})
7777
validate_command(command)
7878
cmd = [command] << command_options
7979

80-
custom_environment = { 'HOME' => ENV['HOME'] }.merge(custom_environment)
80+
custom_environment = { 'HOME' => ENV.fetch('HOME', nil) }.merge(custom_environment)
8181

8282
if Puppet::Util::Platform.windows?
8383
custom_environment[:PATH] = windows_path_without_puppet_bin

lib/puppet/provider/package/pkgutil.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
confine 'os.family' => :solaris
1313

1414
has_command(:pkguti, pkgutil_bin) do
15-
environment :HOME => ENV['HOME']
15+
environment :HOME => ENV.fetch('HOME', nil)
1616
end
1717

1818
def self.healthcheck

lib/puppet/provider/package/puppet_gem.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
confine :true => Puppet.runtime[:facter].value(:aio_agent_version)
1010

1111
def self.windows_gemcmd
12-
puppet_dir = ENV['PUPPET_DIR']
12+
puppet_dir = ENV.fetch('PUPPET_DIR', nil)
1313
if puppet_dir
14-
File.join(ENV['PUPPET_DIR'].to_s, 'bin', 'gem.bat')
14+
File.join(puppet_dir.to_s, 'bin', 'gem.bat')
1515
else
1616
File.join(Gem.default_bindir, 'gem.bat')
1717
end

0 commit comments

Comments
 (0)