Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of SECRET_KEY_BASE_DUMMY env variable #151

Open
OlegChuev opened this issue May 29, 2024 · 2 comments · May be fixed by #152
Open

Add support of SECRET_KEY_BASE_DUMMY env variable #151

OlegChuev opened this issue May 29, 2024 · 2 comments · May be fixed by #152
Assignees

Comments

@OlegChuev
Copy link

OlegChuev commented May 29, 2024

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
Copy link
Owner

palkan commented May 29, 2024

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 (or config.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 (and ANYWAY_SUPPRESS_VALIDATIONS is not).

@OlegChuev
Copy link
Author

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

@OlegChuev OlegChuev linked a pull request May 30, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants