dry-credentials 0.3.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '059c7a02cdb5b067ad93852c53e2249da715146753df8257eb0f64263f80a392'
4
- data.tar.gz: 54ab5c829f2f9bdf0543832f0f8eb292d586a4e5a0ad41d95a9e10696428312e
3
+ metadata.gz: '083daca34bc70e83df585d9dc978c6ca640f6871b88be092058b33e61dfdbfc6'
4
+ data.tar.gz: 6f39399a6063d42e39f6f3d6128f042eb7d1c54f828deaa60f0345b3d106b2be
5
5
  SHA512:
6
- metadata.gz: '063048e5fec98ca9cde997657b3a3afd1ef58040a4536cb9721cfe4c0f0a5f5e4d453db754aa147c2900b9045c8ad9ce9115f436d44cc769c2b81d65677bc053'
7
- data.tar.gz: 5b9203d7e779263e1faa8ec810882aa8bb51da7e663cc7667e9284549925a861aa96a56334c0c23c34f97d560a86468cb82a66a7f35797cf6d3dab50820df531
6
+ metadata.gz: 42ce1b8de4cb29e0ce70a0365ff51ea7738a552e81e08fded3c530bb9fe6395f744453f7d7e9d4ac59a14ed46d8e4f04782b28e2b4eb31278182970e745ac7d0
7
+ data.tar.gz: 7191f924aea1f515ac35ea82236286095370904c8a1bcf4cd791a1b20e3a0571314fdc0731bf480076c97cfa2bc152508820e01bfbea0c51ef71ce1b390242ba
data/CHANGELOG.md CHANGED
@@ -2,39 +2,44 @@
2
2
 
3
3
  Nothing so far
4
4
 
5
+ ## 0.5.0
6
+
7
+ ### Changes
8
+ * Drop certs
9
+ * Add action for trusted release
10
+
11
+ ## 0.4.0
12
+
13
+ ### Additions
14
+ * Dynamic secrets
15
+
5
16
  ## 0.3.1
6
17
 
7
- Nothing so far
18
+ ### Changes
19
+ * Update Ruby to 3.4
8
20
 
9
21
  ## 0.3.0
10
22
 
11
- #### Additions
12
-
23
+ ### Additions
13
24
  * Support generic fallback environment variable +CREDENTIALS_KEY+
14
25
 
15
26
  ## 0.2.1
16
27
 
17
- ## 0.2.1
18
-
19
- #### Additions
20
-
28
+ ### Additions
21
29
  * Add square brackets setter for settings
22
30
  * Explain integrations for Bridgetown, Hanami 2 and Rodbot
23
31
 
24
32
  ## 0.2.0
25
33
 
26
- #### Breaking changes
27
-
34
+ ### Breaking changes
28
35
  * Fall back to `APP_ENV` instead of `RACK_ENV`
29
36
 
30
- #### Fixes
31
-
37
+ ### Fixes
32
38
  * Don't re-encrypt if credentials haven't been modified
33
39
 
34
40
  ## 0.1.0
35
41
 
36
- #### Initial implementation
37
-
42
+ ### Initial implementation
38
43
  * Require Ruby 3.0 or newer
39
44
  * Class mixin featuring the `credentials` macro:
40
45
  * Block to change (default) settings such as the cipher
data/README.md CHANGED
@@ -17,16 +17,6 @@ Thank you for supporting free and open-source software by sponsoring on [GitHub]
17
17
 
18
18
  ## Install
19
19
 
