config-rails 0.1.0 → 0.1.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: 3f400091fc360f391ce5812d4a7e37df84c878059d05a8758c73789a03326777
4
- data.tar.gz: 9be7545904371f43c70f51ee52afdd2cf9632bf05a87b2acf2b29d970a383e37
3
+ metadata.gz: d6473cf468cc40d76adf8e1c6cc85b99e02910c95535b0658a60b3735cce0bce
4
+ data.tar.gz: a29fc298589802c2bf7cd387dc5fe054c8dc3b8c3d576888045165babb0cb18f
5
5
  SHA512:
6
- metadata.gz: 4327e4b039a12b664533990afe7807f95392c4db7f457ce9708f88ca606ec8440bd8343fce4c40f04ac74e2d50f75efc1d01fb21e9915acb13599827f21e0953
7
- data.tar.gz: 0fd07b41244b144c5a7a82b3edd196542213828a7a177d4e893aa27bc77d5cc83ec9d4a084f9d50bbe510836bbda07f7e0fe44df45a3dc136dd6d81db52f8c93
6
+ metadata.gz: aba7f1c614bcf77ac6969c308dcae764e6f19615ed681ebb35244b3defad51150ae95abe566ec8d7d83021e0c4a0ab49ab6692a6ccf558afc565e2ace69f5527
7
+ data.tar.gz: fb9d69ceb67fea5faa6855268416372442ac0bb447868291e6755cf19ed860b77875b3d3fa9ad26c6fa394c9223f630c1a1701792f080e1908393575210eb9d6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
- ## 0.1.0
3
+ ## 0.1.1 (2026-12-03)
4
4
 
5
- - Initial release: merge `Rails.application.credentials` into the config gem's `Settings`.
5
+ - Keep credentials out of `rake config:heroku`, which exports only `*.local.yml` settings.
6
+
7
+ ## 0.1.0 (2026-12-03)
8
+
9
+ - Initial release.
data/README.md CHANGED
@@ -1,34 +1,25 @@
1
1
  # config-rails
2
2
 
