kreds 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 13f6ab3b6f9ddb0cb9a04d9b9bd802b8cce3ed6498fd07046fa2ad42684402c5
4
+ data.tar.gz: b94371b06a5786c60f7bb92b147ad67b48ac0ddede98a8211a51d57d08256c3b
5
+ SHA512:
6
+ metadata.gz: 693e1d768edaa7867809efe75f5f10b349e755b181859740c3c0d19fae62e491ad60f7c703a1d8e05e4b455e2132391a439fbb2668b0892007646e050f3c18b0
7
+ data.tar.gz: fa4330a91248bc4bf1c6dff36995d74cbad6f1254be6b55b02f9185a8ceb6e839d1e1fbe26d262bd4dc7c3fb5564a3dac51f0309b206cf24d69e56f880f7f6c9
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.1.0
2
+
3
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 enjaku4 (https://github.com/enjaku4)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Kreds
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/kreds.svg)](http://badge.fury.io/rb/kreds)
4
+ [![Github Actions badge](https://github.com/enjaku4/kreds/actions/workflows/ci.yml/badge.svg)](https://github.com/enjaku4/kreds/actions/workflows/ci.yml)
5
+
6
+ Kreds is a simpler and shorter way to access Rails credentials — with safety 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
+
8
+ Instead of writing:
9
+
10
+ ```ruby
11
+ Rails.application.credentials[:recaptcha][:site_key]
12
+ ```
13
+
14
+ You can simply use:
15
+
16
+ ```ruby
17
+ Kreds.fetch!(:recaptcha, :site_key)
18
+ ```
19
+
20
+ This not only shortens your code but also ensures an exception is raised if a key is missing or a value is blank, with a clear, human-readable error message.
21
+
22
+ ## Installation
23
+
24
+ Add this line to your application's Gemfile:
25
+
26
+ ```ruby
27
+ gem "kreds"
28
+ ```
29
+
30
+ And then execute:
31
+
32
+ ```shell
33
+ bundle install
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ Kreds provides a single method `.fetch!(*keys)`:
39
+
40
+ ```ruby
41
+ Kreds.fetch!(:aws, :s3, :credentials, :access_key_id)
42
+ ```
43
+
44
+ If you make a typo, such as writing `access_key` instead of `access_key_id`, Kreds will raise `Kreds::UnknownKeyError` with the message: `Key not found: [:aws][:s3][:credentials][:access_key]`. The same applies to any incorrect key in the path.
45
+
46
+ Similarly, if you add an extra key that doesn’t exist, such as: `Kreds.fetch!(:aws, :s3, :credentials, :access_key_id, :id)`, Kreds will raise `Kreds::UnknownKeyError` with the message: `Key not found: [:aws][:s3][:credentials][:access_key_id][:id]`.
47
+
48
+ Kreds also ensures that values are not left blank. For example, if all keys are correct but the value for `access_key_id` is empty, Kreds will raise `Kreds::BlankValueError` with the message: `Blank value for: [:aws][:s3][:credentials][:access_key_id]`.
49
+
50
+ ## Problems?
51
+
52
+ Facing a problem or want to suggest an enhancement?
53
+
54
+ - **Open a Discussion**: If you have a question, experience difficulties using the gem, or have a suggestion for improvements, feel free to use the Discussions section.
55
+
56
+ Encountered a bug?
57
+
58
+ - **Create an Issue**: If you've identified a bug, please create an issue. Be sure to provide detailed information about the problem, including the steps to reproduce it.
59
+ - **Contribute a Solution**: Found a fix for the issue? Feel free to create a pull request with your changes.
60
+
61
+ ## Contributing
62
+
63
+ Before creating an issue or a pull request, please read the [contributing guidelines](https://github.com/enjaku4/kreds/blob/master/CONTRIBUTING.md).
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](https://github.com/enjaku4/kreds/blob/master/LICENSE.txt).
68
+
69
+ ## Code of Conduct
70
+
71
+ Everyone interacting in the Kreds project is expected to follow the [code of conduct](https://github.com/enjaku4/kreds/blob/master/CODE_OF_CONDUCT.md).
data/kreds.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ require_relative "lib/kreds/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "kreds"
5
+ spec.version = Kreds::VERSION
6
+ spec.authors = ["enjaku4"]
7
+ spec.homepage = "https://github.com/enjaku4/kreds"
8
+ spec.metadata["homepage_uri"] = spec.homepage
9
+ spec.metadata["source_code_uri"] = spec.homepage
10
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
11
+ spec.metadata["rubygems_mfa_required"] = "true"
12
+ spec.summary = "The missing shorthand for Rails credentials"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 3.1", "< 3.5"
15
+
16
+ spec.files = [
17
+ "kreds.gemspec", "README.md", "CHANGELOG.md", "LICENSE.txt"
18
+ ] + Dir.glob("lib/**/*")
19
+
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "rails", ">= 7.0", "< 8.1"
23
+ end
@@ -0,0 +1,20 @@
1
+ module Kreds
2
+ module Fetch
3
+ def fetch!(*keys)
4
+ path = []
5
+
6
+ keys.reduce(Rails.application.credentials) do |hash, key|
7
+ path << key
8
+
9
+ result = hash.fetch(key)
10
+
11
+ raise(BlankValueError, "Blank value for: [:#{path.join("][:")}]") if result.blank?
12
+ raise(UnknownKeyError, "Key not found: [:#{path.join("][:")}][:#{keys[path.size]}]") if !result.is_a?(Hash) && keys != path
13
+
14
+ result
15
+ end
16
+ rescue KeyError
17
+ raise UnknownKeyError, "Key not found: [:#{path.join("][:")}]"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Kreds
2
+ VERSION = "0.1.0"
3
+ end
data/lib/kreds.rb ADDED
@@ -0,0 +1,14 @@
1
+ require_relative "kreds/version"
2
+
3
+ require "rails"
4
+
5
+ require_relative "kreds/fetch"
6
+
7
+ module Kreds
8
+ class Error < StandardError; end
9
+
10
+ class UnknownKeyError < Error; end
11
+ class BlankValueError < Error; end
12
+
13
+ extend ::Kreds::Fetch
14
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kreds
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - enjaku4
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-03-06 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '7.0'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '8.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '7.0'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '8.1'
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - CHANGELOG.md
37
+ - LICENSE.txt
38
+ - README.md
39
+ - kreds.gemspec
40
+ - lib/kreds.rb
41
+ - lib/kreds/fetch.rb
42
+ - lib/kreds/version.rb
43
+ homepage: https://github.com/enjaku4/kreds
44
+ licenses:
45
+ - MIT
46
+ metadata:
47
+ homepage_uri: https://github.com/enjaku4/kreds
48
+ source_code_uri: https://github.com/enjaku4/kreds
49
+ changelog_uri: https://github.com/enjaku4/kreds/blob/main/CHANGELOG.md
50
+ rubygems_mfa_required: 'true'
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '3.1'
59
+ - - "<"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.5'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.6.2
69
+ specification_version: 4
70
+ summary: The missing shorthand for Rails credentials
71
+ test_files: []