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 +4 -4
- data/CHANGELOG.md +6 -2
- data/README.md +44 -41
- data/lib/config/rails_credentials/railtie.rb +2 -0
- data/lib/config/rails_credentials/version.rb +3 -1
- data/lib/config/rails_credentials.rb +17 -3
- data/lib/config/sources/rails_credentials_source.rb +4 -0
- data/lib/config-rails.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d6473cf468cc40d76adf8e1c6cc85b99e02910c95535b0658a60b3735cce0bce
|
|
4
|
+
data.tar.gz: a29fc298589802c2bf7cd387dc5fe054c8dc3b8c3d576888045165babb0cb18f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
3
|
+
## 0.1.1 (2026-12-03)
|
|
4
4
|
|
|
5
|
-
-
|
|
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
|
-
|
|
4
|
-
(
|
|
3
|
+
[](https://badge.fury.io/rb/config-rails)
|
|
4
|
+
[](https://github.com/deepakmahakale/config-rails/actions/workflows/ci.yml)
|
|
5
5
|
|
|
6
|
-
|
|
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
|
-
|
|
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:
|
|
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 # => "
|
|
39
|
+
Settings.stripe.secret_key # => "sk_live_123"
|
|
49
40
|
```
|
|
50
41
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
`
|
|
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
|
-
|
|
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
|
-
##
|
|
68
|
+
## Caveats
|
|
66
69
|
|
|
67
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,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)
|
|
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)
|
data/lib/config-rails.rb
CHANGED