3
- Adds Rails encrypted credentials to the [config](https://github.com/rubyconfig/config) gem's `Settings`
4
- ([rubyconfig/config#68](https://github.com/rubyconfig/config/issues/68)).
3
+ [![Gem Version](https://badge.fury.io/rb/config-rails.svg)](https://badge.fury.io/rb/config-rails)
4
+ [![CI](https://github.com/deepakmahakale/config-rails/actions/workflows/ci.yml/badge.svg)](https://github.com/deepakmahakale/config-rails/actions/workflows/ci.yml)
5
5
 
6
- Keep using `Settings.x.y`. Values come from your settings YAML files as before, plus `Rails.application.credentials`.
6
+ Rails encrypted credentials support for the [config](https://github.com/rubyconfig/config) gem.
7
+
8
+ `Settings` is loaded from your YAML files as usual, with `Rails.application.credentials` merged on top.
9
+ See [rubyconfig/config#68](https://github.com/rubyconfig/config/issues/68).
7
10
 
8
11
  ## Installation
9
12
 
13
+ Add the gem alongside `config`:
14
+
10
15
  ```ruby
11
16
  gem "config"
12
17
  gem "config-rails"
13
18
  ```
14
19
 
15
- There is nothing else to set up.
16
-
17
- ## Precedence
18
-
19
- Later sources win, deep-merged:
20
+ ## Usage
20
21
 
21
- ```
22
- config/settings.yml
23
- config/settings/<env>.yml
24
- config/environments/<env>.yml
25
- *.local.yml
26
- Config.extra_sources
27
- Rails credentials <- added by this gem
28
- ENV (when Config.use_env)
29
- ```
30
-
31
- So you can keep defaults in YAML and put only the secrets in credentials:
22
+ Keep defaults in YAML and secrets in credentials:
32
23
 
33
24
  ```yaml
34
25
  # config/settings.yml
@@ -40,20 +31,32 @@ stripe:
40
31
  ```yaml
41
32
  # bin/rails credentials:edit
42
33
  stripe:
43
- secret_key: sk_live_...
34
+ secret_key: sk_live_123
44
35
  ```
45
36
 
46
37
  ```ruby
47
38
  Settings.stripe.api_base # => "https://api.stripe.com"
48
- Settings.stripe.secret_key # => "sk_live_..."
39
+ Settings.stripe.secret_key # => "sk_live_123"
49
40
  ```
50
41
 
51
- Credentials are read the same way Rails reads them. This covers per-environment files
52
- (`config/credentials/<env>.yml.enc`), `RAILS_MASTER_KEY`, `config.credentials.content_path` / `key_path`,
53
- and `config.require_master_key`. If no key is available, `Settings` holds only the YAML values, unless
54
- `require_master_key` is set, in which case it raises.
42
+ Sources are deep-merged in the following order, later ones taking precedence:
43
+
44
+ 1. `config/settings.yml`
45
+ 2. `config/settings/<env>.yml`, `config/environments/<env>.yml`
46
+ 3. `*.local.yml`
47
+ 4. `Config.extra_sources`
48
+ 5. Rails credentials
49
+ 6. `ENV`, when `Config.use_env` is enabled
55
50
 
56
- ## Disabling
51
+ Credentials are resolved the same way Rails resolves them, including per-environment files,
52
+ `RAILS_MASTER_KEY`, custom `config.credentials` paths and `config.require_master_key`.
53
+ If no key is available, credentials are skipped, unless `require_master_key` is set, in which case boot fails.
54
+
55
+ `Settings.reload!` re-reads the credentials, as does the per-request reload in development.
56
+
57
+ ## Configuration
58
+
59
+ To disable credentials loading:
57
60
 
58
61
  ```ruby
59
62
  # config/initializers/config.rb
@@ -62,30 +65,30 @@ Config.setup do |config|
62
65
  end
63
66
  ```
64
67
 
65
- ## How it works
68
+ ## Caveats
66
69
 
67
- This gem is a small patch on top of `config`:
70
+ `Settings` is first built before `config/application.rb` runs, and rebuilt once the application and environment
71
+ configuration have loaded. Code in `config/application.rb` that reads `Settings` therefore sees credentials from
72
+ the default location, not from a custom `config.credentials.content_path`.
68
73
 
69
- * `Config.load_and_set_settings` (which builds the `Settings` constant) gets an extra source,
70
- `Config::Sources::RailsCredentialsSource`. `Config.load_files` is left alone.
71
- * The source decrypts the credentials again on every load, so `Settings.reload!`, and the per-request
72
- reload in development, pick up edits.
73
- * It does **not** call `Rails.application.credentials`, because that method caches its result. `config` builds
74
- `Settings` before `config/application.rb` runs. Reading that method at that point would cache the credentials
75
- before your app could change their path, which is the "eager loads credentials" problem reported in #68.
76
- * `Settings` is rebuilt once in `before_initialize`, after `config/application.rb` and
77
- `config/environments/*.rb` have run, so settings made there (custom paths, `require_master_key`) are picked up.
74
+ ## Compatibility
78
75
 
79
- Caveat: if `config/application.rb` itself reads `Settings`, it sees the credentials from the default path,
80
- because your overrides have not run yet at that point.
76
+ Ruby 3.1+, Rails 7.1+, config 5.x.
81
77
 
82
78
  ## Development
83
79
 
84
- ```
80
+ ```sh
85
81
  bundle install
86
82
  bundle exec rake test
87
83
  ```
88
84
 
85
+ To test against a specific Rails version:
86
+
87
+ ```sh
88
+ BUNDLE_GEMFILE=gemfiles/rails_7_2.gemfile bundle install
89
+ BUNDLE_GEMFILE=gemfiles/rails_7_2.gemfile bundle exec rake test
90
+ ```
91
+
89
92
  ## License
90
93
 
91
- MIT
94
+ Released under the [MIT License](LICENSE.txt).
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Config
2
4
  module RailsCredentials
3
5
  class Railtie < ::Rails::Railtie
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Config
2
4
  module RailsCredentials
3
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
4
6
  end
5
7
  end
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "config"
4
+ require "config/integrations/heroku"
2
5
  require "config/rails_credentials/version"
3
6
  require "config/sources/rails_credentials_source"
4
7
 
@@ -7,9 +10,7 @@ module Config
7
10
 
8
11
  module RailsCredentials
9
12
  # Adds Rails credentials as a source of the Settings constant, after the
10
- # YAML files and before ENV (when Config.use_env is on), so:
11
- #
12
- # settings.yml < settings/<env>.yml < *.local.yml < credentials < ENV
13
+ # YAML files and extra_sources and before ENV (when Config.use_env is on).
13
14
  module LoadAndSetSettings
14
15
  def load_and_set_settings(*sources)
15
16
  return super unless Config.use_rails_credentials && RailsCredentials.rails_app?
@@ -18,12 +19,25 @@ module Config
18
19
  end
19
20
  end
20
21
 
22
+ # `rake config:heroku` copies Settings into Heroku config vars and prints
23
+ # them. It is meant to copy only *.local.yml, so keep credentials out.
24
+ module HerokuVars
25
+ def vars
26
+ enabled = Config.use_rails_credentials
27
+ Config.use_rails_credentials = false
28
+ super
29
+ ensure
30
+ Config.use_rails_credentials = enabled
31
+ end
32
+ end
33
+
21
34
  def self.rails_app?
22
35
  defined?(::Rails) && ::Rails.respond_to?(:application) && !::Rails.application.nil?
23
36
  end
24
37
  end
25
38
 
26
39
  singleton_class.prepend RailsCredentials::LoadAndSetSettings
40
+ Integrations::Heroku.prepend RailsCredentials::HerokuVars
27
41
  end
28
42
 
29
43
  require "config/rails_credentials/railtie" if defined?(::Rails::Railtie)
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/hash/keys"
4
+
1
5
  module Config
2
6
  module Sources
3
7
  class RailsCredentialsSource
data/lib/config-rails.rb CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "config/rails_credentials"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Deepak Mahakale