rails-creds 0.3.0 → 0.5.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 +4 -4
- data/.github/workflows/ci.yml +46 -0
- data/.rspec +0 -1
- data/CHANGELOG.md +23 -6
- data/Rakefile +1 -1
- data/creds.gemspec +6 -6
- data/lib/creds/railtie.rb +7 -0
- data/lib/creds/version.rb +2 -2
- data/lib/creds.rb +41 -57
- data/lib/tasks/creds.rake +6 -0
- data/log/test.log +0 -0
- metadata +9 -25
- data/.travis.yml +0 -11
- data/CODE_OF_CONDUCT.md +0 -74
- data/lib/creds/errors.rb +0 -64
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbc1c067d2f4b0a326231eb8c98d1ad5a79f308cc6ef82c2bc9ba2409dd6656d
|
4
|
+
data.tar.gz: 35af2f8b5ba9d9488a466dd64f04da29a78065eb94678e774a8e810b669cbccb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b8e7609ef17e6ea9a5b96ba66ccdd3ff2cd21d916ca30f2df1d52a9c1ef318c6f5e81bdbe417faf5fd26fd15a28e22db9753adf17689205bfa010ff4231a97f
|
7
|
+
data.tar.gz: 19d31443777ff80b7f4dbea23dd7ccd2e2c888136797377274b3fdd606fe812be96454cedfa35d0fe27296666616ef05d85a4a076a614d82dbf17d4365281146
|
@@ -0,0 +1,46 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
push:
|
6
|
+
branches: [main]
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
test:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
|
12
|
+
strategy:
|
13
|
+
fail-fast: false
|
14
|
+
matrix:
|
15
|
+
ruby:
|
16
|
+
- "3.0"
|
17
|
+
- "3.1"
|
18
|
+
- "3.2"
|
19
|
+
- "3.3"
|
20
|
+
- "3.4"
|
21
|
+
|
22
|
+
steps:
|
23
|
+
- name: Install packages
|
24
|
+
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y build-essential git pkg-config google-chrome-stable
|
25
|
+
|
26
|
+
- name: Checkout code
|
27
|
+
uses: actions/checkout@v4
|
28
|
+
|
29
|
+
- name: Set up Ruby
|
30
|
+
uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: ruby-3.4.1
|
33
|
+
bundler-cache: true
|
34
|
+
|
35
|
+
- name: Run tests
|
36
|
+
env:
|
37
|
+
RAILS_ENV: test
|
38
|
+
run: bin/rails test
|
39
|
+
|
40
|
+
- name: Keep screenshots from failed system tests
|
41
|
+
uses: actions/upload-artifact@v4
|
42
|
+
if: failure()
|
43
|
+
with:
|
44
|
+
name: screenshots
|
45
|
+
path: ${{ github.workspace }}/tmp/screenshots
|
46
|
+
if-no-files-found: ignore
|
data/.rspec
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.5.0
|
4
|
+
|
5
|
+
**NB:** Probably breaking change.
|
6
|
+
|
7
|
+
We now rely on YAML for merging credentials. See `bin/rails creds:example` for an example configuration.
|
8
|
+
|
9
|
+
- New: Missing keys always raise.
|
10
|
+
- Added example task.
|
11
|
+
|
12
|
+
## 0.4.0 (2023-07-08)
|
13
|
+
|
14
|
+
### Added
|
15
|
+
|
16
|
+
- Return `nil` and don't read credentials nor complain when SECRET_KEY_BASE_DUMMY=1
|
17
|
+
|
1
18
|
## 0.3.0 (2019-09-19)
|
2
19
|
|
3
20
|
### Breaking changes
|
@@ -8,22 +25,22 @@
|
|
8
25
|
|
9
26
|
### Fixed:
|
10
27
|
|
11
|
-
|
28
|
+
- Require strip_heredoc extension before use
|
12
29
|
|
13
30
|
## 0.2.1
|
14
31
|
|
15
32
|
## Changed:
|
16
33
|
|
17
|
-
|
34
|
+
- Credentials are now memoized after successful read.
|
18
35
|
|
19
36
|
## 0.2.0
|
20
37
|
|
21
38
|
### Changed:
|
22
39
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
40
|
+
- Creds will now warn about missing credentials when the encrypted file isn't
|
41
|
+
found. It will afterwards be a Null Object and return `nil` on every key.
|
42
|
+
- When encrypted credentials are found but the master key file AND env
|
43
|
+
variable is missing, Creds will return a special error with explanation.
|
27
44
|
|
28
45
|
## 0.1.0
|
29
46
|
|
data/Rakefile
CHANGED
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
|
25
|
+
spec.add_dependency("rails", ">= 5.2")
|
25
26
|
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
|
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/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.
|
1
|
+
module Creds
|
2
|
+
VERSION = "0.5.0".freeze
|
3
3
|
end
|
data/lib/creds.rb
CHANGED
@@ -1,79 +1,63 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require "rails"
|
2
|
+
require "active_support/core_ext/string/strip"
|
4
3
|
|
5
4
|
require "creds/version"
|
6
|
-
require "creds/
|
5
|
+
require "creds/railtie"
|
7
6
|
|
8
7
|
# The main module of rails-creds
|
9
|
-
|
10
|
-
|
8
|
+
module Creds
|
9
|
+
EXAMPLE_CONFIG = <<-YAML
|
10
|
+
---
|
11
|
+
secret_key_base: "abc123"
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
def respond_to_missing?(_name)
|
15
|
-
true
|
16
|
-
end
|
13
|
+
shared: &shared
|
14
|
+
secret: 123
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
nil
|
21
|
-
end
|
22
|
-
# rubocop:enable Style/MethodMissingSuper
|
16
|
+
test:
|
17
|
+
<<: *shared
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
19
|
+
development:
|
20
|
+
<<: *shared
|
28
21
|
|
29
|
-
|
30
|
-
|
31
|
-
|
22
|
+
production:
|
23
|
+
<<: *shared
|
24
|
+
secret: 456
|
25
|
+
YAML
|
26
|
+
.strip_heredoc
|
27
|
+
.freeze
|
32
28
|
|
33
|
-
|
34
|
-
|
35
|
-
instance.credentials.fetch(name)
|
36
|
-
rescue KeyError
|
37
|
-
raise MissingKeyError.new(name, Rails.env)
|
38
|
-
end
|
39
|
-
# rubocop:enable Style/MethodMissingSuper
|
29
|
+
class MissingKeyError < StandardError
|
30
|
+
MESSAGE = "Key :%<key>s missing from credentials in \"%<env>s\" env".freeze
|
40
31
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
def credentials
|
46
|
-
return @credentials if @credentials
|
47
|
-
|
48
|
-
unless encrypted_credentials_exist?
|
49
|
-
Rails.logger.warn MissingCredentialsWarning
|
50
|
-
return NullCredentials.new
|
32
|
+
def initialize(key, env)
|
33
|
+
super(format(MESSAGE, key: key, env: env))
|
51
34
|
end
|
35
|
+
end
|
52
36
|
|
53
|
-
|
37
|
+
class MissingEnvError < StandardError
|
38
|
+
MESSAGE = <<-MSG
|
39
|
+
It seems you are missing a scope for the environment "%<env>s".
|
54
40
|
|
55
|
-
|
56
|
-
end
|
41
|
+
Here's an example of how your credentials could look:
|
57
42
|
|
58
|
-
|
43
|
+
#{Creds::EXAMPLE_CONFIG.gsub(/^([^\n]+)$/m, " \\1")}
|
44
|
+
MSG
|
45
|
+
.strip_heredoc
|
46
|
+
.freeze
|
59
47
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
base.delete(Rails.env.to_sym)
|
64
|
-
base.merge(scoped)
|
65
|
-
rescue KeyError
|
66
|
-
raise MissingEnvError, Rails.env
|
48
|
+
def initialize(env)
|
49
|
+
super(format(MESSAGE, env: env))
|
50
|
+
end
|
67
51
|
end
|
68
52
|
|
69
|
-
def
|
70
|
-
|
71
|
-
|
53
|
+
def self.method_missing(mth, *args, &block)
|
54
|
+
@cache ||= Rails.application.credentials[Rails.env].tap do |scoped|
|
55
|
+
raise MissingEnvError.new(Rails.env) unless scoped.is_a?(Hash)
|
56
|
+
raise MissingKeyError.new(mth, Rails.env) unless scoped.key?(mth.to_sym)
|
72
57
|
|
73
|
-
|
74
|
-
|
75
|
-
return true if File.exist?(Rails.root.join("config", "master.key"))
|
58
|
+
scoped
|
59
|
+
end
|
76
60
|
|
77
|
-
|
61
|
+
@cache.fetch(mth.to_sym)
|
78
62
|
end
|
79
63
|
end
|
data/log/test.log
ADDED
File without changes
|
metadata
CHANGED
@@ -1,27 +1,26 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-creds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikkel Malmberg
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rails
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
|
-
- - "
|
16
|
+
- - ">="
|
18
17
|
- !ruby/object:Gem::Version
|
19
18
|
version: '5.2'
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
|
-
- - "
|
23
|
+
- - ">="
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: '5.2'
|
27
26
|
- !ruby/object:Gem::Dependency
|
@@ -66,20 +65,6 @@ dependencies:
|
|
66
65
|
- - "~>"
|
67
66
|
- !ruby/object:Gem::Version
|
68
67
|
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
68
|
description: ''
|
84
69
|
email:
|
85
70
|
- mikkel@brnbw.com
|
@@ -87,11 +72,10 @@ executables: []
|
|
87
72
|
extensions: []
|
88
73
|
extra_rdoc_files: []
|
89
74
|
files:
|
75
|
+
- ".github/workflows/ci.yml"
|
90
76
|
- ".gitignore"
|
91
77
|
- ".rspec"
|
92
|
-
- ".travis.yml"
|
93
78
|
- CHANGELOG.md
|
94
|
-
- CODE_OF_CONDUCT.md
|
95
79
|
- Gemfile
|
96
80
|
- LICENSE.txt
|
97
81
|
- README.md
|
@@ -99,15 +83,16 @@ files:
|
|
99
83
|
- config/master.key
|
100
84
|
- creds.gemspec
|
101
85
|
- lib/creds.rb
|
102
|
-
- lib/creds/
|
86
|
+
- lib/creds/railtie.rb
|
103
87
|
- lib/creds/version.rb
|
104
88
|
- lib/rails-creds.rb
|
89
|
+
- lib/tasks/creds.rake
|
90
|
+
- log/test.log
|
105
91
|
homepage: https://github.com/mikker/rails-creds
|
106
92
|
licenses:
|
107
93
|
- MIT
|
108
94
|
metadata:
|
109
95
|
source_code_uri: https://github.com/mikker/rails-creds
|
110
|
-
post_install_message:
|
111
96
|
rdoc_options: []
|
112
97
|
require_paths:
|
113
98
|
- lib
|
@@ -122,8 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
107
|
- !ruby/object:Gem::Version
|
123
108
|
version: '0'
|
124
109
|
requirements: []
|
125
|
-
rubygems_version: 3.
|
126
|
-
signing_key:
|
110
|
+
rubygems_version: 3.6.8
|
127
111
|
specification_version: 4
|
128
112
|
summary: Shorter, env-scoped version of Rails' credentials
|
129
113
|
test_files: []
|
data/.travis.yml
DELETED
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,74 +0,0 @@
|
|
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 mikkel@brnbw.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/lib/creds/errors.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require "active_support/core_ext/string/strip"
|
2
|
-
|
3
|
-
class Creds
|
4
|
-
class MissingCredentialsWarning
|
5
|
-
MESSAGE =
|
6
|
-
<<-MSG
|
7
|
-
You have no encrypted credentials at config/credentials.yml.enc.
|
8
|
-
Creds will return nil for any key.
|
9
|
-
Run this to generate your credentials file:
|
10
|
-
$ bin/rails credentials:edit
|
11
|
-
MSG
|
12
|
-
.strip_heredoc.freeze
|
13
|
-
end
|
14
|
-
|
15
|
-
# @api private
|
16
|
-
class MissingKeyError < StandardError
|
17
|
-
MESSAGE = 'Key :%<key>s missing from credentials in "%<env>s" env'.freeze
|
18
|
-
|
19
|
-
def initialize(key, env)
|
20
|
-
super format(MESSAGE, key: key, env: env)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# @api private
|
25
|
-
class MissingEnvError < StandardError
|
26
|
-
# rubocop:disable Layout/TrailingWhitespace
|
27
|
-
MESSAGE =
|
28
|
-
<<-MSG
|
29
|
-
Creds scopes credentials to the current Rails environment.
|
30
|
-
It seems you are missing a scope for the environment "%<env>s".
|
31
|
-
|
32
|
-
Here's an example of how your credentials could look:
|
33
|
-
|
34
|
-
---
|
35
|
-
aws_key: 'shared between environments'
|
36
|
-
|
37
|
-
production:
|
38
|
-
<<: *default
|
39
|
-
aws_key: 'you can override defaults for individual environments'
|
40
|
-
MSG
|
41
|
-
.strip_heredoc.freeze
|
42
|
-
# rubocop:enable Layout/TrailingWhitespace
|
43
|
-
|
44
|
-
def initialize(env)
|
45
|
-
super format(MESSAGE, env: env)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# @api private
|
50
|
-
class MissingMasterKeyError < StandardError
|
51
|
-
MESSAGE =
|
52
|
-
<<-MSG
|
53
|
-
You have encrypted credentials but no master key.
|
54
|
-
|
55
|
-
Either get or recover the file config/master.key
|
56
|
-
or set the environment variable RAILS_MASTER_KEY
|
57
|
-
MSG
|
58
|
-
.strip_heredoc.freeze
|
59
|
-
|
60
|
-
def initalize
|
61
|
-
super(MESSAGE)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|