secvault 2.4.0 → 2.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: 18d7c81d380aa63a8092f4bd91a438ee3e02282695b6fcbe6841ffbb81a30a9b
4
- data.tar.gz: 2dbe018b171e0840e9a6047027fcf8e60ef73ec60867e4f6f4f97240df74f126
3
+ metadata.gz: 7aa65a706270754c5654d4ddac89114d5c6f59f80c2bd1480d11dc0b350a57d9
4
+ data.tar.gz: 9ce9a4d9661505ba37a8c827d8f5811c8b9ff0b2fab8f8a8b89bb9f53fb62618
5
5
  SHA512:
6
- metadata.gz: c864336bbb71f184bf09e9f3bc0c191cbd7f7d750ee5a9c541cc3711b0ddc0cc608103e574dffd940b64dc814b4d5b5f433940ef0adf6235e3d17caf9f5784ce
7
- data.tar.gz: 6c62bb91d5a9a0ca1ac0a984f94c92d11c9815d8832e371b7b362d2d6142e1a5f6ea5b058ce8d7762708c271c4cfe848b753d8ea2c6c1dbf47ace950c6df16fd
6
+ metadata.gz: ebd99a7e5c479c1bf98f7180414bcf7b77b45f70a19d56b3b20d734da069ed5f4d18b6855356a89d47475c6955f8ce5a4edc161e2ee13c5d4ab1494a4be38855
7
+ data.tar.gz: 888b561a34ff6be3798accb339d812d0456e3e10df0f4725c2c522e080ccef70c6dc23e54cae76878b5e4a67a44b4b63527b5bd0386133907b3df9a6bbec3df5
data/README.md CHANGED
@@ -86,32 +86,28 @@ production:
86
86
 
87
87
  ## Multi-File Configuration
88
88
 
89
- Organize secrets across multiple files for better maintainability:
89
+ Organize secrets across multiple files with a **super clean API**:
90
90
 
91
91
  ```ruby
92
92
  # config/initializers/secvault.rb
93
93
  require "secvault"
94
- Secvault.setup_backward_compatibility_with_older_rails!
95
94
 
96
- Rails.application.config.after_initialize do
97
- # Load multiple files in order (later files override earlier ones)
98
- secrets_files = [
99
- Rails.root.join('config', 'secrets.yml'), # Base secrets
100
- Rails.root.join('config', 'secrets.oauth.yml'), # OAuth & APIs
101
- Rails.root.join('config', 'secrets.local.yml') # Local overrides
102
- ]
103
-
104
- existing_files = secrets_files.select(&:exist?)
105
-
106
- if existing_files.any?
107
- merged_secrets = Rails::Secrets.parse(existing_files, env: Rails.env)
108
- secrets_object = ActiveSupport::OrderedOptions.new
109
- secrets_object.merge!(merged_secrets)
110
- Rails.application.define_singleton_method(:secrets) { secrets_object }
111
- end
112
- end
95
+ # That's it! Just pass your files array
96
+ Secvault.setup_multi_file!([
97
+ 'config/secrets.yml', # Base secrets
98
+ 'config/secrets.oauth.yml', # OAuth & APIs
99
+ 'config/secrets.local.yml' # Local overrides
100
+ ])
113
101
  ```
114
102
 
103
+ **What this does automatically:**
104
+ - ✅ Sets up Rails 7.1 compatibility (calls `setup_backward_compatibility_with_older_rails!`)
105
+ - ✅ Loads and merges all files in order (later files override earlier ones)
106
+ - ✅ Handles missing files gracefully
107
+ - ✅ Adds `reload_secrets!` method in development
108
+ - ✅ Provides logging (except in production)
109
+ - ✅ Creates Rails.application.secrets with merged configuration
110
+
115
111
  **File organization example:**
116
112
  ```
117
113
  config/
@@ -120,6 +116,18 @@ config/
120
116
  ├── secrets.local.yml # Local development overrides (gitignored)
121
117
  ```
122
118
 
119
+ **Advanced options:**
120
+ ```ruby
121
+ # Disable reload helper or logging
122
+ Secvault.setup_multi_file!(files, reload_method: false, logger: false)
123
+
124
+ # Use Pathname objects if needed
125
+ Secvault.setup_multi_file!([
126
+ Rails.root.join('config', 'secrets.yml'),
127
+ Rails.root.join('config', 'secrets.oauth.yml')
128
+ ])
129
+ ```
130
+
123
131
  ## Advanced Usage
124
132
 
125
133
  **Manual multi-file parsing:**
@@ -175,10 +183,14 @@ production:
175
183
 
