rails-creds 0.4.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 +9 -0
- data/Rakefile +1 -1
- data/creds.gemspec +1 -1
- data/lib/creds/railtie.rb +7 -0
- data/lib/creds/version.rb +2 -2
- data/lib/creds.rb +41 -62
- data/lib/tasks/creds.rake +6 -0
- metadata +8 -11
- data/.github/workflows/test.yml +0 -17
- data/CODE_OF_CONDUCT.md +0 -74
- data/lib/creds/errors.rb +0 -58
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,5 +1,14 @@
|
|
1
1
|
# Changelog
|
2
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
|
+
|
3
12
|
## 0.4.0 (2023-07-08)
|
4
13
|
|
5
14
|
### Added
|
data/Rakefile
CHANGED
data/creds.gemspec
CHANGED
@@ -22,7 +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
|
-
spec.add_dependency("rails", "
|
25
|
+
spec.add_dependency("rails", ">= 5.2")
|
26
26
|
|
27
27
|
spec.add_development_dependency("bundler", "~> 2.0")
|
28
28
|
spec.add_development_dependency("rake", "~> 12.3")
|
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,84 +1,63 @@
|
|
1
1
|
require "rails"
|
2
|
+
require "active_support/core_ext/string/strip"
|
2
3
|
|
3
4
|
require "creds/version"
|
4
|
-
require "creds/
|
5
|
+
require "creds/railtie"
|
5
6
|
|
6
7
|
# The main module of rails-creds
|
7
|
-
|
8
|
-
|
8
|
+
module Creds
|
9
|
+
EXAMPLE_CONFIG = <<-YAML
|
10
|
+
---
|
11
|
+
secret_key_base: "abc123"
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
def respond_to_missing?(_name)
|
13
|
-
true
|
14
|
-
end
|
15
|
-
|
16
|
-
def method_missing(*_args)
|
17
|
-
nil
|
18
|
-
end
|
13
|
+
shared: &shared
|
14
|
+
secret: 123
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.respond_to_missing?(_name)
|
26
|
-
true
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.method_missing(name, *_args)
|
30
|
-
instance.credentials.fetch(name)
|
31
|
-
rescue KeyError
|
32
|
-
raise MissingKeyError.new(name, Rails.env)
|
33
|
-
end
|
16
|
+
test:
|
17
|
+
<<: *shared
|
34
18
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
19
|
+
development:
|
20
|
+
<<: *shared
|
38
21
|
|
39
|
-
|
40
|
-
|
22
|
+
production:
|
23
|
+
<<: *shared
|
24
|
+
secret: 456
|
25
|
+
YAML
|
26
|
+
.strip_heredoc
|
27
|
+
.freeze
|
41
28
|
|
42
|
-
|
43
|
-
|
44
|
-
return @credentials
|
45
|
-
end
|
29
|
+
class MissingKeyError < StandardError
|
30
|
+
MESSAGE = "Key :%<key>s missing from credentials in \"%<env>s\" env".freeze
|
46
31
|
|
47
|
-
|
48
|
-
|
49
|
-
@credentials = NullCredentials.new
|
50
|
-
return @credentials
|
32
|
+
def initialize(key, env)
|
33
|
+
super(format(MESSAGE, key: key, env: env))
|
51
34
|
end
|
52
|
-
|
53
|
-
raise MissingMasterKeyError unless master_key_present?
|
54
|
-
|
55
|
-
@credentials = fetch_credentials_for_current_env
|
56
35
|
end
|
57
36
|
|
58
|
-
|
37
|
+
class MissingEnvError < StandardError
|
38
|
+
MESSAGE = <<-MSG
|
39
|
+
It seems you are missing a scope for the environment "%<env>s".
|
59
40
|
|
60
|
-
|
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)
|
65
|
-
rescue KeyError
|
66
|
-
raise MissingEnvError, Rails.env
|
67
|
-
end
|
41
|
+
Here's an example of how your credentials could look:
|
68
42
|
|
69
|
-
|
70
|
-
|
43
|
+
#{Creds::EXAMPLE_CONFIG.gsub(/^([^\n]+)$/m, " \\1")}
|
44
|
+
MSG
|
45
|
+
.strip_heredoc
|
46
|
+
.freeze
|
47
|
+
|
48
|
+
def initialize(env)
|
49
|
+
super(format(MESSAGE, env: env))
|
50
|
+
end
|
71
51
|
end
|
72
52
|
|
73
|
-
def
|
74
|
-
|
75
|
-
|
76
|
-
|
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)
|
77
57
|
|
78
|
-
|
79
|
-
|
58
|
+
scoped
|
59
|
+
end
|
80
60
|
|
81
|
-
|
82
|
-
ENV.fetch("SECRET_KEY_BASE_DUMMY", nil) == "1"
|
61
|
+
@cache.fetch(mth.to_sym)
|
83
62
|
end
|
84
63
|
end
|
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
|
@@ -73,11 +72,10 @@ executables: []
|
|
73
72
|
extensions: []
|
74
73
|
extra_rdoc_files: []
|
75
74
|
files:
|
76
|
-
- ".github/workflows/
|
75
|
+
- ".github/workflows/ci.yml"
|
77
76
|
- ".gitignore"
|
78
77
|
- ".rspec"
|
79
78
|
- CHANGELOG.md
|
80
|
-
- CODE_OF_CONDUCT.md
|
81
79
|
- Gemfile
|
82
80
|
- LICENSE.txt
|
83
81
|
- README.md
|
@@ -85,16 +83,16 @@ files:
|
|
85
83
|
- config/master.key
|
86
84
|
- creds.gemspec
|
87
85
|
- lib/creds.rb
|
88
|
-
- lib/creds/
|
86
|
+
- lib/creds/railtie.rb
|
89
87
|
- lib/creds/version.rb
|
90
88
|
- lib/rails-creds.rb
|
89
|
+
- lib/tasks/creds.rake
|
91
90
|
- log/test.log
|
92
91
|
homepage: https://github.com/mikker/rails-creds
|
93
92
|
licenses:
|
94
93
|
- MIT
|
95
94
|
metadata:
|
96
95
|
source_code_uri: https://github.com/mikker/rails-creds
|
97
|
-
post_install_message:
|
98
96
|
rdoc_options: []
|
99
97
|
require_paths:
|
100
98
|
- lib
|
@@ -109,8 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
107
|
- !ruby/object:Gem::Version
|
110
108
|
version: '0'
|
111
109
|
requirements: []
|
112
|
-
rubygems_version: 3.
|
113
|
-
signing_key:
|
110
|
+
rubygems_version: 3.6.8
|
114
111
|
specification_version: 4
|
115
112
|
summary: Shorter, env-scoped version of Rails' credentials
|
116
113
|
test_files: []
|
data/.github/workflows/test.yml
DELETED
@@ -1,17 +0,0 @@
|
|
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/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,58 +0,0 @@
|
|
1
|
-
require "active_support/core_ext/string/strip"
|
2
|
-
|
3
|
-
class Creds
|
4
|
-
class MissingCredentialsWarning
|
5
|
-
MESSAGE = <<-MSG.strip_heredoc.freeze
|
6
|
-
You have no encrypted credentials at config/credentials.yml.enc.
|
7
|
-
Creds will return nil for any key.
|
8
|
-
Run this to generate your credentials file:
|
9
|
-
$ bin/rails credentials:edit
|
10
|
-
MSG
|
11
|
-
end
|
12
|
-
|
13
|
-
# @api private
|
14
|
-
class MissingKeyError < StandardError
|
15
|
-
MESSAGE = "Key :%<key>s missing from credentials in \"%<env>s\" env".freeze
|
16
|
-
|
17
|
-
def initialize(key, env)
|
18
|
-
super(format(MESSAGE, key: key, env: env))
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
# @api private
|
23
|
-
class MissingEnvError < StandardError
|
24
|
-
# rubocop:disable Layout/TrailingWhitespace
|
25
|
-
MESSAGE = <<-MSG.strip_heredoc.freeze
|
26
|
-
Creds scopes credentials to the current Rails environment.
|
27
|
-
It seems you are missing a scope for the environment "%<env>s".
|
28
|
-
|
29
|
-
Here's an example of how your credentials could look:
|
30
|
-
|
31
|
-
---
|
32
|
-
aws_key: 'shared between environments'
|
33
|
-
|
34
|
-
production:
|
35
|
-
<<: *default
|
36
|
-
aws_key: 'you can override defaults for individual environments'
|
37
|
-
MSG
|
38
|
-
# rubocop:enable Layout/TrailingWhitespace
|
39
|
-
|
40
|
-
def initialize(env)
|
41
|
-
super(format(MESSAGE, env: env))
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# @api private
|
46
|
-
class MissingMasterKeyError < StandardError
|
47
|
-
MESSAGE = <<-MSG.strip_heredoc.freeze
|
48
|
-
You have encrypted credentials but no master key.
|
49
|
-
|
50
|
-
Either get or recover the file config/master.key
|
51
|
-
or set the environment variable RAILS_MASTER_KEY
|
52
|
-
MSG
|
53
|
-
|
54
|
-
def initalize
|
55
|
-
super(MESSAGE)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|