rails-creds 0.3.0 → 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: a713e64a2dc6c6e291bb0973929f4cb44441eb59c0d359870e0b932e5d4fcc3c
4
- data.tar.gz: 483da513f4671cde3fc1e2cf83a2b04b5bc456e3fbc564079afd2085002da33b
3
+ metadata.gz: bc2e9f9bab0600a6bd80cb4de294fed74e0350dec39a44ece69e2f2f9cf33bb1
4
+ data.tar.gz: 122898482b87c4963fe814f87b5121454528ad19f2f1b0fec5add0fac7dba33b
5
5
  SHA512:
6
- metadata.gz: 12c4b010d5370eaabfbafcac7c02b2bb9173b2a0e106f76523719f6c5c6fe8273b2ead284fe85ca767ff789c62e844d0f12cbc9679a05823c1343fa1c5a5fbf3
7
- data.tar.gz: f3446191d7149a213fcff4277b78354a652a41166743ea341e4191bfe79e5a1bed73a5ee83bcfed8162252c5b8d204ef025a6f400d7656f5ba42bf41aa0f39f3
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,3 +1,11 @@
1
+ # Changelog
2
+
3
+ ## 0.4.0 (2023-07-08)
4
+
5
+ ### Added
6
+
7
+ - Return `nil` and don't read credentials nor complain when SECRET_KEY_BASE_DUMMY=1
8
+
1
9
  ## 0.3.0 (2019-09-19)
2
10
 
3
11
  ### Breaking changes
@@ -8,22 +16,22 @@
8
16
 
9
17
  ### Fixed:
10
18
 
11
- - Require strip_heredoc extension before use
19
+ - Require strip_heredoc extension before use
12
20
 
13
21
  ## 0.2.1
14
22
 
15
23
  ## Changed:
16
24
 
17
- - Credentials are now memoized after successful read.
25
+ - Credentials are now memoized after successful read.
18
26
 
19
27
  ## 0.2.0
20
28
 
21
29
  ### Changed:
22
30
 
23
- - Creds will now warn about missing credentials when the encrypted file isn't
24
- found. It will afterwards be a Null Object and return `nil` on every key.
25
- - When encrypted credentials are found but the master key file AND env
26
- variable is missing, Creds will return a special error with explanation.
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.
27
35
 
28
36
  ## 0.1.0
29
37
 
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", "~> 12.3"
28
- spec.add_development_dependency "rspec", "~> 3.0"
29
- spec.add_development_dependency "standard", "~> 0.1.0"
30
- end
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
+ end
data/lib/creds/errors.rb CHANGED
@@ -2,30 +2,27 @@ 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
 
@@ -33,29 +30,26 @@ class Creds
33
30
 
34
31
  ---
35
32
  aws_key: 'shared between environments'
36
-
33
+
37
34
  production:
38
35
  <<: *default
39
36
  aws_key: 'you can override defaults for individual environments'
40
- MSG
41
- .strip_heredoc.freeze
37
+ MSG
42
38
  # rubocop:enable Layout/TrailingWhitespace
43
39
 
44
40
  def initialize(env)
45
- super format(MESSAGE, env: env)
41
+ super(format(MESSAGE, env: env))
46
42
  end
47
43
  end
48
44
 
49
45
  # @api private
50
46
  class MissingMasterKeyError < StandardError
51
- MESSAGE =
52
- <<-MSG
47
+ MESSAGE = <<-MSG.strip_heredoc.freeze
53
48
  You have encrypted credentials but no master key.
54
49
 
55
50
  Either get or recover the file config/master.key
56
51
  or set the environment variable RAILS_MASTER_KEY
57
- MSG
58
- .strip_heredoc.freeze
52
+ MSG
59
53
 
60
54
  def initalize
61
55
  super(MESSAGE)
data/lib/creds/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Creds
2
- VERSION = "0.3.0".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?
@@ -67,13 +67,18 @@ class Creds
67
67
  end
68
68
 
69
69
  def encrypted_credentials_exist?
70
- File.exist? Rails.root.join("config", "credentials.yml.enc")
70
+ File.exist?(Rails.root.join("config", "credentials.yml.enc"))
71
71
  end
72
72
 
73
73
  def master_key_present?
74
+ return true unless Rails.application.config.require_master_key
74
75
  return true if ENV["RAILS_MASTER_KEY"]
75
76
  return true if File.exist?(Rails.root.join("config", "master.key"))
76
77
 
77
78
  false
78
79
  end
80
+
81
+ def dummy?
82
+ ENV.fetch("SECRET_KEY_BASE_DUMMY", nil) == "1"
83
+ end
79
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.3.0
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-09-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
@@ -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.3
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