dry-credentials 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +17 -2
- data/README.md +116 -1
- data/lib/dry/credentials/extension.rb +8 -0
- data/lib/dry/credentials/helpers.rb +1 -1
- data/lib/dry/credentials/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +40 -12
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a87f2e29c53fafba34356002ee07e2eb2d31fba25135d51b9098b34171a771cb
|
4
|
+
data.tar.gz: d675791b951d5220f8dafc35330deb022eea62cd2bc82f7e84963d9504441763
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a13c705e06e11791408562219391cf524d7e1d17069cfcfd1d9469cb41187bf7649be21df8b230435c487621b90a2d86f05b19d54bb52dab7a09f215a042b25
|
7
|
+
data.tar.gz: 0c07cae029dc55ba469e469a4f250f36ae73064ec8d5529b6a9f6f9239757eb1ce95ceae7471bb6d959c60e2419fd559de3a6169204bf99c2d15bae726431c43
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -2,9 +2,24 @@
|
|
2
2
|
|
3
3
|
Nothing so far
|
4
4
|
|
5
|
+
## 0.3.0
|
6
|
+
|
7
|
+
#### Additions
|
8
|
+
|
9
|
+
* Support generic fallback environment variable +CREDENTIALS_KEY+
|
10
|
+
|
11
|
+
## 0.2.1
|
12
|
+
|
13
|
+
## 0.2.1
|
14
|
+
|
15
|
+
#### Additions
|
16
|
+
|
17
|
+
* Add square brackets setter for settings
|
18
|
+
* Explain integrations for Bridgetown, Hanami 2 and Rodbot
|
19
|
+
|
5
20
|
## 0.2.0
|
6
21
|
|
7
|
-
#### Breaking
|
22
|
+
#### Breaking changes
|
8
23
|
|
9
24
|
* Fall back to `APP_ENV` instead of `RACK_ENV`
|
10
25
|
|
@@ -14,7 +29,7 @@ Nothing so far
|
|
14
29
|
|
15
30
|
## 0.1.0
|
16
31
|
|
17
|
-
#### Initial
|
32
|
+
#### Initial implementation
|
18
33
|
|
19
34
|
* Require Ruby 3.0 or newer
|
20
35
|
* Class mixin featuring the `credentials` macro:
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
[![Version](https://img.shields.io/gem/v/dry-credentials.svg?style=flat)](https://rubygems.org/gems/dry-credentials)
|
2
2
|
[![Tests](https://img.shields.io/github/actions/workflow/status/svoop/dry-credentials/test.yml?style=flat&label=tests)](https://github.com/svoop/dry-credentials/actions?workflow=Test)
|
3
3
|
[![Code Climate](https://img.shields.io/codeclimate/maintainability/svoop/dry-credentials.svg?style=flat)](https://codeclimate.com/github/svoop/dry-credentials/)
|
4
|
-
[![
|
4
|
+
[![GitHub Sponsors](https://img.shields.io/github/sponsors/svoop.svg)](https://github.com/sponsors/svoop)
|
5
5
|
|
6
6
|
# Dry::Credentials
|
7
7
|
|
@@ -13,6 +13,8 @@ While similar in purpose to ActiveSupport::EncryptedConfiguration, this lightwei
|
|
13
13
|
* [API](https://www.rubydoc.info/gems/dry-credentials)
|
14
14
|
* Author: [Sven Schwyn - Bitcetera](https://bitcetera.com)
|
15
15
|
|
16
|
+
Thank you for supporting free and open-source software by sponsoring on [GitHub](https://github.com/sponsors/svoop) or on [Donorbox](https://donorbox.com/bitcetera). Any gesture is appreciated, from a single Euro for a ☕️ cup of coffee to 🍹 early retirement.
|
17
|
+
|
16
18
|
## Install
|
17
19
|
|
18
20
|
### Security
|
@@ -37,6 +39,8 @@ And then install the bundle:
|
|
37
39
|
bundle install --trust-policy MediumSecurity
|
38
40
|
```
|
39
41
|
|
42
|
+
See [Integrations](#integrations) below for how to integrate Dry::Credentials into frameworks.
|
43
|
+
|
40
44
|
## Usage
|
41
45
|
|
42
46
|
Extend any class with `Dry::Credentials` to use the [default settings](#defaults):
|
@@ -94,6 +98,12 @@ To decrypt the credentials and use them in your app, you have to set just this o
|
|
94
98
|
export SANDBOX_CREDENTIALS_KEY=68656973716a4e706e336733377245732b6e77584c6c772b5432446532456f674767664271374a623876383d
|
95
99
|
```
|
96
100
|
|
101
|
+
Alternatively, you can omit the first part of the variable name. Such a key will be used for any app environment, but a more specific key will always take precedence. This is particularly useful when working with containerized setups:
|
102
|
+
|
103
|
+
```sh
|
104
|
+
export CREDENTIALS_KEY=68656973716a4e706e336733377245732b6e77584c6c772b5432446532456f674767664271374a623876383d
|
105
|
+
```
|
106
|
+
|
97
107
|
With this in place, you can use the decrypted credentials anywhere in your app:
|
98
108
|
|
99
109
|
```ruby
|
@@ -154,6 +164,111 @@ Setting | Default | Description
|
|
154
164
|
`digest` | `"sha256"` | sign digest used if the cipher doesn't support AEAD
|
155
165
|
`serializer` | `Marshal` | serializer responding to `dump` and `load`
|
156
166
|
|
167
|
+
## Integrations
|
168
|
+
|
169
|
+
### Bridgetown
|
170
|
+
|
171
|
+
The [bridgetown_credentials gem](https://github.com/svoop/bridgetown_credentials) integrates Dry::Credentials into your [Bridgetown](https://www.bridgetownrb.com) site.
|
172
|
+
|
173
|
+
### Hanami 2
|
174
|
+
|
175
|
+
To use credentials in a [Hanami 2](https//hanami.org) app, first add this gem to the Gemfile of the app and then create a provider `config/providers/credentials.rb`:
|
176
|
+
|
177
|
+
```ruby
|
178
|
+
# frozen_string_literal: true
|
179
|
+
|
180
|
+
Hanami.app.register_provider :credentials do
|
181
|
+
prepare do
|
182
|
+
require "dry-credentials"
|
183
|
+
|
184
|
+
Dry::Credentials::Extension.new.then do |credentials|
|
185
|
+
credentials[:env] = Hanami.env
|
186
|
+
credentials[:dir] = Hanami.app.root.join(credentials[:dir])
|
187
|
+
credentials[:dir].mkpath
|
188
|
+
credentials.load!
|
189
|
+
register "credentials", credentials
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
```
|
194
|
+
|
195
|
+
Next up are Rake tasks `lib/tasks/credentials.rake`:
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
namespace :credentials do
|
199
|
+
desc "Edit (or create) the encrypted credentials file"
|
200
|
+
task :edit, [:env] => [:environment] do |_, args|
|
201
|
+
Hanami.app.prepare(:credentials)
|
202
|
+
Hanami.app['credentials'].edit! args[:env]
|
203
|
+
end
|
204
|
+
end
|
205
|
+
```
|
206
|
+
|
207
|
+
(As of Hanami 2.1, you have to [explicitly load such tasks in the Rakefile](https://github.com/hanami/hanami/issues/1375) yourself.)
|
208
|
+
|
209
|
+
You can now create a new credentials file for the development environment:
|
210
|
+
|
211
|
+
```
|
212
|
+
rake credentials:edit
|
213
|
+
```
|
214
|
+
|
215
|
+
This prints the credentials key you have to set in `.env`:
|
216
|
+
|
217
|
+
```
|
218
|
+
DEVELOPMENT_CREDENTIALS_KEY=...
|
219
|
+
```
|
220
|
+
|
221
|
+
The credentials are now available anywhere you inject them:
|
222
|
+
|
223
|
+
```ruby
|
224
|
+
module MyHanamiApp
|
225
|
+
class ApiKeyPrinter
|
226
|
+
include Deps[
|
227
|
+
"credentials"
|
228
|
+
]
|
229
|
+
|
230
|
+
def call
|
231
|
+
puts credentials.api_key
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
```
|
236
|
+
|
237
|
+
You can use the credentials in other providers. Say, you want to pass the [ROM](https://rom-rb.org/) database URL (which contains the connection password) using credentials instead of settings. Simply replace `target["settings"].database_url` with `target["credentials"].database_url` and you're good to go:
|
238
|
+
|
239
|
+
```ruby
|
240
|
+
Hanami.app.register_provider :persistence, namespace: true do
|
241
|
+
prepare do
|
242
|
+
require "rom"
|
243
|
+
|
244
|
+
config = ROM::Configuration.new(:sql, target["credentials"].database_url)
|
245
|
+
|
246
|
+
register "config", config
|
247
|
+
register "db", config.gateways[:default].connection
|
248
|
+
end
|
249
|
+
|
250
|
+
(...)
|
251
|
+
end
|
252
|
+
```
|
253
|
+
|
254
|
+
Finally, if you have trouble using the credentials in slices, you might have to [share this app component](https://www.rubydoc.info/gems/hanami/Hanami/Config#shared_app_component_keys-instance_method) in `config/app.rb`:
|
255
|
+
|
256
|
+
```ruby
|
257
|
+
module MyHanamiApp
|
258
|
+
class App < Hanami::App
|
259
|
+
config.shared_app_component_keys += ["credentials"]
|
260
|
+
end
|
261
|
+
end
|
262
|
+
```
|
263
|
+
|
264
|
+
### Ruby on Rails
|
265
|
+
|
266
|
+
ActiveSupport implements [encrypted configuration](https://www.rubydoc.info/gems/activesupport/ActiveSupport/EncryptedConfiguration) which is used by `rails credentials:edit` [out of the box]((https://guides.rubyonrails.org/security.html#custom-credentials)). There's no benefit from introducing an additional dependency like Dry::Credentials.
|
267
|
+
|
268
|
+
### Rodbot
|
269
|
+
|
270
|
+
Dry::Credentials is integrated into [Rodbot](https://github.com/svoop/rodbot) out of the box, see [the README for more](https://github.com/svoop/rodbot/blob/main/README.md#credentials).
|
271
|
+
|
157
272
|
## Development
|
158
273
|
|
159
274
|
To install the development dependencies and then run the test suite:
|
@@ -55,6 +55,14 @@ module Dry
|
|
55
55
|
@settings.send(setting)
|
56
56
|
end
|
57
57
|
|
58
|
+
# Change settings
|
59
|
+
#
|
60
|
+
# @param setting [String] name of the setting
|
61
|
+
# @param value [Object] new value of the setting
|
62
|
+
def []=(setting, value)
|
63
|
+
@settings.send(setting, value)
|
64
|
+
end
|
65
|
+
|
58
66
|
end
|
59
67
|
end
|
60
68
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-credentials
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sven Schwyn
|
@@ -11,8 +11,8 @@ cert_chain:
|
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICAT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WXmGd57uojk3RcIXNwBRRP4DTKcKgVXhuyHb7q1vjTXrS6bw1Ortu0KmWOIk
|
29
|
+
jTyRsT1gymASS2KHe+BaCTwD74GqO8q4woYLZgXnJ/PvgcFgY2FEi2Kn/sXLp4JE
|
30
|
+
boIgxQCMT+nxBHCD
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date:
|
32
|
+
date: 2024-12-08 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: base64
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
type: :runtime
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
34
48
|
- !ruby/object:Gem::Dependency
|
35
49
|
name: debug
|
36
50
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,6 +87,20 @@ dependencies:
|
|
73
87
|
- - ">="
|
74
88
|
- !ruby/object:Gem::Version
|
75
89
|
version: '0'
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: minitest-substitute
|
92
|
+
requirement: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
type: :development
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
76
104
|
- !ruby/object:Gem::Dependency
|
77
105
|
name: minitest-flash
|
78
106
|
requirement: !ruby/object:Gem::Requirement
|
@@ -203,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
231
|
- !ruby/object:Gem::Version
|
204
232
|
version: '0'
|
205
233
|
requirements: []
|
206
|
-
rubygems_version: 3.
|
234
|
+
rubygems_version: 3.5.23
|
207
235
|
signing_key:
|
208
236
|
specification_version: 4
|
209
237
|
summary: A mixin to use encrypted credentials in your classes
|
metadata.gz.sig
CHANGED
Binary file
|