credentials_for_rails_env 0.1.2 → 1.0.0
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/Gemfile.lock +3 -3
- data/README.md +16 -15
- data/credentials_for_rails_env.gemspec +2 -2
- data/lib/active_support/encrypted_configuration_env.rb +49 -0
- data/lib/credentials_for_rails_env.rb +4 -3
- data/lib/credentials_for_rails_env/version.rb +1 -1
- data/lib/rails/application_encrypted.rb +14 -0
- metadata +10 -10
- data/lib/active_support/fetch_rails_env.rb +0 -24
- data/lib/rails/application/credentials_env.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0484df2e3603dfe81ceed14aa0aeb5a143f00261ee8a5e857e7a0585f04bcff4'
|
4
|
+
data.tar.gz: b14e146f694a717367c682668c9cb6bc17d2ac890d29ac87dc060eecbc226d33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 804b5ed371ebfbb2a12e1612feddfa552021dd090c3d91473874370da46d03783fdfbe0c4f651f8a9daf2fb3d3851edd90d6f9da07797c95cad5077b9aaa975c
|
7
|
+
data.tar.gz: 1d5fca391400aaada844febf682db0c52e0a289a16a45aa468560181975384d91fd699a34e0f2dcef2ce22db28faabf1cfa1266ea5bd6265c8acb8f285b72860
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
credentials_for_rails_env (0.
|
5
|
-
rails (
|
4
|
+
credentials_for_rails_env (1.0.0)
|
5
|
+
rails (~> 5.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -135,7 +135,7 @@ PLATFORMS
|
|
135
135
|
|
136
136
|
DEPENDENCIES
|
137
137
|
bundler (~> 1.16)
|
138
|
-
byebug
|
138
|
+
byebug (~> 10.0)
|
139
139
|
credentials_for_rails_env!
|
140
140
|
rake (~> 10.0)
|
141
141
|
rspec (~> 3.0)
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# CredentialsForRailsEnv
|
2
2
|
|
3
|
-
Now you can easily fetch different credentials for the each of your RAILS_ENV environments. The new Rails.application.
|
3
|
+
Now you can easily fetch different credentials for the each of your RAILS_ENV environments. The new Rails.application.credentials.env method does the work for you. Here is a sample credentials file.
|
4
4
|
|
5
5
|
```yaml
|
6
|
-
$ EDITOR=
|
6
|
+
$ EDITOR=vim rails credentials:edit
|
7
7
|
```
|
8
8
|
|
9
9
|
```yaml
|
@@ -14,19 +14,19 @@ production:
|
|
14
14
|
foo: production foo
|
15
15
|
```
|
16
16
|
|
17
|
-
The new
|
17
|
+
The new credentials.env method will return values from the RAILS_ENV slice of the credentials. For example when RAILS_ENV == "development":
|
18
18
|
|
19
19
|
```ruby
|
20
|
-
Rails.application.
|
21
|
-
Rails.application.
|
22
|
-
Rails.application.
|
23
|
-
Rails.application.
|
24
|
-
|
20
|
+
Rails.application.credentials.env.foo => "development foo"
|
21
|
+
Rails.application.credentials.env[:foo] => "development foo"
|
22
|
+
Rails.application.credentials.env.dig(:foo) => "development foo"
|
23
|
+
Rails.application.credentials.env.fetch(:foo) => "development foo"
|
24
|
+
Rails.application.credentials.env.config => { foo: "development foo" }
|
25
25
|
```
|
26
26
|
|
27
|
-
This makes it very easy to migrate from the deprecated Rails 5.1 secrets convention to the new Rails 5.2 credentials convention. Just add the contents of your secrets file to your credentials file and replace all calls to "Rails.application.secrets" with calls to "Rails.application.
|
27
|
+
This makes it very easy to migrate from the deprecated Rails 5.1 secrets convention to the new Rails 5.2 credentials convention. Just add the contents of your secrets file to your credentials file and replace all calls to "Rails.application.secrets" with calls to "Rails.application.credentials.env". Then you can delete your secrets files.
|
28
28
|
|
29
|
-
You can still call "Rails.application.credentials" as usual.
|
29
|
+
You can still call "Rails.application.credentials" as usual to see the global credentials view.
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
Rails.application.credentials.foo => "global foo"
|
@@ -51,17 +51,18 @@ Or install it yourself as:
|
|
51
51
|
## Usage
|
52
52
|
|
53
53
|
```ruby
|
54
|
-
Rails.application.
|
55
|
-
Rails.application.
|
56
|
-
Rails.application.
|
57
|
-
Rails.application.
|
54
|
+
Rails.application.credentials.env.foo
|
55
|
+
Rails.application.credentials.env[:foo]
|
56
|
+
Rails.application.credentials.env.dig(:foo)
|
57
|
+
Rails.application.credentials.env.fetch(:foo)
|
58
|
+
Rails.application.credentials.env.config
|
58
59
|
```
|
59
60
|
|
60
61
|
## Development
|
61
62
|
|
62
63
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
63
64
|
|
64
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
65
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
65
66
|
|
66
67
|
## Contributing
|
67
68
|
|
@@ -33,9 +33,9 @@ Gem::Specification.new do |spec|
|
|
33
33
|
end
|
34
34
|
spec.require_paths = ["lib"]
|
35
35
|
|
36
|
-
spec.add_dependency "rails", "
|
36
|
+
spec.add_dependency "rails", "~> 5.2"
|
37
37
|
spec.add_development_dependency "bundler", "~> 1.16"
|
38
38
|
spec.add_development_dependency "rake", "~> 10.0"
|
39
39
|
spec.add_development_dependency "rspec", "~> 3.0"
|
40
|
-
spec.add_development_dependency "byebug"
|
40
|
+
spec.add_development_dependency "byebug", "~>10.0"
|
41
41
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaml"
|
4
|
+
require "active_support/encrypted_file"
|
5
|
+
require "active_support/ordered_options"
|
6
|
+
require "active_support/core_ext/object/inclusion"
|
7
|
+
require "active_support/core_ext/module/delegation"
|
8
|
+
|
9
|
+
module ActiveSupport
|
10
|
+
class EncryptedConfiguration < EncryptedFile
|
11
|
+
|
12
|
+
def initialize(config_path:, key_path:, env_key:, raise_if_missing_key:,
|
13
|
+
rails_env: nil)
|
14
|
+
super content_path: config_path, key_path: key_path,
|
15
|
+
env_key: env_key, raise_if_missing_key: raise_if_missing_key
|
16
|
+
@rails_env = rails_env
|
17
|
+
end
|
18
|
+
|
19
|
+
def write(contents)
|
20
|
+
deserialize(contents)
|
21
|
+
@config = @options = @env = nil # Reinitialize for changed content.
|
22
|
+
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
class RailsEnv < BasicObject
|
27
|
+
delegate :[], :fetch, to: :config
|
28
|
+
delegate_missing_to :options
|
29
|
+
|
30
|
+
def initialize(full_config, rails_env)
|
31
|
+
@full_config = full_config || {}
|
32
|
+
@rails_env = rails_env || ''
|
33
|
+
end
|
34
|
+
|
35
|
+
def config
|
36
|
+
@config ||= @full_config[@rails_env.to_sym] || {}
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def options
|
41
|
+
@options ||= ::ActiveSupport::InheritableOptions.new(config)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def env
|
46
|
+
@env ||= RailsEnv.new(config, @rails_env)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,6 +1,7 @@
|
|
1
|
-
# Rails.application.
|
1
|
+
# Rails.application.credentials.env fetches Rails.env slice of the credentials.
|
2
2
|
|
3
3
|
require "credentials_for_rails_env/version"
|
4
|
-
require "active_support/
|
4
|
+
require "active_support/encrypted_configuration"
|
5
|
+
require "active_support/encrypted_configuration_env"
|
5
6
|
require "rails/application"
|
6
|
-
require "rails/
|
7
|
+
require "rails/application_encrypted"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
module Rails
|
3
|
+
class Application < Engine
|
4
|
+
def encrypted(path, key_path: "config/master.key", env_key: "RAILS_MASTER_KEY")
|
5
|
+
ActiveSupport::EncryptedConfiguration.new(
|
6
|
+
config_path: Rails.root.join(path),
|
7
|
+
key_path: Rails.root.join(key_path),
|
8
|
+
env_key: env_key,
|
9
|
+
raise_if_missing_key: config.require_master_key,
|
10
|
+
rails_env: Rails.env
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: credentials_for_rails_env
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Gorman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '5.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '5.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: byebug
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
75
|
+
version: '10.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
82
|
+
version: '10.0'
|
83
83
|
description: Fetch the current RAILS_ENV specific credentials from Rails.application.credentials_env.foo
|
84
84
|
just like Rails.application.secrets.foo.
|
85
85
|
email:
|
@@ -99,10 +99,10 @@ files:
|
|
99
99
|
- bin/console
|
100
100
|
- bin/setup
|
101
101
|
- credentials_for_rails_env.gemspec
|
102
|
-
- lib/active_support/
|
102
|
+
- lib/active_support/encrypted_configuration_env.rb
|
103
103
|
- lib/credentials_for_rails_env.rb
|
104
104
|
- lib/credentials_for_rails_env/version.rb
|
105
|
-
- lib/rails/
|
105
|
+
- lib/rails/application_encrypted.rb
|
106
106
|
homepage: https://github.com/jgorman/credentials_for_rails_env
|
107
107
|
licenses:
|
108
108
|
- MIT
|
@@ -1,24 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Fetch the Rails.env slice of a hash.
|
3
|
-
#
|
4
|
-
|
5
|
-
module ActiveSupport
|
6
|
-
class FetchRailsEnv < BasicObject
|
7
|
-
def initialize(wrapped)
|
8
|
-
@wrapped = wrapped
|
9
|
-
end
|
10
|
-
|
11
|
-
def config
|
12
|
-
@config ||= @wrapped[::Rails.env.to_sym] || {}
|
13
|
-
end
|
14
|
-
|
15
|
-
def [](sym)
|
16
|
-
config[sym]
|
17
|
-
end
|
18
|
-
alias_method :fetch, :[]
|
19
|
-
|
20
|
-
def method_missing(sym, *args, &block)
|
21
|
-
config[sym]
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|