anyway_config 2.6.4 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7cfb06bc950fa9f4c16b771509fc8e88cbe1481ea82a145c2fae80fca80b57b
4
- data.tar.gz: fdbd419a8ff57a7fbbb4e887381048e68d830d4927761ec420706e8add146e3a
3
+ metadata.gz: c6e808e00b7756aa1b22f20792dfcfbc5989c5f41a88ae5b16e87ee3e556b17d
4
+ data.tar.gz: ef819a44f7ac000f206929dbb412f778130bb40b240c45478e548c582a7b52f9
5
5
  SHA512:
6
- metadata.gz: b7dd1abbf6411c416571ac67c127b0f0e365c73689d96d094289ab0ede4c494bd56f4246848431a689b2292a2903cea74b918e11569d89423c21e11f2dc3e9ca
7
- data.tar.gz: 4d8f2aecbbe6e79314a81d47f4fb92b3dcaba42a656387fbb24dd7c0dc051f3cae0b98de84f797cb48bc3fb9055bf59fd32c128ad4ee979e60eb3a71935a5e5a
6
+ metadata.gz: ca3f7f4ad799af0c53b613786a5407fa4d41a937528b12d17b69f466f3a7152a3b89e61cbcd4112f9bfd69b26089d3223eb85ba68859f9173997636ff04626a6
7
+ data.tar.gz: '00762802a9a92438cfd3ef29681eebaad657a81ddda44a06799c39c4f024d3975458b3380b8ef7b97611d9d561476a7fab386aa636aaa0a6712491790a583919'
data/CHANGELOG.md CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 2.7.1 (2025-02-24)
6
+
7
+ - Suppress required validations when running Rails credentials commands. ([@palkan][])
8
+
9
+ ## 2.7.0 (2025-02-12)
10
+
11
+ - Added `suppress_required_validations` configuration for skipping validation in CI. ([@OlegChuev][])
12
+
13
+ - 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. ([@OlegChuev][])
14
+
15
+ - Introduced a global setting `Anyway::Settings.suppress_required_validations = true` to disable validations. This can be toggled via the environment variable `ANYWAY_SUPPRESS_VALIDATIONS`. Please note, `ANYWAY_SUPPRESS_VALIDATIONS` takes precedence over `SECRET_KEY_BASE_DUMMY`.
16
+
17
+ - Added `:integer!` type support (strong integer coercion). ([@klondaiker][])
18
+
19
+ - Fix handling relative vs. absolute paths in `autoload_static_configs_path=`. ([@palkan][])
20
+
21
+ - Fix support for array values in `except` option for required attributes. ([@dominikb][])
22
+
5
23
  ## 2.6.4 (2024-04-30)
6
24
 
7
25
  - Fix RBS manifest file name (`.yml` -> `.yaml`). ([@carlqt][])
@@ -579,3 +597,6 @@ No we're dependency-free!
579
597
  [@tagirahmad]: https://github.com/tagirahmad
580
598
  [@bessey]: https://github.com/bessey
581
599
  [@carlqt]: https://github.com/carlqt
600
+ [@OlegChuev]: https://github.com/OlegChuev
601
+ [@dominikb]: https://github.com/dominikb
602
+ [@klondaiker]: https://github.com/klondaiker
data/README.md CHANGED
@@ -73,7 +73,7 @@ end
73
73
 
74
74
  Using Ruby classes to represent configuration allows you to add helper methods and computed parameters easily, makes the configuration **testable**.
75
75
 