20
- ### Security
21
-
22
- This gem is [cryptographically signed](https://guides.rubygems.org/security/#using-gems) in order to assure it hasn't been tampered with. Unless already done, please add the author's public key as a trusted certificate now:
23
-
24
- ```
25
- gem cert --add <(curl -Ls https://raw.github.com/svoop/dry-credentials/main/certs/svoop.pem)
26
- ```
27
-
28
- ### Bundler
29
-
30
20
  Add the following to the <tt>Gemfile</tt> or <tt>gems.rb</tt> of your [Bundler](https://bundler.io) powered Ruby project:
31
21
 
32
22
  ```ruby
@@ -36,7 +26,7 @@ gem 'dry-credentials'
36
26
  And then install the bundle:
37
27
 
38
28
  ```
39
- bundle install --trust-policy MediumSecurity
29
+ bundle install
40
30
  ```
41
31
 
42
32
  See [Integrations](#integrations) below for how to integrate Dry::Credentials into frameworks.
@@ -122,7 +112,7 @@ By default, the current environment is read from `APP_ENV`. You shouldn't use `R
122
112
 
123
113
  ⚠️ For safety reasons, don't share the same key across multiple environments!
124
114
 
125
- ## Reload Credentials
115
+ ## Reload credentials
126
116
 
127
117
  The credentials are lazy loaded when queried for the first time. After that, changes in the encrypted credentials files are not taken into account at runtime for efficiency reasons.
128
118
 
@@ -134,7 +124,7 @@ App.credentials.reload!
134
124
 
135
125
  The reload is not done immediately but the next time credentials are queried.
136
126
 
137
- ## Edit Credentials
127
+ ## Edit credentials
138
128
 
139
129
  This gem does not provide any CLI tools to edit the credentials. You should integrate it into your app instead e.g. with a Rake task or an extension to the CLI tool of the app framework you're using.
140
130
 
@@ -146,6 +136,40 @@ App.credentials.edit! "production"
146
136
 
147
137
  Editing credentials implicitly schedules a `reload!`.
148
138
 
139
+ ## Dynamic secrets
140
+
141
+ In case you have to partition secrets beyond environments, you can set dynamic secrets which are composed on the fly. Here's an example.
142
+
143
+ You want to be able to connect to a shared database for the test environment, but the database URL differs whether you run the tests locally or on your favourite CI platform. To differ between the two, you set an environment variable `CONTEXT` which is either `local` or `ci` and you defined the secrets accordingly:
144
+
145
+ ```yaml
146
+ database_url:
147
+ local: postgres://localhost:5432/example
148
+ ci: postgres://testuser:testpassword@remote.db.example.com:5432/example
149
+ ```
150
+
151
+ To get the actual database URL, you have to:
152
+
153
+ ```ruby
154
+ App.credentials.database_url.send(ENV['CONTEXT'])
155
+ ```
156
+
157
+ This is okay, but it may grow a lot longer and less readable in a real app. Enter dynamic secrets which are composed according to your needs:
158
+
159
+ ```ruby
160
+ App.credentials.define! :current_database_url do |credentials|
161
+ credentials.database_url.send(ENV['CONTEXT'])
162
+ end
163
+ ```
164
+
165
+ Dynamic secrets are then available like any other secret, however, the block is called every time you query the dynamic secret:
166
+
167
+ ```ruby
168
+ App.credentials.current_database_url # => "postgres://localhost..."
169
+ ```
170
+
171
+ ⚠️ Don't try to use the same key for a dynamic secret as for an existing regular one since this could create an endless loop and therefore any such attempt will raise a `Dry::Credentials::DefineError`.
172
+
149
173
  ## Settings
150
174
 
151
175
  If you have to, you can access the settings programmatically:
@@ -180,7 +204,9 @@ To use credentials in a [Hanami 2](https//hanami.org) app, first add this gem to
180
204
  Hanami.app.register_provider :credentials do
181
205
  prepare do
182
206
  require "dry-credentials"
207
+ end
183
208
 
209
+ start do
184
210
  Dry::Credentials::Extension.new.then do |credentials|
185
211
  credentials[:env] = Hanami.env
186
212
  credentials[:dir] = Hanami.app.root.join(credentials[:dir])
@@ -263,7 +289,7 @@ end
263
289
 
264
290
  ### Ruby on Rails
265
291
 
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.
292
+ 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 not much benefit from introducing Dry::Credentials as an additional dependency.
267
293
 
268
294
  ### Rodbot
269
295
 
@@ -21,5 +21,9 @@ module Dry
21
21
  class YAMLFormatError < StandardError
22
22
  def initialize(msg='top level must be a dictionary') = super
23
23
  end
24
+
25
+ class DefineError < StandardError
26
+ def initialize(msg='cowardly refusing to redefine existing key') = super
27
+ end
24
28
  end
25
29
  end
@@ -47,6 +47,20 @@ module Dry
47
47
  end
48
48
  end
49
49
 
50
+ # Define a dynamic secret
51
+ #
52
+ # @param key [Symbol, String] name of the dynamic secret
53
+ # @yield [Dry::Credentials::Extension] compose the dynamic secret using
54
+ # the static credentials yielded and other inputs such as `ENV`
55
+ # @yieldreturn [Object] dynamic secret
56
+ # @raise [Types] description
57
+ # @return [self]
58
+ def define!(key, &block)
59
+ fail Dry::Credentials::DefineError if respond_to? key
60
+ define_singleton_method(key) { block.call(self) }
61
+ self
62
+ end
63
+
50
64
  # Query settings
51
65
  #
52
66
  # @param setting [String] name of the setting
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Credentials
5
- VERSION = "0.3.1"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,34 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-credentials
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Schwyn
8
8
  bindir: bin
9
- cert_chain:
10
- - |
11
- -----BEGIN CERTIFICATE-----
12
- MIIDODCCAiCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhydWJ5
13
- L0RDPWJpdGNldGVyYS9EQz1jb20wHhcNMjQxMTIwMjExMDIwWhcNMjUxMTIwMjEx
14
- MDIwWjAjMSEwHwYDVQQDDBhydWJ5L0RDPWJpdGNldGVyYS9EQz1jb20wggEiMA0G
15
- CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDcLg+IHjXYaUlTSU7R235lQKD8ZhEe
16
- KMhoGlSUonZ/zo1OT3KXcqTCP1iMX743xYs6upEGALCWWwq+nxvlDdnWRjF3AAv7
17
- ikC+Z2BEowjyeCCT/0gvn4ohKcR0JOzzRaIlFUVInlGSAHx2QHZ2N8ntf54lu7nd
18
- L8CiDK8rClsY4JBNGOgH9UC81f+m61UUQuTLxyM2CXfAYkj/sGNTvFRJcNX+nfdC
19
- hM9r2kH1+7wsa8yG7wJ2IkrzNACD8v84oE6qVusN8OLEMUI/NaEPVPbw2LUM149H
20
- PVa0i729A4IhroNnFNmw4wOC93ARNbM1+LW36PLMmKjKudf5Exg8VmDVAgMBAAGj
21
- dzB1MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0GA1UdDgQWBBSfK8MtR62mQ6oN
22
- yoX/VKJzFjLSVDAdBgNVHREEFjAUgRJydWJ5QGJpdGNldGVyYS5jb20wHQYDVR0S
23
- BBYwFIEScnVieUBiaXRjZXRlcmEuY29tMA0GCSqGSIb3DQEBCwUAA4IBAQDSeB1x
24
- 8QK8F/ML37isgvwGiQxovDUqu6Sq14cQ1qE9y5prUBmL2AsDuCBpXXctcvamFqNC
25
- PgfJtj7ZZcXmY0SfKCog7T1btkr6zYxPXpxwUqB45n0I6v5qc0UCNvMEfBzxlak5
26
- VW7UMNlKD9qukeN55hxuLF2F/sLldMcHUo/ATgdV4zk1t3sK6A9+02wz5K5qfWdM
27
- Mi+XWXmGd57uojk3RcIXNwBRRP4DTKcKgVXhuyHb7q1vjTXrS6bw1Ortu0KmWOIk
28
- jTyRsT1gymASS2KHe+BaCTwD74GqO8q4woYLZgXnJ/PvgcFgY2FEi2Kn/sXLp4JE
29
- boIgxQCMT+nxBHCD
30
- -----END CERTIFICATE-----
31
- date: 2024-12-25 00:00:00.000000000 Z
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
32
11
  dependencies:
33
12
  - !ruby/object:Gem::Dependency
34
13
  name: base64
@@ -183,9 +162,9 @@ email:
183
162
  executables: []
184
163
  extensions: []
185
164
  extra_rdoc_files:
186
- - README.md
187
165
  - CHANGELOG.md
188
166
  - LICENSE.txt
167
+ - README.md
189
168
  files:
190
169
  - CHANGELOG.md
191
170
  - LICENSE.txt
@@ -229,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
208
  - !ruby/object:Gem::Version
230
209
  version: '0'
231
210
  requirements: []
232
- rubygems_version: 3.6.2
211
+ rubygems_version: 3.6.9
233
212
  specification_version: 4
234
213
  summary: A mixin to use encrypted credentials in your classes
235
214
  test_files: []
checksums.yaml.gz.sig DELETED
@@ -1 +0,0 @@
1
- o�j=��]Vdw2�']D�$U��݌����hvhzI��U�v �A�{.2�HCԟ����Q�g֨�����Q���\M�GF��k�U���m�ВT��b��Rj��B)͒}�8��@;ۮ- ��t���ǚ]7n����3�<�kA�b�3R���i6�w� G��v�c�>$e[��{7����ؐj7�#L:
data.tar.gz.sig DELETED
@@ -1 +0,0 @@
1
- �]H  r���s�y���7u��B�]�)C �x�ʁҭ��a����~���E�2�C�v*��}�Q�~�q��3C�ʕ�tG����NQ��pO��uŠC�y��EFb��'|܄W%Ȳ,��ǂ�� �0���2g��G�JŽ�B��d�{��R"�p��k�d�rηixa��2JgJ�z�������ID,�3(&O��I�{��쒜s)�a�r��l�-�ho�,���S>�g�*�����]��Q�`R��t33������e��
metadata.gz.sig DELETED
Binary file