rails-env-credentials 0.0.1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84517ccea34a2ff4d2cb10143e6b404bdffa06268fc4c9041df0b308d5399906
4
- data.tar.gz: 9d5680bd39e0fea33ff4ec6efa91d468cebab0fcc689727b379e8ae768002913
3
+ metadata.gz: 363b33c0c34aeb3dad04152477f1e528b47b9ab085e4360f4222aacfb5bfc348
4
+ data.tar.gz: fca49e47dabee021fbeb639adde223f696bea9dd6f6bae68c736fbf528eb7209
5
5
  SHA512:
6
- metadata.gz: 8a73a80e72719f1c2a5b3e003bdcba4a9edc874e976bf52e02232139a3307353057692663f21499fa8191d265862b1f87dd486c1a4eb6ccc947b9731b9230be3
7
- data.tar.gz: df73410d35cf50d9c083aad8f696462e3e13193f119a71eb986f042f126dc3eb10e809201eb24aba03598c121038b2519a2970346270a38ff335adff5aa6892a
6
+ metadata.gz: 15a9a335dc2eb2f32919d2d6d8f778051c120f0f684d5f9a99a6bc0df039b9a4328337e1e180d0ace296f8c41f7cf063b296976bc8bed321e654a60decc0526c
7
+ data.tar.gz: 7584a2d9f323183ad2aeb3b325053b97d479f3a51dbc080bb213f09b110339ccf38ca833179573d076cce409d0e6a4748f6ee2213f6c03e24bd3d2c9653b82a6
data/Gemfile CHANGED
@@ -4,5 +4,3 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in rails-env-credentials.gemspec
6
6
  gemspec
