From ec36b8ec6d628697c89b6ebcbd490308dba1e570 Mon Sep 17 00:00:00 2001 From: enjaku4 Date: Thu, 12 Mar 2026 21:57:35 +0100 Subject: [PATCH 01/11] drop support for ruby 3.2 and rails 7.1 --- .github/workflows/ci.yml | 4 +--- .rubocop.yml | 4 ++-- Gemfile | 2 +- kreds.gemspec | 4 ++-- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a3c8d2..1caf534 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 3.2 + ruby-version: 3.3 - name: Bundle install run: bundle install - name: Run RuboCop @@ -48,12 +48,10 @@ jobs: strategy: matrix: ruby: - - "3.2" - "3.3" - "3.4" - "4.0" rails: - - "~> 7.1.0" - "~> 7.2.0" - "~> 8.0.0" - "~> 8.1.0" diff --git a/.rubocop.yml b/.rubocop.yml index da8fc15..9684966 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,8 +9,8 @@ plugins: - rubocop-thread_safety AllCops: - TargetRailsVersion: 7.1 - TargetRubyVersion: 3.2 + TargetRailsVersion: 7.2 + TargetRubyVersion: 3.3 NewCops: enable Layout/IndentationConsistency: diff --git a/Gemfile b/Gemfile index 6674ba3..99454c2 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" gemspec -rails_version = ENV.fetch("RAILS_VERSION", "~> 7.1") +rails_version = ENV.fetch("RAILS_VERSION", "~> 7.2") gem "byebug" gem "rails", rails_version diff --git a/kreds.gemspec b/kreds.gemspec index da6cce1..c3340ef 100644 --- a/kreds.gemspec +++ b/kreds.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |spec| spec.summary = "The missing shorthand for Rails credentials" spec.description = "Simpler and safer Rails credentials access with blank value detection and clear error messages" spec.license = "MIT" - spec.required_ruby_version = ">= 3.2", "< 4.1" + spec.required_ruby_version = ">= 3.3", "< 4.1" spec.files = [ "kreds.gemspec", "README.md", "CHANGELOG.md", "LICENSE.txt" @@ -24,5 +24,5 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] - spec.add_dependency "rails", ">= 7.1", "< 8.2" + spec.add_dependency "rails", ">= 7.2", "< 8.2" end From 74b041c856266b8dbe35d41324cb11907fd20dbd Mon Sep 17 00:00:00 2001 From: enjaku4 Date: Thu, 12 Mar 2026 21:57:48 +0100 Subject: [PATCH 02/11] minor refactoring --- lib/kreds/fetch.rb | 2 +- lib/kreds/show.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/kreds/fetch.rb b/lib/kreds/fetch.rb index 6c42199..179b0fc 100644 --- a/lib/kreds/fetch.rb +++ b/lib/kreds/fetch.rb @@ -41,7 +41,7 @@ def fetch_key(hash, key, path, keys) end def fallback_to_var(error, var, &) - return raise_or_yield(error, &) if var.blank? + return raise_or_yield(error, &) if var.nil? var!(var, &) rescue Kreds::BlankEnvironmentVariableError, Kreds::UnknownEnvironmentVariableError => e diff --git a/lib/kreds/show.rb b/lib/kreds/show.rb index a7833b9..9f26902 100644 --- a/lib/kreds/show.rb +++ b/lib/kreds/show.rb @@ -1,7 +1,7 @@ module Kreds module Show def show - Rails.application.credentials.as_json.deep_symbolize_keys + Rails.application.credentials.config.to_h end end end From cfb419c09b03f80c991e2a5e2e81f98b8db4e1b6 Mon Sep 17 00:00:00 2001 From: enjaku4 Date: Thu, 12 Mar 2026 21:57:58 +0100 Subject: [PATCH 03/11] bump version --- lib/kreds/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kreds/version.rb b/lib/kreds/version.rb index 235b265..bceed1a 100644 --- a/lib/kreds/version.rb +++ b/lib/kreds/version.rb @@ -1,3 +1,3 @@ module Kreds - VERSION = "1.1.7".freeze + VERSION = "2.0.0".freeze end From 09656a17f4bb65ee906d27d13d4acfa49845fcbf Mon Sep 17 00:00:00 2001 From: enjaku4 Date: Thu, 12 Mar 2026 21:58:04 +0100 Subject: [PATCH 04/11] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d65f8bf..025fc5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v2.0.0 + +- Dropped support for Ruby 3.2 +- Dropped support for Rails 7.1 +- Minor code improvements + ## v1.1.7 - Added support for Ruby 4 From e98ae7b61d16efe52062c151aa3b10b54d800c24 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Mar 2026 21:07:26 +0000 Subject: [PATCH 05/11] Initial plan From 0ccd47669203bf7806fb3c9378b6a0c4b1ddd11d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 12 Mar 2026 21:08:06 +0000 Subject: [PATCH 06/11] Update todo job to use Ruby 3.3 instead of 3.2 Co-authored-by: enjaku4 <32835381+enjaku4@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1caf534..8d15bfa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,7 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 3.2 + ruby-version: 3.3 - name: Install grepfruit run: gem install grepfruit - name: Run grepfruit From 2eb51162d581546b088c99406ee9e6b2e6eea60f Mon Sep 17 00:00:00 2001 From: enjaku4 Date: Fri, 13 Mar 2026 09:41:11 +0100 Subject: [PATCH 07/11] better errors --- lib/kreds/fetch.rb | 6 +++--- spec/kreds_spec.rb | 17 +++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/kreds/fetch.rb b/lib/kreds/fetch.rb index 179b0fc..866ce26 100644 --- a/lib/kreds/fetch.rb +++ b/lib/kreds/fetch.rb @@ -14,7 +14,7 @@ def fetch!(*keys, var: nil, &) end def env_fetch!(*keys, var: nil, &) - fetch!(Rails.env, *keys, var:, &) + fetch!(Rails.env, *Kreds::Inputs.process(keys, as: :symbol_array), var:, &) end def var!(var, &) @@ -33,7 +33,7 @@ def fetch_key(hash, key, path, keys) value = hash.fetch(key) raise Kreds::BlankCredentialsError, "Blank value in credentials: #{path_to_s(path)}" if value.blank? - raise Kreds::UnknownCredentialsError, "Credentials key not found: #{path_to_s(path)}[:#{keys[path.size]}]" unless value.is_a?(Hash) || keys == path + raise Kreds::UnknownCredentialsError, "Credentials key not found: #{path_to_s(path.append(keys[path.size]))}" unless value.is_a?(Hash) || keys == path value rescue KeyError @@ -53,7 +53,7 @@ def raise_or_yield(error, &) end def path_to_s(path) - "[:#{path.join("][:")}]" + path.map(&:inspect).join(" => ") end end end diff --git a/spec/kreds_spec.rb b/spec/kreds_spec.rb index 880745a..cfaef4a 100644 --- a/spec/kreds_spec.rb +++ b/spec/kreds_spec.rb @@ -38,17 +38,17 @@ it "raises error for missing end key" do expect { described_class.fetch!(:foo, :bar, :bad) } - .to raise_error(Kreds::UnknownCredentialsError, "Credentials key not found: [:foo][:bar][:bad]") + .to raise_error(Kreds::UnknownCredentialsError, "Credentials key not found: :foo => :bar => :bad") end it "raises error for missing middle key" do expect { described_class.fetch!(:foo, :bad, :baz) } - .to raise_error(Kreds::UnknownCredentialsError, "Credentials key not found: [:foo][:bad]") + .to raise_error(Kreds::UnknownCredentialsError, "Credentials key not found: :foo => :bad") end it "raises error for blank value" do expect { described_class.fetch!(:bad) } - .to raise_error(Kreds::BlankCredentialsError, "Blank value in credentials: [:bad]") + .to raise_error(Kreds::BlankCredentialsError, "Blank value in credentials: :bad") end end @@ -116,7 +116,7 @@ context "when handling edge cases" do it "raises error when trying to access non-hash as hash" do expect { described_class.fetch!(:foo, :bar, :baz, :extra) } - .to raise_error(Kreds::UnknownCredentialsError, "Credentials key not found: [:foo][:bar][:baz][:extra]") + .to raise_error(Kreds::UnknownCredentialsError, "Credentials key not found: :foo => :bar => :baz => :extra") end it "works with single key" do @@ -128,7 +128,7 @@ describe ".env_fetch!" do it "raises error for invalid key types" do expect { described_class.env_fetch!(:foo, 42) } - .to raise_error(Kreds::InvalidArgumentError, "Expected an array of symbols or strings, got `[\"test\", :foo, 42]`") + .to raise_error(Kreds::InvalidArgumentError, "Expected an array of symbols or strings, got `[:foo, 42]`") end it "raises error for invalid var type when fallback is needed" do @@ -137,8 +137,9 @@ end context "without var" do - it "returns entire test environment hash when no keys provided" do - expect(described_class.env_fetch!).to eq({ foo: [1, 2, 3] }) + it "raises error for empty keys" do + expect { described_class.env_fetch! } + .to raise_error(Kreds::InvalidArgumentError, "Expected an array of symbols or strings, got `[]`") end it "returns specific value from test environment" do @@ -147,7 +148,7 @@ it "raises error for missing key in test environment" do expect { described_class.env_fetch!(:foo, :bar, :bad) } - .to raise_error(Kreds::UnknownCredentialsError, "Credentials key not found: [:test][:foo][:bar]") + .to raise_error(Kreds::UnknownCredentialsError, "Credentials key not found: :test => :foo => :bar") end end From 2d8f26b630153c8ac61cfca2b9b23e904b66cb3a Mon Sep 17 00:00:00 2001 From: enjaku4 Date: Fri, 13 Mar 2026 09:41:15 +0100 Subject: [PATCH 08/11] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 025fc5c..0630aea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ - Dropped support for Ruby 3.2 - Dropped support for Rails 7.1 -- Minor code improvements +- Improved error messages and input validation ## v1.1.7 From 8cab7db8588354e59d229a000cbd679d746e15c3 Mon Sep 17 00:00:00 2001 From: enjaku4 Date: Thu, 19 Mar 2026 18:26:58 +0100 Subject: [PATCH 09/11] add env_show method --- README.md | 16 ++++++++++++++-- lib/kreds/show.rb | 4 ++++ spec/kreds_spec.rb | 11 +++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9ee4a91..33fb3e1 100644 --- a/README.md +++ b/README.md @@ -24,10 +24,10 @@ Rails.application.credentials.fetch(:recaptcha).fetch(:key) # Kreds (clear, human-readable errors): Kreds.fetch!(:recaptcha, :site_key) -# => Blank value in credentials: [:recaptcha][:site_key] (Kreds::BlankCredentialsError) +# => Blank value in credentials: :recaptcha => :site_key (Kreds::BlankCredentialsError) Kreds.fetch!(:recaptcha, :key) -# => Credentials key not found: [:recaptcha][:key] (Kreds::UnknownCredentialsError) +# => Credentials key not found: :recaptcha => :key (Kreds::UnknownCredentialsError) ``` ## Table of Contents @@ -139,6 +139,18 @@ Useful for debugging and exploring available credentials in the Rails console. ```ruby Kreds.show +# => { production: { aws: { access_key_id: "...", secret_access_key: "..." } }, ... } +``` + +**`Kreds.env_show`** + +Like `show`, but scoped to the current Rails environment. + +**Returns:** Hash containing credentials for `Rails.env` + +```ruby +# In production, returns credentials[:production] +Kreds.env_show # => { aws: { access_key_id: "...", secret_access_key: "..." }, ... } ``` diff --git a/lib/kreds/show.rb b/lib/kreds/show.rb index 9f26902..55dcdfe 100644 --- a/lib/kreds/show.rb +++ b/lib/kreds/show.rb @@ -3,5 +3,9 @@ module Show def show Rails.application.credentials.config.to_h end + + def env_show + show[Rails.env.to_sym].to_h + end end end diff --git a/spec/kreds_spec.rb b/spec/kreds_spec.rb index cfaef4a..63289ce 100644 --- a/spec/kreds_spec.rb +++ b/spec/kreds_spec.rb @@ -14,6 +14,17 @@ end end + describe ".env_show" do + it "returns credentials for the current environment" do + expect(described_class.env_show).to eq({ foo: [1, 2, 3] }) + end + + it "returns empty hash for an environment not in credentials" do + allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new("staging")) + expect(described_class.env_show).to eq({}) + end + end + describe ".fetch!" do describe "input validation" do it "raises error for empty keys" do From 63dc4ea1a79d524a959f3460f449721a0f0b232b Mon Sep 17 00:00:00 2001 From: enjaku4 Date: Thu, 19 Mar 2026 18:27:14 +0100 Subject: [PATCH 10/11] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0630aea..6807d18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ - Dropped support for Ruby 3.2 - Dropped support for Rails 7.1 - Improved error messages and input validation +- Added `Kreds.env_show` method +- `Kreds.env_fetch!` now raises `InvalidArgumentError` when called with no keys ## v1.1.7 From bbf1edf8b61e60ceaab0296d4bd872ce1e11290c Mon Sep 17 00:00:00 2001 From: enjaku4 Date: Thu, 19 Mar 2026 18:43:52 +0100 Subject: [PATCH 11/11] return an empty hash for missing environment --- lib/kreds/show.rb | 2 +- spec/kreds_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/kreds/show.rb b/lib/kreds/show.rb index 55dcdfe..87e6ccc 100644 --- a/lib/kreds/show.rb +++ b/lib/kreds/show.rb @@ -5,7 +5,7 @@ def show end def env_show - show[Rails.env.to_sym].to_h + show[Rails.env.to_sym] || {} end end end diff --git a/spec/kreds_spec.rb b/spec/kreds_spec.rb index 63289ce..b6a5b2e 100644 --- a/spec/kreds_spec.rb +++ b/spec/kreds_spec.rb @@ -23,6 +23,11 @@ allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new("staging")) expect(described_class.env_show).to eq({}) end + + it "returns the raw value when environment entry is not a hash" do + allow(described_class).to receive(:show).and_return({ test: "not_a_hash" }) + expect(described_class.env_show).to eq("not_a_hash") + end end describe ".fetch!" do