ENV: add sensitive_environment function
ENV#sensitive_environment is used to list all sensitive environments. Also refactor the code on determining whether an environment is sensitive.
This commit is contained in:
parent
9232ca4508
commit
66697d4290
@ -29,12 +29,16 @@ module EnvActivation
|
|||||||
replace(old_env)
|
replace(old_env)
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_sensitive_environment!
|
def sensitive?(key)
|
||||||
each_key do |key|
|
/(cookie|key|token|password)/i =~ key
|
||||||
next unless /(cookie|key|token|password)/i =~ key
|
end
|
||||||
|
|
||||||
delete key
|
def sensitive_environment
|
||||||
end
|
select { |key, _| sensitive?(key) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def clear_sensitive_environment!
|
||||||
|
each_key { |key| delete key if sensitive?(key) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ require "hardware"
|
|||||||
require "software_spec"
|
require "software_spec"
|
||||||
require "rexml/document"
|
require "rexml/document"
|
||||||
require "development_tools"
|
require "development_tools"
|
||||||
|
require "extend/ENV"
|
||||||
|
|
||||||
class SystemConfig
|
class SystemConfig
|
||||||
class << self
|
class << self
|
||||||
@ -173,7 +174,7 @@ class SystemConfig
|
|||||||
next if boring_keys.include?(key)
|
next if boring_keys.include?(key)
|
||||||
next if defaults_hash[key.to_sym]
|
next if defaults_hash[key.to_sym]
|
||||||
|
|
||||||
value = "set" if key =~ /(cookie|key|token|password)/i
|
value = "set" if ENV.sensitive?(key)
|
||||||
f.puts "#{key}: #{value}"
|
f.puts "#{key}: #{value}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -143,6 +143,13 @@ shared_examples EnvActivation do
|
|||||||
expect(subject["MAKEFLAGS"]).to eq("-j4")
|
expect(subject["MAKEFLAGS"]).to eq("-j4")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#sensitive_environment" do
|
||||||
|
it "list sensitive environment" do
|
||||||
|
subject["SECRET_TOKEN"] = "password"
|
||||||
|
expect(subject.sensitive_environment).to include("SECRET_TOKEN")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#clear_sensitive_environment!" do
|
describe "#clear_sensitive_environment!" do
|
||||||
it "removes sensitive environment variables" do
|
it "removes sensitive environment variables" do
|
||||||
subject["SECRET_TOKEN"] = "password"
|
subject["SECRET_TOKEN"] = "password"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user