-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,29 +31,43 @@ For version 1.x see the [1-4-stable branch](https://github.com/palkan/anyway_con | |
|
||
## Table of contents | ||
|
||
- [Main concepts](#main-concepts) | ||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [Configuration classes](#configuration-classes) | ||
- [Dynamic configuration](#dynamic-configuration) | ||
- [Validation & Callbacks](#validation-and-callbacks) | ||
- [Using with Rails applications](#using-with-rails) | ||
- [Data population](#data-population) | ||
- [Organizing configs](#organizing-configs) | ||
- [Generators](#generators) | ||
- [Using with Ruby applications](#using-with-ruby) | ||
- [Environment variables](#environment-variables) | ||
- [Type coercion](#type-coercion) | ||
- [Local configuration](#local-files) | ||
- [Data loaders](#data-loaders) | ||
- [Doppler integration](#doppler-integration) | ||
- [EJSON support](#ejson-support) | ||
- [Custom loaders](#custom-loaders) | ||
- [Source tracing](#tracing) | ||
- [Pattern matching](#pattern-matching) | ||
- [Test helpers](#test-helpers) | ||
- [OptionParser integration](#optionparser-integration) | ||
- [RBS support](#rbs-support) | ||
- [Anyway Config](#anyway-config) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is irrelevant and not needed; please, revert. |
||
- [Links](#links) | ||
- [Table of contents](#table-of-contents) | ||
- [Main concepts](#main-concepts) | ||
- [Installation](#installation) | ||
- [Supported Ruby versions](#supported-ruby-versions) | ||
- [Usage](#usage) | ||
- [Configuration classes](#configuration-classes) | ||
- [Config name](#config-name) | ||
- [Customize env variable names prefix](#customize-env-variable-names-prefix) | ||
- [Explicit values](#explicit-values) | ||
- [Reload configuration](#reload-configuration) | ||
- [Dynamic configuration](#dynamic-configuration) | ||
- [Validation and callbacks](#validation-and-callbacks) | ||
- [Using with Rails](#using-with-rails) | ||
- [Data population](#data-population) | ||
- [Multi-env configuration](#multi-env-configuration) | ||
- [Organizing configs](#organizing-configs) | ||
- [Generators](#generators) | ||
- [Loading Anyway Config before Rails](#loading-anyway-config-before-rails) | ||
- [Using with Ruby](#using-with-ruby) | ||
- [Environment variables](#environment-variables) | ||
- [Type coercion](#type-coercion) | ||
- [Local files](#local-files) | ||
- [Data loaders](#data-loaders) | ||
- [Doppler integration](#doppler-integration) | ||
- [EJSON support](#ejson-support) | ||
- [Custom loaders](#custom-loaders) | ||
- [Tracing](#tracing) | ||
- [Pretty print](#pretty-print) | ||
- [Pattern matching](#pattern-matching) | ||
- [Test helpers](#test-helpers) | ||
- [OptionParser integration](#optionparser-integration) | ||
- [RBS support](#rbs-support) | ||
- [Handling `on_load`](#handling-on_load) | ||
- [Contributing](#contributing) | ||
- [License](#license) | ||
|
||
## Main concepts | ||
|
||
|
@@ -304,6 +318,9 @@ MyConfig.new(api_secret: "") #=> raises Anyway::Config::ValidationError | |
`Required` method supports additional `env` parameter which indicates necessity to run validations under specified | ||
environments. `Env` parameter could be present in symbol, string, array or hash formats: | ||
|
||
**NOTE:** You can suppress the validation of the required parameters (it can be useful for CI) via the `ANYWAY_SUPPRESS_VALIDATIONS` environment variable or by setting it explicitly in the code: `Anyway::Settings.suppress_required_validations = true`. | ||
If you are using Anyway Config with Rails and have already specified `SECRET_KEY_BASE_DUMMY` for asset precompilation, validation will be skipped by default. | ||
|
||
```ruby | ||
class EnvConfig < Anyway::Config | ||
required :password, env: "production" | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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"] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anyway-specific env var must have precedence:
Suggested change
|
||||||
end | ||||||
end |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -52,6 +52,9 @@ class << self | |||||
:default_environmental_key, | ||||||
:known_environments | ||||||
|
||||||
# Suppress required validations for CI/CD pipelines | ||||||
attr_accessor :suppress_required_validations | ||||||
|
||||||
# A proc returning a path to YML config file given the config name | ||||||
attr_reader :default_config_path | ||||||
|
||||||
|
@@ -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"] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's be more specific here:
Suggested change
|
||||||
end | ||||||
end |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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? | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's either true or false
Suggested change
|
||||||
def self.known_environments: -> Array[String]? | ||||||
|
||||||
class Future | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -934,6 +934,26 @@ def self.name | |
.to raise_error(ArgumentError, /unknown config param: test/i) | ||
end | ||
|
||
context "suppress validation" do | ||
let(:config_values) { {} } | ||
|
||
context "with setting" do | ||
before { allow(Anyway::Settings).to receive(:suppress_required_validations).and_return(true) } | ||
|
||
it "not to raise ValidationError" do | ||
expect { subject }.to_not raise_error | ||
end | ||
end | ||
|
||
context "with env" do | ||
it "not to raise ValidationError" do | ||
with_env("ANYWAY_SUPPRESS_VALIDATIONS" => "1") do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"). |
||
expect { subject }.to_not raise_error | ||
end | ||
end | ||
end | ||
end | ||
|
||
specify "inheritance" do | ||
subconfig = Class.new(config) { required :debug } | ||
|
||
|
There was a problem hiding this comment.
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