rails-creds 0.2.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 180c1ca9192de8e7d152b8287d51031006f724e76e35620c7c19111c97cca536
4
- data.tar.gz: dc4cb85e4083a01a2b825b5568cc56e0391d932e3c9683c466c55f72d676656b
3
+ metadata.gz: bc2e9f9bab0600a6bd80cb4de294fed74e0350dec39a44ece69e2f2f9cf33bb1
4
+ data.tar.gz: 122898482b87c4963fe814f87b5121454528ad19f2f1b0fec5add0fac7dba33b
5
5
  SHA512:
6
- metadata.gz: 56cd8bd00245b4e15d5a9b145e420e8f330a7d76a5db58a38d9580d97b4cdf3319ce10ddc52c6b7de1a4611e20c2a69a836978c21e1af988e50025548ee7f8e1
7
- data.tar.gz: d017e6fbaf58ae2844a91bd820930054696b2b438ec995ff7fc37a1cad8b5f2983fcde085662afa8e15d489552fd0f81b1e989ffc921429c080c4d79122a022a
6
+ metadata.gz: 1cdb35a94bbef472049ea5aa9ea6c13d41478187e34360e22d8f15435f8d8cc342616d11861ccac3c1a9ef637ef767cee142b06344449274e680fcdbb8dc39b5
7
+ data.tar.gz: 8aaf493870469ed8f6578fa480def8d800214ed8740c6eac06cf6f8d2d9c53e22db161ba4643ccaa55c973607f04fcb29fd182c7cff1c659b136222352e73e04
@@ -0,0 +1,17 @@
1
+ name: Tests
2
+ on: [push]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ os: [ubuntu-latest]
9
+ ruby: ["3.0", "3.1", "3.2"]
10
+ runs-on: ${{ matrix.os }}
11
+ steps:
12
+ - uses: actions/checkout@v3
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: ${{ matrix.ruby }}
16
+ bundler-cache: true
17
+ - run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,24 +1,38 @@
1
- # 0.2.3 (2019-08-19)
1
+ # Changelog
2
2
 
3
- Fixed:
3
+ ## 0.4.0 (2023-07-08)
4
4
 
5
- - Require strip_heredoc extension before use
5
+ ### Added
6
6
 
7
- # 0.2.1
7
+ - Return `nil` and don't read credentials nor complain when SECRET_KEY_BASE_DUMMY=1
8
8
 
9
- Changed:
9
+ ## 0.3.0 (2019-09-19)
10
10
 
11
- - Credentials are now memoized after successful read.
11
+ ### Breaking changes
12
12
 
