rails-env-credentials 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +143 -0
- data/LICENSE.txt +21 -0
- data/README.md +117 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rails-env-credentials.rb +3 -0
- data/lib/rails_env_credentials.rb +26 -0
- data/lib/rails_env_credentials/command.rb +21 -0
- data/lib/rails_env_credentials/command/environment_loading.rb +17 -0
- data/lib/rails_env_credentials/command/master_key_path_reloading.rb +11 -0
- data/lib/rails_env_credentials/configuration.rb +56 -0
- data/lib/rails_env_credentials/credentials_loading.rb +9 -0
- data/lib/rails_env_credentials/encrypted_configuration.rb +15 -0
- data/lib/rails_env_credentials/railtie.rb +11 -0
- data/lib/rails_env_credentials/version.rb +5 -0
- data/rails-env-credentials.gemspec +31 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 84517ccea34a2ff4d2cb10143e6b404bdffa06268fc4c9041df0b308d5399906
|
4
|
+
data.tar.gz: 9d5680bd39e0fea33ff4ec6efa91d468cebab0fcc689727b379e8ae768002913
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8a73a80e72719f1c2a5b3e003bdcba4a9edc874e976bf52e02232139a3307353057692663f21499fa8191d265862b1f87dd486c1a4eb6ccc947b9731b9230be3
|
7
|
+
data.tar.gz: df73410d35cf50d9c083aad8f696462e3e13193f119a71eb986f042f126dc3eb10e809201eb24aba03598c121038b2519a2970346270a38ff335adff5aa6892a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at sinsoku.listy@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/rails/rails
|
3
|
+
revision: 921b877c2fd51cc0abdcf0ef6ca3528808047056
|
4
|
+
specs:
|
5
|
+
actioncable (5.2.0.beta2)
|
6
|
+
actionpack (= 5.2.0.beta2)
|
7
|
+
nio4r (~> 2.0)
|
8
|
+
websocket-driver (~> 0.6.1)
|
9
|
+
actionmailer (5.2.0.beta2)
|
10
|
+
actionpack (= 5.2.0.beta2)
|
11
|
+
actionview (= 5.2.0.beta2)
|
12
|
+
activejob (= 5.2.0.beta2)
|
13
|
+
mail (~> 2.5, >= 2.5.4)
|
14
|
+
rails-dom-testing (~> 2.0)
|
15
|
+
actionpack (5.2.0.beta2)
|
16
|
+
actionview (= 5.2.0.beta2)
|
17
|
+
activesupport (= 5.2.0.beta2)
|
18
|
+
rack (~> 2.0)
|
19
|
+
rack-test (>= 0.6.3)
|
20
|
+
rails-dom-testing (~> 2.0)
|
21
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
22
|
+
actionview (5.2.0.beta2)
|
23
|
+
activesupport (= 5.2.0.beta2)
|
24
|
+
builder (~> 3.1)
|
25
|
+
erubi (~> 1.4)
|
26
|
+
rails-dom-testing (~> 2.0)
|
27
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
28
|
+
activejob (5.2.0.beta2)
|
29
|
+
activesupport (= 5.2.0.beta2)
|
30
|
+
globalid (>= 0.3.6)
|
31
|
+
activemodel (5.2.0.beta2)
|
32
|
+
activesupport (= 5.2.0.beta2)
|
33
|
+
activerecord (5.2.0.beta2)
|
34
|
+
activemodel (= 5.2.0.beta2)
|
35
|
+
activesupport (= 5.2.0.beta2)
|
36
|
+
arel (>= 9.0)
|
37
|
+
activestorage (5.2.0.beta2)
|
38
|
+
actionpack (= 5.2.0.beta2)
|
39
|
+
activerecord (= 5.2.0.beta2)
|
40
|
+
activesupport (5.2.0.beta2)
|
41
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
42
|
+
i18n (~> 0.7)
|
43
|
+
minitest (~> 5.1)
|
44
|
+
tzinfo (~> 1.1)
|
45
|
+
rails (5.2.0.beta2)
|
46
|
+
actioncable (= 5.2.0.beta2)
|
47
|
+
actionmailer (= 5.2.0.beta2)
|
48
|
+
actionpack (= 5.2.0.beta2)
|
49
|
+
actionview (= 5.2.0.beta2)
|
50
|
+
activejob (= 5.2.0.beta2)
|
51
|
+
activemodel (= 5.2.0.beta2)
|
52
|
+
activerecord (= 5.2.0.beta2)
|
53
|
+
activestorage (= 5.2.0.beta2)
|
54
|
+
activesupport (= 5.2.0.beta2)
|
55
|
+
bundler (>= 1.3.0)
|
56
|
+
railties (= 5.2.0.beta2)
|
57
|
+
sprockets-rails (>= 2.0.0)
|
58
|
+
railties (5.2.0.beta2)
|
59
|
+
actionpack (= 5.2.0.beta2)
|
60
|
+
activesupport (= 5.2.0.beta2)
|
61
|
+
method_source
|
62
|
+
rake (>= 0.8.7)
|
63
|
+
thor (>= 0.18.1, < 2.0)
|
64
|
+
|
65
|
+
PATH
|
66
|
+
remote: .
|
67
|
+
specs:
|
68
|
+
rails-env-credentials (0.0.1)
|
69
|
+
|
70
|
+
GEM
|
71
|
+
remote: https://rubygems.org/
|
72
|
+
specs:
|
73
|
+
arel (9.0.0)
|
74
|
+
builder (3.2.3)
|
75
|
+
concurrent-ruby (1.0.5)
|
76
|
+
crass (1.0.3)
|
77
|
+
diff-lcs (1.3)
|
78
|
+
erubi (1.7.0)
|
79
|
+
globalid (0.4.1)
|
80
|
+
activesupport (>= 4.2.0)
|
81
|
+
i18n (0.9.1)
|
82
|
+
concurrent-ruby (~> 1.0)
|
83
|
+
loofah (2.1.1)
|
84
|
+
crass (~> 1.0.2)
|
85
|
+
nokogiri (>= 1.5.9)
|
86
|
+
mail (2.7.0)
|
87
|
+
mini_mime (>= 0.1.1)
|
88
|
+
method_source (0.9.0)
|
89
|
+
mini_mime (1.0.0)
|
90
|
+
mini_portile2 (2.3.0)
|
91
|
+
minitest (5.11.0)
|
92
|
+
nio4r (2.2.0)
|
93
|
+
nokogiri (1.8.1)
|
94
|
+
mini_portile2 (~> 2.3.0)
|
95
|
+
rack (2.0.3)
|
96
|
+
rack-test (0.8.2)
|
97
|
+
rack (>= 1.0, < 3)
|
98
|
+
rails-dom-testing (2.0.3)
|
99
|
+
activesupport (>= 4.2.0)
|
100
|
+
nokogiri (>= 1.6)
|
101
|
+
rails-html-sanitizer (1.0.3)
|
102
|
+
loofah (~> 2.0)
|
103
|
+
rake (10.5.0)
|
104
|
+
rspec (3.7.0)
|
105
|
+
rspec-core (~> 3.7.0)
|
106
|
+
rspec-expectations (~> 3.7.0)
|
107
|
+
rspec-mocks (~> 3.7.0)
|
108
|
+
rspec-core (3.7.0)
|
109
|
+
rspec-support (~> 3.7.0)
|
110
|
+
rspec-expectations (3.7.0)
|
111
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
112
|
+
rspec-support (~> 3.7.0)
|
113
|
+
rspec-mocks (3.7.0)
|
114
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
115
|
+
rspec-support (~> 3.7.0)
|
116
|
+
rspec-support (3.7.0)
|
117
|
+
sprockets (3.7.1)
|
118
|
+
concurrent-ruby (~> 1.0)
|
119
|
+
rack (> 1, < 3)
|
120
|
+
sprockets-rails (3.2.1)
|
121
|
+
actionpack (>= 4.0)
|
122
|
+
activesupport (>= 4.0)
|
123
|
+
sprockets (>= 3.0.0)
|
124
|
+
thor (0.20.0)
|
125
|
+
thread_safe (0.3.6)
|
126
|
+
tzinfo (1.2.4)
|
127
|
+
thread_safe (~> 0.1)
|
128
|
+
websocket-driver (0.6.5)
|
129
|
+
websocket-extensions (>= 0.1.0)
|
130
|
+
websocket-extensions (0.1.3)
|
131
|
+
|
132
|
+
PLATFORMS
|
133
|
+
ruby
|
134
|
+
|
135
|
+
DEPENDENCIES
|
136
|
+
bundler (~> 1.16)
|
137
|
+
rails!
|
138
|
+
rails-env-credentials!
|
139
|
+
rake (~> 10.0)
|
140
|
+
rspec (~> 3.0)
|
141
|
+
|
142
|
+
BUNDLED WITH
|
143
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 sinsoku
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
# RailsEnvCredentials
|
2
|
+
|
3
|
+
RailsEnvCredentials enhances the credentials configuration introduced by Rails v5.2.0.
|
4
|
+
|
5
|
+
It make that `Rails.application.credentials` returns environment specific credentials.
|
6
|
+
|
7
|
+
## Features
|
8
|
+
|
9
|
+
It supports two cases as below:
|
10
|
+
|
11
|
+
### Case 1: Specify config file per env
|
12
|
+
|
13
|
+
You can use credentials with a different file per env.
|
14
|
+
|
15
|
+
```yaml
|
16
|
+
# config/credentials-development.yml.enc
|
17
|
+
token: xxx
|
18
|
+
```
|
19
|
+
|
20
|
+
```yaml
|
21
|
+
# config/credentials.yml.enc
|
22
|
+
token: xxx
|
23
|
+
```
|
24
|
+
|
25
|
+
### Case 2: Includes env in credentials
|
26
|
+
|
27
|
+
You can include env at a root level in credentials.
|
28
|
+
|
29
|
+
```yaml
|
30
|
+
# config/credentials.yml.enc
|
31
|
+
development:
|
32
|
+
token: xxx
|
33
|
+
|
34
|
+
test:
|
35
|
+
token: xxx
|
36
|
+
|
37
|
+
production:
|
38
|
+
token: xxx
|
39
|
+
```
|
40
|
+
|
41
|
+
## Installation
|
42
|
+
|
43
|
+
Add this line to your application's Gemfile:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
gem 'rails-env-credentials'
|
47
|
+
```
|
48
|
+
|
49
|
+
Then add this to `bin/rails` before `require 'rails/commands'`:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
require 'rails_env_credentials/command'
|
53
|
+
```
|
54
|
+
|
55
|
+
## Usage
|
56
|
+
|
57
|
+
You need to configure in `config/application.rb`:
|
58
|
+
|
59
|
+
### Case 1: Specify config file per env
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
# config/application.rb
|
63
|
+
RailsEnvCredentials.configure do |config|
|
64
|
+
config.development = {
|
65
|
+
config_path: "config/credentials-development.yml.enc",
|
66
|
+
key_path: "config/development.key",
|
67
|
+
env_key: "RAILS_DEVELOPMENT_KEY",
|
68
|
+
}
|
69
|
+
|
70
|
+
config.test = {
|
71
|
+
config_path: "config/credentials-test.yml.enc",
|
72
|
+
key_path: "config/test.key",
|
73
|
+
env_key: "RAILS_TEST_KEY",
|
74
|
+
}
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
78
|
+
### Case 2: Includes env in credentials
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
# config/application.rb
|
82
|
+
RailsEnvCredentials.configure do |config|
|
83
|
+
config.default[:include_env] = true
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
### How to edit credentials
|
88
|
+
|
89
|
+
If you use only one file, so execute the command normally.
|
90
|
+
|
91
|
+
```bash
|
92
|
+
$ rails credentials:edit
|
93
|
+
```
|
94
|
+
|
95
|
+
If you use multiple config files, so execute with environment arguments.
|
96
|
+
|
97
|
+
```bash
|
98
|
+
$ rails credentials:edit -e production
|
99
|
+
```
|
100
|
+
|
101
|
+
## Development
|
102
|
+
|
103
|
+
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.
|
104
|
+
|
105
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
106
|
+
|
107
|
+
## Contributing
|
108
|
+
|
109
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sinsoku/rails-env-credentials. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
110
|
+
|
111
|
+
## License
|
112
|
+
|
113
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
114
|
+
|
115
|
+
## Code of Conduct
|
116
|
+
|
117
|
+
Everyone interacting in the Rails::Env::Credentials project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rails-env-credentials/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rails/env/credentials"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/module/delegation"
|
4
|
+
require "rails"
|
5
|
+
|
6
|
+
require "rails_env_credentials/configuration"
|
7
|
+
require "rails_env_credentials/credentials_loading"
|
8
|
+
require "rails_env_credentials/railtie"
|
9
|
+
require "rails_env_credentials/version"
|
10
|
+
|
11
|
+
module RailsEnvCredentials
|
12
|
+
class << self
|
13
|
+
delegate :credentials, :include_env?, :key_path, to: :config
|
14
|
+
|
15
|
+
def configure
|
16
|
+
yield config
|
17
|
+
config.reload!
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def config
|
23
|
+
@config ||= Configuration.new
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails_env_credentials"
|
4
|
+
require "rails_env_credentials/command/environment_loading"
|
5
|
+
require "rails_env_credentials/command/master_key_path_reloading"
|
6
|
+
|
7
|
+
# Allow environment argument in `credentials:edit` command
|
8
|
+
require "rails/command"
|
9
|
+
require "rails/commands/credentials/credentials_command"
|
10
|
+
require "rails/command/environment_argument"
|
11
|
+
Rails::Command::CredentialsCommand.include(Rails::Command::EnvironmentArgument)
|
12
|
+
Rails::Command::CredentialsCommand.prepend(RailsEnvCredentials::EnvironmentLoading)
|
13
|
+
|
14
|
+
# Reload master key path before use it
|
15
|
+
require "rails/generators"
|
16
|
+
require "rails/generators/rails/master_key/master_key_generator"
|
17
|
+
Rails::Generators::MasterKeyGenerator.prepend(RailsEnvCredentials::MasterKeyPathReloading)
|
18
|
+
|
19
|
+
# Use EnvCredentials instead of original credentials
|
20
|
+
require "rails/generators/rails/credentials/credentials_generator"
|
21
|
+
Rails::Generators::CredentialsGenerator.prepend(RailsEnvCredentials::CredentialsLoading)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsEnvCredentials
|
4
|
+
module EnvironmentLoading
|
5
|
+
def edit
|
6
|
+
extract_environment_option_from_argument
|
7
|
+
ENV["RAILS_ENV"] = options[:environment]
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def show
|
12
|
+
extract_environment_option_from_argument
|
13
|
+
ENV["RAILS_ENV"] = options[:environment]
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RailsEnvCredentials
|
4
|
+
module MasterKeyPathReloading
|
5
|
+
def add_master_key_file
|
6
|
+
self.class.send(:remove_const, :MASTER_KEY_PATH)
|
7
|
+
self.class.const_set(:MASTER_KEY_PATH, Pathname.new(RailsEnvCredentials.key_path))
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails_env_credentials/encrypted_configuration"
|
4
|
+
|
5
|
+
module RailsEnvCredentials
|
6
|
+
class Configuration
|
7
|
+
attr_accessor :default
|
8
|
+
delegate :[], :fetch, to: :env_config
|
9
|
+
delegate_missing_to :env_config
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@default = {
|
13
|
+
config_path: "config/credentials.yml.enc",
|
14
|
+
key_path: "config/master.key",
|
15
|
+
env_key: "RAILS_MASTER_KEY",
|
16
|
+
require_master_key: false,
|
17
|
+
include_env: false
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def credentials
|
22
|
+
EncryptedConfiguration.new(
|
23
|
+
config_path: Rails.root.join(current_config[:config_path]),
|
24
|
+
key_path: Rails.root.join(current_config[:key_path]),
|
25
|
+
env_key: current_config[:env_key],
|
26
|
+
raise_if_missing_key: current_config[:require_master_key]
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def include_env?
|
31
|
+
current_config[:include_env]
|
32
|
+
end
|
33
|
+
|
34
|
+
def key_path
|
35
|
+
current_config[:key_path]
|
36
|
+
end
|
37
|
+
|
38
|
+
def reload!
|
39
|
+
@current_config = nil
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def current_config
|
45
|
+
@current_config ||= default.merge(env_config[Rails.env])
|
46
|
+
end
|
47
|
+
|
48
|
+
def env_config
|
49
|
+
@env_config ||= ActiveSupport::InheritableOptions.new(
|
50
|
+
development: {},
|
51
|
+
test: {},
|
52
|
+
production: {}
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/encrypted_configuration"
|
4
|
+
|
5
|
+
module RailsEnvCredentials
|
6
|
+
class EncryptedConfiguration < ActiveSupport::EncryptedConfiguration
|
7
|
+
def config
|
8
|
+
if RailsEnvCredentials.include_env?
|
9
|
+
super[Rails.env.to_sym] || {}
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails_env_credentials/credentials_loading"
|
4
|
+
|
5
|
+
module RailsEnvCredentials
|
6
|
+
class Railtie < ::Rails::Railtie
|
7
|
+
initializer 'rails-env-credentials' do
|
8
|
+
Rails::Application.prepend(CredentialsLoading)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "rails_env_credentials/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "rails-env-credentials"
|
9
|
+
spec.version = RailsEnvCredentials::VERSION
|
10
|
+
spec.authors = ["sinsoku"]
|
11
|
+
spec.email = ["sinsoku.listy@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = "It enhances the credentials configuration configuration introduced by Rails v5.2.0"
|
14
|
+
spec.description = "It enhances the credentials configuration configuration introduced by Rails v5.2.0"
|
15
|
+
spec.homepage = "https://github.com/sinsoku/rails-env-credentials"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
# TODO: Add a dependecy after the v5.2.0 releases
|
26
|
+
# spec.add_dependency "rails", ">= 5.2.0"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-env-credentials
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sinsoku
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: It enhances the credentials configuration configuration introduced by
|
56
|
+
Rails v5.2.0
|
57
|
+
email:
|
58
|
+
- sinsoku.listy@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- CODE_OF_CONDUCT.md
|
67
|
+
- Gemfile
|
68
|
+
- Gemfile.lock
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- lib/rails-env-credentials.rb
|
75
|
+
- lib/rails_env_credentials.rb
|
76
|
+
- lib/rails_env_credentials/command.rb
|
77
|
+
- lib/rails_env_credentials/command/environment_loading.rb
|
78
|
+
- lib/rails_env_credentials/command/master_key_path_reloading.rb
|
79
|
+
- lib/rails_env_credentials/configuration.rb
|
80
|
+
- lib/rails_env_credentials/credentials_loading.rb
|
81
|
+
- lib/rails_env_credentials/encrypted_configuration.rb
|
82
|
+
- lib/rails_env_credentials/railtie.rb
|
83
|
+
- lib/rails_env_credentials/version.rb
|
84
|
+
- rails-env-credentials.gemspec
|
85
|
+
homepage: https://github.com/sinsoku/rails-env-credentials
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.7.3
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: It enhances the credentials configuration configuration introduced by Rails
|
109
|
+
v5.2.0
|
110
|
+
test_files: []
|