-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup the environment before submitting jobs (#3628)
* sanitize the job environment * sanitize bc jobs * climate_control not only dev/test gem now * should not have added pry
- Loading branch information
Showing
5 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
# Sanitize an environment by returning a new Hash that can | ||
# be used with ClimateControl to submit jobs with that new | ||
# environment. | ||
module SanitizedEnv | ||
PREFIXES = [ | ||
'SECRET', 'PASSENGER', 'BUNDLE', | ||
'RACK', 'HTTP', 'NODE', 'RAILS', 'RUBY', | ||
'GEM', 'NGINX' | ||
].freeze | ||
|
||
def sanitized_env | ||
# these are all one offs that we should clear so they don't conflict | ||
# with the job. | ||
{ | ||
'LD_LIBRARY_PATH' => nil, | ||
'MANPATH' => nil, | ||
'PYTHONUNBUFFERED' => nil, | ||
'X_SCLS' => nil, | ||
'WSGI_ENV' => nil, | ||
'ALLOWED_HOSTS' => nil, | ||
'IN_PASSENGER' => nil, | ||
'SERVER_SOFTWARE' => nil, | ||
'PKG_CONFIG_PATH' => nil | ||
}.merge(sanitize_env(Regexp.new(PREFIXES.join('|')))) | ||
end | ||
|
||
def sanitize_env(prefix) | ||
ENV.select do |key, _value| | ||
key.start_with?(prefix) | ||
end.map do |key, _value| | ||
[key, nil] | ||
end.to_h | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
# Sanitize an environment by returning a new Hash that can | ||
# be used with ClimateControl to submit jobs with that new | ||
# environment. | ||
module SanitizedEnv | ||
PREFIXES = [ | ||
'SECRET', 'PASSENGER', 'BUNDLE', | ||
'RACK', 'HTTP', 'NODE', 'RAILS', 'RUBY', | ||
'GEM', 'NGINX' | ||
].freeze | ||
|
||
def sanitized_env | ||
# these are all one offs that we should clear so they don't conflict | ||
# with the job. | ||
{ | ||
'LD_LIBRARY_PATH' => nil, | ||
'MANPATH' => nil, | ||
'PYTHONUNBUFFERED' => nil, | ||
'X_SCLS' => nil, | ||
'WSGI_ENV' => nil, | ||
'ALLOWED_HOSTS' => nil, | ||
'IN_PASSENGER' => nil, | ||
'SERVER_SOFTWARE' => nil, | ||
'PKG_CONFIG_PATH' => nil | ||
}.merge(sanitize_env(Regexp.new(PREFIXES.join('|')))) | ||
end | ||
|
||
def sanitize_env(prefix) | ||
ENV.select do |key, _value| | ||
key.start_with?(prefix) | ||
end.map do |key, _value| | ||
[key, nil] | ||
end.to_h | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters