kreds 1.0.0 → 1.1.1
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/CHANGELOG.md +8 -0
- data/README.md +17 -5
- data/kreds.gemspec +1 -1
- data/lib/kreds/fetch.rb +22 -10
- data/lib/kreds/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fa30f22ae5af3cd8d3cfbc20b59eacabe4c2b79db4033feca2e4e89740d27aa
|
4
|
+
data.tar.gz: 42a758a1e6b4c04d3a87f2d3320da866d6bda9355119cbcda77cee5d1e36881e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c406cca1bd875a184c0a0c2dc00e8d42865ae62eae6e5d820a344e06873ef399e1f7455239f3918c5a4ed75cec32a8c77c2c1597a54c3b36f6674d1e181a7af
|
7
|
+
data.tar.gz: 8ddcfa759c8b22eaebfe5ffc55bdac6ba63bebb316faa1dc18609a5eabf6c7e35531a76c6399f8ecee9fe0e6f8c67753885beb57ffbe3e115bf9b5d8417d1164
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Kreds
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/kreds)
|
4
|
-
[](https://github.com/brownboxdev/kreds/actions/workflows/ci.yml)
|
5
5
|
|
6
6
|
Kreds is a simpler, shorter, and safer way to access Rails credentials, with a few additional features built in. Rails credentials are a convenient way to store secrets, but retrieving them could be more intuitive — that’s where Kreds comes in.
|
7
7
|
|
@@ -52,7 +52,7 @@ If all keys are correct but the value is blank, Kreds will raise `Kreds::BlankCr
|
|
52
52
|
You can optionally provide a fallback environment variable:
|
53
53
|
|
54
54
|
```ruby
|
55
|
-
Kreds.fetch!(:aws, :s3, :credentials, :access_key_id,
|
55
|
+
Kreds.fetch!(:aws, :s3, :credentials, :access_key_id, var: "AWS_ACCESS_KEY_ID")
|
56
56
|
```
|
57
57
|
|
58
58
|
If the key is missing or blank in credentials, Kreds will attempt to fetch the value from the specified environment variable.
|
@@ -85,6 +85,18 @@ You can also provide an optional fallback environment variable:
|
|
85
85
|
Kreds.env_fetch!(:recaptcha, :site_key, var: "RECAPTCHA_SITE_KEY")
|
86
86
|
```
|
87
87
|
|
88
|
+
### Pass a block on failure
|
89
|
+
|
90
|
+
You can pass a block to `fetch!`, `env_fetch!`, and `var!`, which will be executed if the method fails to retrieve the value.
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
Kreds.fetch!(:aws, :s3, :credentials, :access_key_id) do
|
94
|
+
raise MyCustomError, "Custom error message"
|
95
|
+
end
|
96
|
+
|
97
|
+
Kreds.var!("THREADS") { 1 }
|
98
|
+
```
|
99
|
+
|
88
100
|
### Show credentials
|
89
101
|
|
90
102
|
To inspect all credentials as a hash:
|
@@ -108,12 +120,12 @@ Encountered a bug?
|
|
108
120
|
|
109
121
|
## Contributing
|
110
122
|
|
111
|
-
Before creating an issue or a pull request, please read the [contributing guidelines](https://github.com/
|
123
|
+
Before creating an issue or a pull request, please read the [contributing guidelines](https://github.com/brownboxdev/kreds/blob/master/CONTRIBUTING.md).
|
112
124
|
|
113
125
|
## License
|
114
126
|
|
115
|
-
The gem is available as open source under the terms of the [MIT License](https://github.com/
|
127
|
+
The gem is available as open source under the terms of the [MIT License](https://github.com/brownboxdev/kreds/blob/master/LICENSE.txt).
|
116
128
|
|
117
129
|
## Code of Conduct
|
118
130
|
|
119
|
-
Everyone interacting in the Kreds project is expected to follow the [code of conduct](https://github.com/
|
131
|
+
Everyone interacting in the Kreds project is expected to follow the [code of conduct](https://github.com/brownboxdev/kreds/blob/master/CODE_OF_CONDUCT.md).
|
data/kreds.gemspec
CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |spec|
|
|
4
4
|
spec.name = "kreds"
|
5
5
|
spec.version = Kreds::VERSION
|
6
6
|
spec.authors = ["enjaku4"]
|
7
|
-
spec.homepage = "https://github.com/
|
7
|
+
spec.homepage = "https://github.com/brownboxdev/kreds"
|
8
8
|
spec.metadata["homepage_uri"] = spec.homepage
|
9
9
|
spec.metadata["source_code_uri"] = spec.homepage
|
10
10
|
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
|
data/lib/kreds/fetch.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Kreds
|
2
2
|
module Fetch
|
3
|
-
def fetch!(*keys, var: nil)
|
3
|
+
def fetch!(*keys, var: nil, &)
|
4
4
|
validate_keys!(keys)
|
5
5
|
validate_var!(var)
|
6
6
|
|
@@ -11,18 +11,21 @@ module Kreds
|
|
11
11
|
fetch_key(hash, key, path, keys)
|
12
12
|
end
|
13
13
|
rescue Kreds::BlankCredentialsError, Kreds::UnknownCredentialsError => e
|
14
|
-
fallback_to_var(e, var)
|
14
|
+
fallback_to_var(e, var, &)
|
15
15
|
end
|
16
16
|
|
17
|
-
def env_fetch!(*keys, var: nil)
|
18
|
-
fetch!(Rails.env, *keys, var: var)
|
17
|
+
def env_fetch!(*keys, var: nil, &)
|
18
|
+
fetch!(Rails.env, *keys, var: var, &)
|
19
19
|
end
|
20
20
|
|
21
|
-
def var!(var)
|
21
|
+
def var!(var, &)
|
22
22
|
validate_var!(var)
|
23
23
|
|
24
24
|
result, success = check_var(var)
|
25
|
-
|
25
|
+
|
26
|
+
return result if success
|
27
|
+
|
28
|
+
raise_or_yield(result, &)
|
26
29
|
end
|
27
30
|
|
28
31
|
private
|
@@ -50,11 +53,16 @@ module Kreds
|
|
50
53
|
raise Kreds::UnknownCredentialsError, "Credentials key not found: [:#{path.join("][:")}]"
|
51
54
|
end
|
52
55
|
|
53
|
-
def fallback_to_var(error, var)
|
54
|
-
|
56
|
+
def fallback_to_var(error, var, &)
|
57
|
+
if var.present?
|
58
|
+
result, success = check_var(var)
|
55
59
|
|
56
|
-
|
57
|
-
|
60
|
+
return result if success
|
61
|
+
|
62
|
+
raise_or_yield(Kreds::Error.new([error.message, result.message].join(", ")), &)
|
63
|
+
end
|
64
|
+
|
65
|
+
raise_or_yield(error, &)
|
58
66
|
end
|
59
67
|
|
60
68
|
def check_var(var)
|
@@ -66,5 +74,9 @@ module Kreds
|
|
66
74
|
rescue KeyError
|
67
75
|
[Kreds::UnknownEnvironmentVariableError.new("Environment variable not found: #{var.inspect}"), false]
|
68
76
|
end
|
77
|
+
|
78
|
+
def raise_or_yield(error, &)
|
79
|
+
block_given? ? yield : raise(error)
|
80
|
+
end
|
69
81
|
end
|
70
82
|
end
|
data/lib/kreds/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kreds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- enjaku4
|
@@ -41,13 +41,13 @@ files:
|
|
41
41
|
- lib/kreds/fetch.rb
|
42
42
|
- lib/kreds/show.rb
|
43
43
|
- lib/kreds/version.rb
|
44
|
-
homepage: https://github.com/
|
44
|
+
homepage: https://github.com/brownboxdev/kreds
|
45
45
|
licenses:
|
46
46
|
- MIT
|
47
47
|
metadata:
|
48
|
-
homepage_uri: https://github.com/
|
49
|
-
source_code_uri: https://github.com/
|
50
|
-
changelog_uri: https://github.com/
|
48
|
+
homepage_uri: https://github.com/brownboxdev/kreds
|
49
|
+
source_code_uri: https://github.com/brownboxdev/kreds
|
50
|
+
changelog_uri: https://github.com/brownboxdev/kreds/blob/main/CHANGELOG.md
|
51
51
|
rubygems_mfa_required: 'true'
|
52
52
|
rdoc_options: []
|
53
53
|
require_paths:
|