Add support of SECRET_KEY_BASE_DUMMY env variable
Opened this issue · 2 comments
Is your feature request related to a problem? Please describe.
The main idea is to add support for the Rails built-in environment variable SECRET_KEY_BASE_DUMMY
. If a user has added this variable, we skip any kind of validations for required attributes. This could be useful for executing bundle exec rails assets:precompile
in CI/CD pipelines.
Describe the solution you'd like
As far as I can see (I'm not very familiar with the gem's codebase), we could add an additional condition to the validate_required_attributes
method:
def validate_required_attributes!
self.class.required_attributes.select do |name|
val = values.dig(*name.to_s.split(".").map(&:to_sym))
val.nil? || (val.is_a?(String) && val.empty?)
end.then do |missing|
next if missing.empty? || ENV['SECRET_KEY_BASE_DUMMY'].present? <- Add validation here
raise_validation_error "The following config parameters for `#{self.class.name}(config_name: #{self.class.config_name})` are missing or empty: #{missing.join(", ")}"
end
end
Describe alternatives you've considered
Additional context
Yeah, makes sense.
The way we should do that is as follows:
-
Add a global setting to disable validations, smth like:
Anyway::Settings.suppress_required_validations = true
(orconfig.anyway_config.suppress_required_validations = true
) -
Use some custom env var to toggle this setting, e.g.,
ANYWAY_SUPPRESS_VALIDATIONS=true
-
For Rails apps, set this parameter to true if the
SECRET_KEY_BASE_DUMMY
is defined (andANYWAY_SUPPRESS_VALIDATIONS
is not).