13
- # 0.2.0
13
+ - _(Possibly breaking)_ Scoped creds are now merged with top level creds ([#23](https://github.com/mikker/rails-creds/pull/23))
14
14
 
15
- Changed:
15
+ ## 0.2.3 (2019-08-19)
16
16
 
17
- - Creds will now warn about missing credentials when the encrypted file isn't
18
- found. It will afterwards be a Null Object and return `nil` on every key.
19
- - When encrypted credentials are found but the master key file AND env
20
- variable is missing, Creds will return a special error with explanation.
17
+ ### Fixed:
21
18
 
22
- # 0.1.0
19
+ - Require strip_heredoc extension before use
20
+
21
+ ## 0.2.1
22
+
23
+ ## Changed:
24
+
25
+ - Credentials are now memoized after successful read.
26
+
27
+ ## 0.2.0
28
+
29
+ ### Changed:
30
+
31
+ - Creds will now warn about missing credentials when the encrypted file isn't
32
+ found. It will afterwards be a Null Object and return `nil` on every key.
33
+ - When encrypted credentials are found but the master key file AND env
34
+ variable is missing, Creds will return a special error with explanation.
35
+
36
+ ## 0.1.0
23
37
 
24
38
  Initial version
data/README.md CHANGED
@@ -10,17 +10,9 @@ Given encrypted credentials looking like:
10
10
 
11
11
  ```yaml
12
12
  ---
13
- default: &default
14
- super_secret: 'shared between environments'
15
-
16
- development:
17
- <<: *default
18
-
19
- test:
20
- <<: *default
13
+ super_secret: 'shared between environments'
21
14
 
22
15
  production:
23
- <<: *default
24
16
  super_secret: 'you can override defaults for individual environments'
25
17
  ```
26
18
 
data/creds.gemspec CHANGED
@@ -17,14 +17,14 @@ Gem::Specification.new do |spec|
17
17
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
18
  f.match(%r{^(test|spec|features)/})
19
19
  end
20
+
20
21
  spec.bindir = "exe"
21
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
23
  spec.require_paths = ["lib"]
23
24
 
24
- spec.add_dependency "rails", "> 5.2"
25
+ spec.add_dependency("rails", "> 5.2")
25
26
 
26
- spec.add_development_dependency "bundler", "~> 2.0"
27
- spec.add_development_dependency "rake", "~> 10.0"
28
- spec.add_development_dependency "rspec", "~> 3.0"
29
- spec.add_development_dependency "standard", "~> 0.1.0"
27
+ spec.add_development_dependency("bundler", "~> 2.0")
28
+ spec.add_development_dependency("rake", "~> 12.3")
29
+ spec.add_development_dependency("rspec", "~> 3.0")
30
30
  end
data/lib/creds/errors.rb CHANGED
@@ -2,67 +2,54 @@ require "active_support/core_ext/string/strip"
2
2
 
3
3
  class Creds
4
4
  class MissingCredentialsWarning
5
- MESSAGE =
6
- <<-MSG
5
+ MESSAGE = <<-MSG.strip_heredoc.freeze
7
6
  You have no encrypted credentials at config/credentials.yml.enc.
8
7
  Creds will return nil for any key.
9
8
  Run this to generate your credentials file:
10
9
  $ bin/rails credentials:edit
11
- MSG
12
- .strip_heredoc.freeze
10
+ MSG
13
11
  end
14
12
 
15
13
  # @api private
16
14
  class MissingKeyError < StandardError
17
- MESSAGE = 'Key :%<key>s missing from credentials in "%<env>s" env'.freeze
15
+ MESSAGE = "Key :%<key>s missing from credentials in \"%<env>s\" env".freeze
18
16
 
19
17
  def initialize(key, env)
20
- super format(MESSAGE, key: key, env: env)
18
+ super(format(MESSAGE, key: key, env: env))
21
19
  end
22
20
  end
23
21
 
24
22
  # @api private
25
23
  class MissingEnvError < StandardError
26
24
  # rubocop:disable Layout/TrailingWhitespace
27
- MESSAGE =
28
- <<-MSG
25
+ MESSAGE = <<-MSG.strip_heredoc.freeze
29
26
  Creds scopes credentials to the current Rails environment.
30
27
  It seems you are missing a scope for the environment "%<env>s".
31
28
 
32
29
  Here's an example of how your credentials could look:
33
30
 
34
31
  ---
35
- default: &default
36
- aws_key: 'shared between environments'
37
-
38
- development:
39
- <<: *default
40
-
41
- test:
42
- <<: *default
43
-
32
+ aws_key: 'shared between environments'
33
+
44
34
  production:
45
35
  <<: *default
46
36
  aws_key: 'you can override defaults for individual environments'
47
- MSG
48
- .strip_heredoc.freeze
37
+ MSG
49
38
  # rubocop:enable Layout/TrailingWhitespace
50
39
 
51
40
  def initialize(env)
52
- super format(MESSAGE, env: env)
41
+ super(format(MESSAGE, env: env))
53
42
  end
54
43
  end
55
44
 
56
45
  # @api private
57
46
  class MissingMasterKeyError < StandardError
58
- MESSAGE =
59
- <<-MSG
47
+ MESSAGE = <<-MSG.strip_heredoc.freeze
60
48
  You have encrypted credentials but no master key.
61
49
 
62
50
  Either get or recover the file config/master.key
63
51
  or set the environment variable RAILS_MASTER_KEY
64
- MSG
65
- .strip_heredoc.freeze
52
+ MSG
66
53
 
67
54
  def initalize
68
55
  super(MESSAGE)
data/lib/creds/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Creds
2
- VERSION = "0.2.3".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
data/lib/creds.rb CHANGED
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "rails"
4
2
 
5
3
  require "creds/version"
@@ -15,11 +13,9 @@ class Creds
15
13
  true
16
14
  end
17
15
 
18
- # rubocop:disable Style/MethodMissingSuper
19
16
  def method_missing(*_args)
20
17
  nil
21
18
  end
22
- # rubocop:enable Style/MethodMissingSuper
23
19
 
24
20
  def nil?
25
21
  true
@@ -30,13 +26,11 @@ class Creds
30
26
  true
31
27
  end
32
28
 
33
- # rubocop:disable Style/MethodMissingSuper
34
29
  def self.method_missing(name, *_args)
35
30
  instance.credentials.fetch(name)
36
31
  rescue KeyError
37
32
  raise MissingKeyError.new(name, Rails.env)
38
33
  end
39
- # rubocop:enable Style/MethodMissingSuper
40
34
 
41
35
  def self.to_h
42
36
  instance.credentials
@@ -45,9 +39,15 @@ class Creds
45
39
  def credentials
46
40
  return @credentials if @credentials
47
41
 
42
+ if dummy?
43
+ @credentials = NullCredentials.new
44
+ return @credentials
45
+ end
46
+
48
47
  unless encrypted_credentials_exist?
49
- Rails.logger.warn MissingCredentialsWarning
50
- return NullCredentials.new
48
+ Rails.logger.warn(MissingCredentialsWarning)
49
+ @credentials = NullCredentials.new
50
+ return @credentials
51
51
  end
52
52
 
53
53
  raise MissingMasterKeyError unless master_key_present?
@@ -58,18 +58,27 @@ class Creds
58
58
  private
59
59
 
60
60
  def fetch_credentials_for_current_env
61
- Rails.application.credentials.fetch(Rails.env.to_sym)
61
+ base = Rails.application.credentials.config
62
+ scoped = base.fetch(Rails.env.to_sym)
63
+ base.delete(Rails.env.to_sym)
64
+ base.merge(scoped)
62
65
  rescue KeyError
63
66
  raise MissingEnvError, Rails.env
64
67
  end
65
68
 
66
69
  def encrypted_credentials_exist?
67
- File.exist? Rails.root.join("config", "credentials.yml.enc")
70
+ File.exist?(Rails.root.join("config", "credentials.yml.enc"))
68
71
  end
69
72
 
70
73
  def master_key_present?
74
+ return true unless Rails.application.config.require_master_key
71
75
  return true if ENV["RAILS_MASTER_KEY"]
72
76
  return true if File.exist?(Rails.root.join("config", "master.key"))
77
+
73
78
  false
74
79
  end
80
+
81
+ def dummy?
82
+ ENV.fetch("SECRET_KEY_BASE_DUMMY", nil) == "1"
83
+ end
75
84
  end
data/log/test.log ADDED
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-creds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikkel Malmberg
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-19 00:00:00.000000000 Z
11
+ date: 2023-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '12.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '12.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
- - !ruby/object:Gem::Dependency
70
- name: standard
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: 0.1.0
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: 0.1.0
83
69
  description: ''
84
70
  email:
85
71
  - mikkel@brnbw.com
@@ -87,9 +73,9 @@ executables: []
87
73
  extensions: []
88
74
  extra_rdoc_files: []
89
75
  files:
76
+ - ".github/workflows/test.yml"
90
77
  - ".gitignore"
91
78
  - ".rspec"
92
- - ".travis.yml"
93
79
  - CHANGELOG.md
94
80
  - CODE_OF_CONDUCT.md
95
81
  - Gemfile
@@ -102,12 +88,13 @@ files:
102
88
  - lib/creds/errors.rb
103
89
  - lib/creds/version.rb
104
90
  - lib/rails-creds.rb
91
+ - log/test.log
105
92
  homepage: https://github.com/mikker/rails-creds
106
93
  licenses:
107
94
  - MIT
108
95
  metadata:
109
96
  source_code_uri: https://github.com/mikker/rails-creds
110
- post_install_message:
97
+ post_install_message:
111
98
  rdoc_options: []
112
99
  require_paths:
113
100
  - lib
@@ -122,8 +109,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
109
  - !ruby/object:Gem::Version
123
110
  version: '0'
124
111
  requirements: []
125
- rubygems_version: 3.0.4
126
- signing_key:
112
+ rubygems_version: 3.4.15
113
+ signing_key:
127
114
  specification_version: 4
128
115
  summary: Shorter, env-scoped version of Rails' credentials
129
116
  test_files: []
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3
5
- - 2.4
6
- - 2.5
7
- - 2.6
8
- - jruby
9
- before_install:
10
- - gem update --system
11
- - gem install bundler