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

feature: added suppress_required_validations option #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

OlegChuev
Copy link

What is the purpose of this pull request?

Closes #151

What changes did you make? (overview)

Added suppress_required_validations configuration for skipping validation in CI:

  • Support for the Rails built-in environment variable SECRET_KEY_BASE_DUMMY. If this variable is set, all validations for required attributes are skipped. This is particularly useful for executing bundle exec rails assets:precompile in CI/CD pipelines.

  • Introduced a global setting Anyway::Settings.suppress_required_validations = true to disable validations. This can be toggled via the environment variable ANYWAY_SUPPRESS_VALIDATIONS.

  • For Rails applications, suppress_required_validations is automatically set to true if SECRET_KEY_BASE_DUMMY is defined.

Is there anything you'd like reviewers to focus on?

Checklist

  • I've added tests for this change
  • I've added a Changelog entry
  • I've updated a documentation

Copy link
Owner

@palkan palkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Left some comments/suggestions.

@@ -2,6 +2,15 @@

## master

## 2.6.5 (2024-05-30)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, do not update version numbers/dates; it's only done on release

- [Test helpers](#test-helpers)
- [OptionParser integration](#optionparser-integration)
- [RBS support](#rbs-support)
- [Anyway Config](#anyway-config)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is irrelevant and not needed; please, revert.

@@ -79,5 +79,7 @@ def app_root
self.use_local_files ||= ::Rails.env.development?
# Don't try read defaults when no key defined
self.default_environmental_key = nil

self.suppress_required_validations = ENV["SECRET_KEY_BASE_DUMMY"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway-specific env var must have precedence:

Suggested change
self.suppress_required_validations = ENV["SECRET_KEY_BASE_DUMMY"]
self.suppress_required_validations = !!ENV["SECRET_KEY_BASE_DUMMY"] unless ENV.key?("ANYWAY_SUPPRESS_VALIDATIONS")

@@ -107,5 +110,8 @@ def matching_env?(env)

# Tracing is enabled by default
self.tracing_enabled = true

# By default, use ANYWAY_SUPPRESS_VALIDATIONS
self.suppress_required_validations = ENV["ANYWAY_SUPPRESS_VALIDATIONS"]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's be more specific here:

Suggested change
self.suppress_required_validations = ENV["ANYWAY_SUPPRESS_VALIDATIONS"]
self.suppress_required_validations = %w[1 t true y yes].include?(ENV["ANYWAY_SUPPRESS_VALIDATIONS"])

@@ -7,6 +7,7 @@ module Anyway
def self.future: -> Future
def self.current_environment: -> String?
def self.default_environmental_key: -> String?
def self.suppress_required_validations: -> bool?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's either true or false

Suggested change
def self.suppress_required_validations: -> bool?
def self.suppress_required_validations: -> bool


context "with env" do
it "not to raise ValidationError" do
with_env("ANYWAY_SUPPRESS_VALIDATIONS" => "1") do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add another test case with the falsey value (e.g., "ANYWAY_SUPPRESS_VALIDATIONS=0").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support of SECRET_KEY_BASE_DUMMY env variable
2 participants