Support environment variables for credentials and upgrade Rails#331
Closed
yshmarov wants to merge 1 commit into
Closed
Support environment variables for credentials and upgrade Rails#331yshmarov wants to merge 1 commit into
yshmarov wants to merge 1 commit into
Conversation
Backport Rails 8.2's unified credentials API (Rails.app.creds) that checks ENV first, then falls back to encrypted credentials. This makes .env and rails credentials interchangeable - developers can choose either approach without code changes. - Add config/initializers/app_credentials.rb polyfill (remove after Rails 8.2 upgrade) - Replace all Rails.application.credentials.dig calls with Rails.app.creds.option - Update .env.example to mirror all credential keys using double-underscore convention - Update Gemfile to Rails ~> 8.1.2 https://claude.ai/code/session_018vkGAjms65YpjwUidRYLkL
Owner
Author
|
will wait for rails 8.2 release |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces support for environment variables as an alternative to Rails encrypted credentials, implements a backport of Rails 8.2's combined credentials API (
Rails.app.creds), and upgrades Rails to version 8.1.2.Key Changes
Environment Variables Support: Added comprehensive
.env.examplewith all supported configuration options organized by service (Stripe, OAuth providers, SMTP, S3, etc.). Environment variables now take precedence over encrypted credentials using double-underscore (__) as a separator for nested keys.New Credentials Initializer: Created
config/initializers/app_credentials.rbthat backports Rails 8.2'sRails.app.credsAPI. This provides a unified interface that checks ENV variables first, then falls back to encrypted credentials.Unified Credentials API: Replaced all instances of
Rails.application.credentials.dig()withRails.app.creds.option()throughout the codebase for consistency and to support both credential sources.Rails Upgrade: Updated Gemfile to use Rails 8.1.2 (from 8.1.1).
Documentation Updates:
.env.examplewith detailed comments explaining the ENV/credentials relationshipconfig/storage.ymlandlib/templates/rails/credentials/credentials.yml.ttwith clarifying commentsconfig/environments/production.rbcomments to reference ENV variablesImplementation Details
The
AppCredsclass provides two methods:option(*keys, default: nil): Returns ENV value, credential value, or default (non-raising)require(*keys): Same asoptionbut raisesKeyErrorif value is missing from both sourcesThis approach maintains backward compatibility while enabling easier deployment via environment variables, which is particularly useful in containerized and cloud environments.
The backport will be automatically removed after upgrading to Rails 8.2+.
https://claude.ai/code/session_018vkGAjms65YpjwUidRYLkL