7
-
8
- gem "rails", github: "rails/rails"
data/README.md CHANGED
@@ -1,102 +1,79 @@
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
1
+ [![Gem Version](https://badge.fury.io/rb/rails-env-credentials.svg)](https://badge.fury.io/rb/rails-env-credentials)
2
+ [![Build Status](https://travis-ci.org/sinsoku/rails-env-credentials.svg?branch=master)](https://travis-ci.org/sinsoku/rails-env-credentials)
8
3
 
9
- It supports two cases as below:
4
+ # RailsEnvCredentials
10
5
 
11
- ### Case 1: Specify config file per env
6
+ It enhances the Credentials feature introduced by Rails v5.2.0.
12
7
 
13
- You can use credentials with a different file per env.
8
+ ## Why make it?
14
9
 
15
- ```yaml
16
- # config/credentials-development.yml.enc
17
- token: xxx
18
- ```
10
+ Credentials is a good feature, but we cannot use it on development and test environment.
19
11
 
20
- ```yaml
21
- # config/credentials.yml.enc
22
- token: xxx
23
- ```
12
+ DHH wrote as follow in the pull request for initial implementation:
24
13
 
25
- ### Case 2: Includes env in credentials
14
+ > It's only in production (and derivative environments, like exposed betas) where the secret actually needs to be secret.
15
+ >
16
+ > refs: https://github.com/rails/rails/pull/30067
26
17
 
27
- You can include env at a root level in credentials.
18
+ However, I have to manage secrets in the staging environment.
28
19
 
29
- ```yaml
30
- # config/credentials.yml.enc
31
- development:
32
- token: xxx
20
+ I do not have the confidence to explain explicit use cases to Rails team, so I implemented as a gem.
33
21
 
34
- test:
35
- token: xxx
36
-
37
- production:
38
- token: xxx
39
- ```
22
+ If many people use it, I would like to send a pull request to Rails.:octocat::heart:
40
23
 
41
24
  ## Installation
42
25
 
43
- Add this line to your application's Gemfile:
26
+ Add this line to your Rails application's Gemfile:
44
27
 
45
28
  ```ruby
46
- gem 'rails-env-credentials'
29
+ group :development, :test do
30
+ gem 'rails-env-credentials'
31
+ end
47
32
  ```
48
33
 
49
- Then add this to `bin/rails` before `require 'rails/commands'`:
34
+ And then execute:
50
35
 
51
- ```ruby
52
- require 'rails_env_credentials/command'
36
+ ```
37
+ $ bundle
53
38
  ```
54
39
 
55
40
  ## Usage
56
41
 
57
- You need to configure in `config/application.rb`:
58
-
59
- ### Case 1: Specify config file per env
42
+ RailsEnvCredentials will automatically generate encrypted file and the master key when you starts editing credentials at first:
60
43
 
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
44
+ ```
45
+ $ rails env_credentials:edit -e development
76
46
  ```
77
47
 
78
- ### Case 2: Includes env in credentials
48
+ If you want to see decrypted contents, use `env_credentials:show`
79
49
 
80
- ```ruby
81
- # config/application.rb
82
- RailsEnvCredentials.configure do |config|
83
- config.default[:include_env] = true
84
- end
85
50
  ```
51
+ $ rails env_credentials:show -e development
52
+ ```
53
+
54
+ ## Additional information
86
55
 
87
- ### How to edit credentials
56
+ ### Other environments support
88
57
 
89
- If you use only one file, so execute the command normally.
58
+ For example, if the `config/environments/staging.rb` exists, RailsEnvCredentials will automatically generate `config/credentials-staging.yml.enc`.
59
+
60
+ ### Display a diff
61
+
62
+ You can’t directly compare encrypted files between two versions, but it turns out you can see a diff using Git attributes.
63
+
64
+ Put the following line in your `.gitattributes` file:
90
65
 
91
- ```bash
92
- $ rails credentials:edit
66
+ ```
67
+ config/credentials*.yml.enc diff=env_credentials
93
68
  ```
94
69
 
95
- If you use multiple config files, so execute with environment arguments.
70
+ Then configure Git to use `env_credentials:show`:
96
71
 
97
- ```bash
98
- $ rails credentials:edit -e production
99
72
  ```
73
+ $ git config diff.env_credentials.textconv 'rails env_credentials:show --file'
74
+ ```
75
+
76
+ This tells Git that encrypted files should decrypt by the `env_credentials:show` task when you try to display a diff.
100
77
 
101
78
  ## Development
102
79
 
@@ -114,4 +91,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
114
91
 
115
92
  ## Code of Conduct
116
93
 
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).
94
+ 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/sinsoku/rails-env-credentials/blob/master/CODE_OF_CONDUCT.md).
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/command/environment_argument"
4
+ require "rails/commands/credentials/credentials_command"
5
+ require "rails_env_credentials"
6
+
7
+ using(Module.new do
8
+ refine Module do
9
+ def const_set!(name, value)
10
+ remove_const(name)
11
+ const_set(name, value)
12
+ end
13
+ end
14
+ end)
15
+
16
+ module Rails
17
+ module Command
18
+ class EnvCredentialsCommand < Rails::Command::CredentialsCommand
19
+ include EnvironmentArgument
20
+
21
+ argument :file, optional: true, banner: "file"
22
+ class_option :file, aliases: "-f", type: :string
23
+
24
+ def edit
25
+ set_credentials_env_from_argument!
26
+ super
27
+ end
28
+
29
+ def show
30
+ set_credentials_env_from_argument!
31
+ super
32
+ end
33
+
34
+ private
35
+
36
+ def set_credentials_env_from_argument!
37
+ extract_environment_option_from_argument
38
+
39
+ if options.file
40
+ RailsEnvCredentials.config_path = options.file
41
+ elsif available_environments.include?(options.environment)
42
+ RailsEnvCredentials.env = options[:environment]
43
+ else
44
+ raise "'#{options.environment}' environment is not found. Available: #{available_environments}"
45
+ end
46
+ end
47
+
48
+ def master_key_generator
49
+ require "rails/generators"
50
+ require "rails/generators/rails/master_key/master_key_generator"
51
+
52
+ key_path = RailsEnvCredentials.options[:key_path]
53
+ Rails::Generators::MasterKeyGenerator.const_set!(:MASTER_KEY_PATH, Pathname.new(key_path))
54
+ Rails::Generators::MasterKeyGenerator.new
55
+ end
56
+
57
+ def credentials_generator
58
+ require "rails/generators"
59
+ require "rails/generators/rails/credentials/credentials_generator"
60
+
61
+ Rails::Generators::CredentialsGenerator.prepend(RailsEnvCredentials::CredentialsOverwrite)
62
+ Rails::Generators::CredentialsGenerator.new
63
+ end
64
+ end
65
+ end
66
+ end
@@ -1,26 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/module/delegation"
4
3
  require "rails"
5
-
6
- require "rails_env_credentials/configuration"
7
- require "rails_env_credentials/credentials_loading"
4
+ require "rails_env_credentials/config"
5
+ require "rails_env_credentials/credentials_overwrite"
8
6
  require "rails_env_credentials/railtie"
9
7
  require "rails_env_credentials/version"
10
8
 
11
9
  module RailsEnvCredentials
12
10
  class << self
13
- delegate :credentials, :include_env?, :key_path, to: :config
11
+ def config_path=(path)
12
+ if path.end_with?('credentials.yml.enc')
13
+ env = 'production'
14
+ else
15
+ env = /-(\w+)\.yml\.enc\Z/.match(path).to_a[1]
16
+ end
17
+ @config = Config.new(env: env, config_path: path)
18
+ end
14
19
 
15
- def configure
16
- yield config
17
- config.reload!
20
+ def env=(env)
21
+ @config = Config.new(env: env)
18
22
  end
19
23
 
20
- private
24
+ def options
25
+ (@config || Config.new).to_options
26
+ end
21
27
 
22
- def config
23
- @config ||= Configuration.new
28
+ def credentials
29
+ ActiveSupport::EncryptedConfiguration.new(options)
24
30
  end
25
31
  end
26
32
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsEnvCredentials
4
+ class Config
5
+ attr_reader :env
6
+
7
+ def initialize(env: nil, config_path: nil)
8
+ @env = env.nil? ? Rails.env : ActiveSupport::StringInquirer.new(env)
9
+ @config_path = config_path
10
+ end
11
+
12
+ def to_options
13
+ env_key = env_suffix("RAILS_MASTER_KEY", "_").upcase
14
+ key_path = "config/#{env_suffix("master")}.key"
15
+
16
+ {
17
+ config_path: config_path,
18
+ env_key: env_key,
19
+ key_path: key_path,
20
+ raise_if_missing_key: false
21
+ }
22
+ end
23
+
24
+ private
25
+
26
+ def config_path
27
+ @config_path || "config/#{env_suffix("credentials")}.yml.enc"
28
+ end
29
+
30
+ def env_suffix(str, suffix = "-")
31
+ env.production? ? str : [str, suffix, env].join
32
+ end
33
+ end
34
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsEnvCredentials
4
- module CredentialsLoading
4
+ module CredentialsOverwrite
5
5
  def credentials
6
6
  @credentials ||= RailsEnvCredentials.credentials
7
7
  end
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rails_env_credentials/credentials_loading"
4
-
5
3
  module RailsEnvCredentials
6
4
  class Railtie < ::Rails::Railtie
7
5
  initializer 'rails-env-credentials' do
8
- Rails::Application.prepend(CredentialsLoading)
6
+ Rails::Application.prepend(CredentialsOverwrite)
9
7
  end
10
8
  end
11
9
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsEnvCredentials
4
- VERSION = "0.0.1"
4
+ VERSION = "0.1.0"
5
5
  end
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ["sinsoku"]
11
11
  spec.email = ["sinsoku.listy@gmail.com"]
12
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"
13
+ spec.summary = "It enhances the credentials configuration introduced by Rails v5.2.0"
14
+ spec.description = "It enhances the credentials configuration introduced by Rails v5.2.0"
15
15
  spec.homepage = "https://github.com/sinsoku/rails-env-credentials"
16
16
  spec.license = "MIT"
17
17
 
@@ -22,8 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- # TODO: Add a dependecy after the v5.2.0 releases
26
- # spec.add_dependency "rails", ">= 5.2.0"
25
+ spec.add_dependency "rails", ">= 5.2.0.rc1"
27
26
 
28
27
  spec.add_development_dependency "bundler", "~> 1.16"
29
28
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-env-credentials
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sinsoku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-01-03 00:00:00.000000000 Z
11
+ date: 2018-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.0.rc1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.0.rc1
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,8 +66,7 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '3.0'
55
- description: It enhances the credentials configuration configuration introduced by
56
- Rails v5.2.0
69
+ description: It enhances the credentials configuration introduced by Rails v5.2.0
57
70
  email:
58
71
  - sinsoku.listy@gmail.com
59
72
  executables: []
@@ -65,20 +78,20 @@ files:
65
78
  - ".travis.yml"
66
79
  - CODE_OF_CONDUCT.md
67
80
  - Gemfile
68
- - Gemfile.lock
69
81
  - LICENSE.txt
70
82
  - README.md
71
83
  - Rakefile
72
84
  - bin/console
73
85
  - bin/setup
86
+ - config/environments/development.rb
87
+ - config/environments/production.rb
88
+ - config/environments/staging.rb
89
+ - config/environments/test.rb
74
90
  - lib/rails-env-credentials.rb
91
+ - lib/rails/commands/env_credentials_command.rb
75
92
  - 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
93
+ - lib/rails_env_credentials/config.rb
94
+ - lib/rails_env_credentials/credentials_overwrite.rb
82
95
  - lib/rails_env_credentials/railtie.rb
83
96
  - lib/rails_env_credentials/version.rb
84
97
  - rails-env-credentials.gemspec
@@ -105,6 +118,5 @@ rubyforge_project:
105
118
  rubygems_version: 2.7.3
106
119
  signing_key:
107
120
  specification_version: 4
108
- summary: It enhances the credentials configuration configuration introduced by Rails
109
- v5.2.0
121
+ summary: It enhances the credentials configuration introduced by Rails v5.2.0
110
122
  test_files: []
data/Gemfile.lock DELETED
@@ -1,143 +0,0 @@
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
@@ -1,21 +0,0 @@
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)
@@ -1,17 +0,0 @@
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
@@ -1,11 +0,0 @@
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
@@ -1,56 +0,0 @@
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
@@ -1,15 +0,0 @@
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