176
184
  ## Development Tools
177
185
 
178
- **Hot-reload secrets (development only):**
186
+ **Hot-reload secrets (automatically available in development):**
179
187
  ```ruby
180
- # In Rails console or code
181
- reload_secrets! # Reloads all secrets files without server restart
188
+ # In Rails console - automatically added by setup_multi_file!
189
+ reload_secrets! # Reloads all configured files without server restart
190
+ # 🔄 Reloaded secrets from 3 files
191
+
192
+ # Also available as:
193
+ Rails.application.reload_secrets!
182
194
  ```
183
195
 
184
196
  **Check integration status:**
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Secvault
4
- VERSION = "2.4.0"
4
+ VERSION = "2.5.0"
5
5
  end
data/lib/secvault.rb CHANGED
@@ -115,8 +115,87 @@ module Secvault
115
115
  end
116
116
  end
117
117
 
118
- # Backward compatibility alias
118
+ # Set up multi-file secrets loading with a clean API
119
+ # Just pass an array of file paths and Secvault handles the rest
120
+ #
121
+ # Usage in an initializer:
122
+ # Secvault.setup_multi_file!([
123
+ # 'config/secrets.yml',
124
+ # 'config/secrets.oauth.yml',
125
+ # 'config/secrets.local.yml'
126
+ # ])
127
+ #
128
+ # Options:
129
+ # - files: Array of file paths (String or Pathname)
130
+ # - reload_method: Add a reload helper method (default: true in development)
131
+ # - logger: Enable/disable logging (default: true except in production)
132
+ def setup_multi_file!(files, reload_method: Rails.env.development?, logger: !Rails.env.production?)
133
+ # Ensure Secvault integration is active
134
+ setup_backward_compatibility_with_older_rails! unless active?
135
+
136
+ # Convert strings to Pathname objects and resolve relative to Rails.root
137
+ file_paths = Array(files).map do |file|
138
+ file.is_a?(Pathname) ? file : Rails.root.join(file)
139
+ end
140
+
141
+ # Set up the multi-file loading
142
+ Rails.application.config.after_initialize do
143
+ load_multi_file_secrets!(file_paths, logger: logger)
144
+ end
145
+
146
+ # Add reload helper in development
147
+ if reload_method
148
+ add_reload_helper!(file_paths)
149
+ end
150
+ end
151
+
152
+ # Load secrets from multiple files and merge them
153
+ def load_multi_file_secrets!(file_paths, logger: !Rails.env.production?)
154
+ existing_files = file_paths.select(&:exist?)
155
+
156
+ if existing_files.any?
157
+ # Load and merge all secrets files
158
+ merged_secrets = Rails::Secrets.parse(existing_files, env: Rails.env)
159
+
160
+ # Create ActiveSupport::OrderedOptions object for Rails compatibility
161
+ secrets_object = ActiveSupport::OrderedOptions.new
162
+ secrets_object.merge!(merged_secrets)
163
+
164
+ # Replace Rails.application.secrets
165
+ Rails.application.define_singleton_method(:secrets) { secrets_object }
166
+
167
+ # Log successful loading
168
+ if logger
169
+ file_names = existing_files.map(&:basename)
170
+ Rails.logger&.info "[Secvault Multi-File] Loaded #{existing_files.size} files: #{file_names.join(', ')}"
171
+ Rails.logger&.info "[Secvault Multi-File] Merged #{merged_secrets.keys.size} secret keys for #{Rails.env}"
172
+ end
173
+
174
+ merged_secrets
175
+ else
176
+ Rails.logger&.warn "[Secvault Multi-File] No secrets files found" if logger
177
+ {}
178
+ end
179
+ end
180
+
181
+ # Add reload helper method for development
182
+ def add_reload_helper!(file_paths)
183
+ # Define reload method on Rails.application
184
+ Rails.application.define_singleton_method(:reload_secrets!) do
185
+ Secvault.load_multi_file_secrets!(file_paths, logger: true)
186
+ puts "🔄 Reloaded secrets from #{file_paths.size} files"
187
+ true
188
+ end
189
+
190
+ # Also make it available as a top-level method
191
+ Object.define_method(:reload_secrets!) do
192
+ Rails.application.reload_secrets!
193
+ end
194
+ end
195
+
196
+ # Backward compatibility aliases
119
197
  alias_method :setup_rails_71_integration!, :setup_backward_compatibility_with_older_rails!
198
+ alias_method :setup_multi_files!, :setup_multi_file! # Alternative name
120
199
  end
121
200
 
122
201
  Secvault.install! if defined?(Rails)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: secvault
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Unnikrishnan KP