palkan / anyway_config

Configuration library for Ruby gems and applications
MIT License
778 stars 52 forks source link

Add support of SECRET_KEY_BASE_DUMMY env variable #151

Open OlegChuev opened 5 months ago

OlegChuev commented 5 months ago

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

-

palkan commented 5 months ago

Yeah, makes sense.

The way we should do that is as follows:

OlegChuev commented 5 months ago

@palkan I could start working on this feature if you don't mind