76
- The `anyway_config` gem takes care of loading parameters from **different sources** (YAML, credentials/secrets, environment variables, etc.). Internally, we use a _pipeline pattern_ and provide the [Loaders API](#data-loaders) to manage and [extend](#custom-loaders) its functionality.
76
+ The `anyway_config` gem takes care of loading parameters from **different sources** (YAML, credentials, environment variables, etc.). Internally, we use a _pipeline pattern_ and provide the [Loaders API](#data-loaders) to manage and [extend](#custom-loaders) its functionality.
77
77
 
78
78
  Check out the libraries using Anyway Config for more examples:
79
79
 
@@ -270,7 +270,6 @@ This feature is similar to `Rails.application.config_for` but more powerful:
270
270
  | Feature | Rails | Anyway Config |
271
271
  | ------------- |-------------:| -----:|
272
272
  | Load data from `config/app.yml` | ✅ | ✅ |
273
- | Load data from `secrets` | ❌ | ✅ |
274
273
  | Load data from `credentials` | ❌ | ✅ |
275
274
  | Load data from environment | ❌ | ✅ |
276
275
  | Load data from [other sources](#data-loaders) | ❌ | ✅ |
@@ -304,6 +303,9 @@ MyConfig.new(api_secret: "") #=> raises Anyway::Config::ValidationError
304
303
  `Required` method supports additional `env` parameter which indicates necessity to run validations under specified
305
304
  environments. `Env` parameter could be present in symbol, string, array or hash formats:
306
305
 
306
+ **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`.
307
+ If you are using Anyway Config with Rails and have already specified `SECRET_KEY_BASE_DUMMY` for asset pre compilation, validation will be skipped by default.
308
+
307
309
  ```ruby
308
310
  class EnvConfig < Anyway::Config
309
311
  required :password, env: "production"
@@ -712,7 +714,7 @@ CoolConfig.new.port == "443" #=> true
712
714
 
713
715
  **IMPORTANT**: Values provided explicitly (via attribute writers) are not coerced. Coercion is only happening during the load phase.
714
716
 
715
- The following types are supported out-of-the-box: `:string`, `:integer`, `:float`, `:date`, `:datetime`, `:uri`, `:boolean`.
717
+ The following types are supported out-of-the-box: `:string`, `:integer`, `:integer!` (strict integer), `:float`, `:date`, `:datetime`, `:uri`, `:boolean`.
716
718
 
717
719
  You can use custom deserializers by passing a callable object instead of a type name:
718
720
 
@@ -445,6 +445,8 @@ module Anyway # :nodoc:
445
445
  attr_reader :values, :__trace__
446
446
 
447
447
  def validate_required_attributes!
448
+ return if Settings.suppress_required_validations
449
+
448
450
  self.class.required_attributes.select do |name|
449
451
  val = values.dig(*name.to_s.split(".").map(&:to_sym))
450
452
  val.nil? || (val.is_a?(String) && val.empty?)
@@ -52,6 +52,9 @@ module Anyway
52
52
  :default_environmental_key,
53
53
  :known_environments
54
54
 
55
+ # Suppress required validations for CI/CD pipelines
56
+ attr_accessor :suppress_required_validations
57
+
55
58
  # A proc returning a path to YML config file given the config name
56
59
  attr_reader :default_config_path
57
60
 
@@ -86,7 +89,7 @@ module Anyway
86
89
 
87
90
  if env.is_a?(::Hash)
88
91
  envs = env[:except]
89
- excluded_envs = [envs].flat_map(&:to_s)
92
+ excluded_envs = [*envs].flat_map(&:to_s)
90
93
  excluded_envs.none?(current_environment)
91
94
  elsif env.is_a?(::Array)
92
95
  env.flat_map(&:to_s).include?(current_environment)
@@ -107,5 +110,8 @@ module Anyway
107
110
 
108
111
  # Tracing is enabled by default
109
112
  self.tracing_enabled = true
113
+
114
+ # By default, use ANYWAY_SUPPRESS_VALIDATIONS
115
+ self.suppress_required_validations = %w[1 t true y yes].include?(ENV["ANYWAY_SUPPRESS_VALIDATIONS"])
110
116
  end
111
117
  end
@@ -88,6 +88,10 @@ module Anyway
88
88
  obj.accept(:boolean) do |_1|
89
89
  _1.to_s.match?(/\A(true|t|yes|y|1)\z/i)
90
90
  end
91
+
92
+ obj.accept(:integer!) do |_1|
93
+ Integer(_1)
94
+ end
91
95
  end
92
96
 
93
97
  unless "".respond_to?(:safe_constantize)
@@ -445,6 +445,8 @@ module Anyway # :nodoc:
445
445
  attr_reader :values, :__trace__
446
446
 
447
447
  def validate_required_attributes!
448
+ return if Settings.suppress_required_validations
449
+
448
450
  self.class.required_attributes.select do |name|
449
451
  val = values.dig(*name.to_s.split(".").map(&:to_sym))
450
452
  val.nil? || (val.is_a?(String) && val.empty?)
@@ -445,6 +445,8 @@ module Anyway # :nodoc:
445
445
  attr_reader :values, :__trace__
446
446
 
447
447
  def validate_required_attributes!
448
+ return if Settings.suppress_required_validations
449
+
448
450
  self.class.required_attributes.select do |name|
449
451
  val = values.dig(*name.to_s.split(".").map(&:to_sym))
450
452
  val.nil? || (val.is_a?(String) && val.empty?)
@@ -445,6 +445,8 @@ module Anyway # :nodoc:
445
445
  attr_reader :values, :__trace__
446
446
 
447
447
  def validate_required_attributes!
448
+ return if Settings.suppress_required_validations
449
+
448
450
  self.class.required_attributes.select do |name|
449
451
  val = values.dig(*name.to_s.split(".").map(&:to_sym))
450
452
  val.nil? || (val.is_a?(String) && val.empty?)
@@ -445,6 +445,8 @@ module Anyway # :nodoc:
445
445
  attr_reader :values, :__trace__
446
446
 
447
447
  def validate_required_attributes!
448
+ return if Settings.suppress_required_validations
449
+
448
450
  self.class.required_attributes.select do |name|
449
451
  val = values.dig(*name.to_s.split(".").map(&:to_sym))
450
452
  val.nil? || (val.is_a?(String) && val.empty?)
@@ -88,6 +88,10 @@ module Anyway
88
88
  obj.accept(:boolean) do
89
89
  _1.to_s.match?(/\A(true|t|yes|y|1)\z/i)
90
90
  end
91
+
92
+ obj.accept(:integer!) do
93
+ Integer(_1)
94
+ end
91
95
  end
92
96
 
93
97
  unless "".respond_to?(:safe_constantize)
data/lib/anyway/config.rb CHANGED
@@ -445,6 +445,8 @@ module Anyway # :nodoc:
445
445
  attr_reader :values, :__trace__
446
446
 
447
447
  def validate_required_attributes!
448
+ return if Settings.suppress_required_validations
449
+
448
450
  self.class.required_attributes.select do |name|
449
451
  val = values.dig(*name.to_s.split(".").map(&:to_sym))
450
452
  val.nil? || (val.is_a?(String) && val.empty?)
@@ -19,7 +19,7 @@ module Anyway
19
19
 
20
20
  return unless ::Rails.root.join(val).exist?
21
21
 
22
- return if val == autoload_static_config_path
22
+ return if ::Rails.root.join(val.to_s) == ::Rails.root.join(autoload_static_config_path.to_s)
23
23
 
24
24
  autoloader&.unload
25
25
 
@@ -79,5 +79,16 @@ module Anyway
79
79
  self.use_local_files ||= ::Rails.env.development?
80
80
  # Don't try read defaults when no key defined
81
81
  self.default_environmental_key = nil
82
+
83
+ self.suppress_required_validations = ENV.key?("SECRET_KEY_BASE_DUMMY") unless ENV.key?("ANYWAY_SUPPRESS_VALIDATIONS")
84
+
85
+ # Suppress validations when working with credentials
86
+ if defined?(::Rails::Command::CredentialsCommand) && ::Rails::Command.respond_to?(:const_source_location)
87
+ credentials_source_path = ::Rails::Command.const_source_location("CredentialsCommand").first
88
+
89
+ if caller_locations.any? { |l| l.absolute_path == credentials_source_path }
90
+ self.suppress_required_validations = true
91
+ end
92
+ end
82
93
  end
83
94
  end
@@ -52,6 +52,9 @@ module Anyway
52
52
  :default_environmental_key,
53
53
  :known_environments
54
54
 
55
+ # Suppress required validations for CI/CD pipelines
56
+ attr_accessor :suppress_required_validations
57
+
55
58
  # A proc returning a path to YML config file given the config name
56
59
  attr_reader :default_config_path
57
60
 
@@ -86,7 +89,7 @@ module Anyway
86
89
 
87
90
  if env.is_a?(::Hash)
88
91
  envs = env[:except]
89
- excluded_envs = [envs].flat_map(&:to_s)
92
+ excluded_envs = [*envs].flat_map(&:to_s)
90
93
  excluded_envs.none?(current_environment)
91
94
  elsif env.is_a?(::Array)
92
95
  env.flat_map(&:to_s).include?(current_environment)
@@ -107,5 +110,8 @@ module Anyway
107
110
 
108
111
  # Tracing is enabled by default
109
112
  self.tracing_enabled = true
113
+
114
+ # By default, use ANYWAY_SUPPRESS_VALIDATIONS
115
+ self.suppress_required_validations = %w[1 t true y yes].include?(ENV["ANYWAY_SUPPRESS_VALIDATIONS"])
110
116
  end
111
117
  end
@@ -88,6 +88,10 @@ module Anyway
88
88
  obj.accept(:boolean) do
89
89
  _1.to_s.match?(/\A(true|t|yes|y|1)\z/i)
90
90
  end
91
+
92
+ obj.accept(:integer!) do
93
+ Integer(_1)
94
+ end
91
95
  end
92
96
 
93
97
  unless "".respond_to?(:safe_constantize)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anyway # :nodoc:
4
- VERSION = "2.6.4"
4
+ VERSION = "2.7.1"
5
5
  end
@@ -19,6 +19,13 @@ module Rails
19
19
 
20
20
  change_credentials_in_system_editor
21
21
  end
22
+
23
+ private
24
+
25
+ def load_environment_config!
26
+ ENV["ANYWAY_SUPPRESS_VALIDATIONS"] = "true"
27
+ super
28
+ end
22
29
  end
23
30
  end
24
31
  end
@@ -7,6 +7,7 @@ module Anyway
7
7
  def self.future: -> Future
8
8
  def self.current_environment: -> String?
9
9
  def self.default_environmental_key: -> String?
10
+ def self.suppress_required_validations: -> bool
10
11
  def self.known_environments: -> Array[String]?
11
12
 
12
13
  class Future
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anyway_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.4
4
+ version: 2.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-30 00:00:00.000000000 Z
11
+ date: 2025-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-next-core
@@ -206,7 +206,7 @@ metadata:
206
206
  homepage_uri: http://github.com/palkan/anyway_config
207
207
  source_code_uri: http://github.com/palkan/anyway_config
208
208
  funding_uri: https://github.com/sponsors/palkan
209
- post_install_message:
209
+ post_install_message:
210
210
  rdoc_options: []
211
211
  require_paths:
212
212
  - lib
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
222
  version: '0'
223
223
  requirements: []
224
224
  rubygems_version: 3.4.19
225
- signing_key:
225
+ signing_key:
226
226
  specification_version: 4
227
227
  summary: Configuration DSL for Ruby libraries and applications
228
228
  test_files: []