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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9aff582c5235a95b2f69881a44ccf9ce60952f550e597e6fc65860ccdc535978
4
- data.tar.gz: 462df324f45466b15a426b59fb5cf21088dc0dc00acc2385cbabeb4a5e59b79c
3
+ metadata.gz: '0484df2e3603dfe81ceed14aa0aeb5a143f00261ee8a5e857e7a0585f04bcff4'
4
+ data.tar.gz: b14e146f694a717367c682668c9cb6bc17d2ac890d29ac87dc060eecbc226d33
5
5
  SHA512:
6
- metadata.gz: 6804f1a48407a57ff049fcfa4f218e307601df3a801398bc29a126682c0704aa1832e16356292fc732faadd002607ee5ccf1d03e605e0b2e54bd944db54f2a84
7
- data.tar.gz: 109a1487e1b1cb8742fc9e251b3ecc34f34f464a4659d1e39e41e09dd0c6f879630533899015125b2d9a0883bcaeae24a94c05058e824f20171f3526a43f314c
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.1.2)
5
- rails (>= 5.2)
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.credentials_env method does the work for you. Here is a sample credentials file.
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=vi rails credentials:edit
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 credentials_env method will return values from the RAILS_ENV slice of the credentials. For example if RAILS_ENV == "development":
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.credentials_env.foo => "development foo"
21
- Rails.application.credentials_env[:foo] => "development foo"
22
- Rails.application.credentials_env.fetch(:foo) => "development foo"
23
- Rails.application.credentials_env.config =>
24
- { foo: "development foo" }
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.credentials_env".
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.credentials_env.foo
55
- Rails.application.credentials_env[:foo]
56
- Rails.application.credentials_env.fetch(:foo)
57
- Rails.application.credentials_env.config
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`. 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).
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", ">= 5.2"
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.credentials_env fetches Rails.env slice of the credentials.
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/fetch_rails_env"
4
+ require "active_support/encrypted_configuration"
5
+ require "active_support/encrypted_configuration_env"
5
6
  require "rails/application"
6
- require "rails/application/credentials_env"
7
+ require "rails/application_encrypted"
@@ -1,3 +1,3 @@
1
1
  module CredentialsForRailsEnv
2
- VERSION = "0.1.2"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -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.1.2
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-10 00:00:00.000000000 Z
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/fetch_rails_env.rb
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/application/credentials_env.rb
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
@@ -1,9 +0,0 @@
1
- # Rails.application.credentials_env fetches Rails.env slice of the credentials.
2
-
3
- module Rails
4
- class Application < Engine
5
- def credentials_env
6
- @credentials_env ||= ActiveSupport::FetchRailsEnv.new(credentials)
7
- end
8
- end
9
- end