Skip to content

Commit 987c607

Browse files
authored
feat: support callable values for credentials config (#32)
* feat: support callable values for username and password config Allows Proc/Lambda for deferred evaluation, enabling use with Rails.application.credentials which isn't available at initializer load time. Fully backward compatible with static string values. Closes #31 * chore: update Gemfile.lock for v1.2.1
1 parent d4c06c5 commit 987c607

7 files changed

Lines changed: 68 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [1.2.1] - 2026-03-17
4+
5+
### Added
6+
7+
- Support for callable values (Proc/Lambda) in `username` and `password` configuration, enabling use with `Rails.application.credentials` and other deferred sources ([#31](https://github.com/vishaltps/solid_queue_monitor/issues/31))
8+
- Initializer template now shows ENV variable and Lambda examples for credentials
9+
310
## [1.2.0] - 2026-03-07
411

512
### Changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
solid_queue_monitor (1.2.0)
4+
solid_queue_monitor (1.2.1)
55
rails (>= 7.0)
66
solid_queue (>= 0.1.0)
77

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ SolidQueueMonitor.setup do |config|
104104
config.authentication_enabled = false
105105

106106
# Set the username for HTTP Basic Authentication (only used if authentication is enabled)
107+
# Supports static values, ENV variables, or callables (Proc/Lambda)
107108
config.username = 'admin'
108109

109110
# Set the password for HTTP Basic Authentication (only used if authentication is enabled)
111+
# Supports static values, ENV variables, or callables (Proc/Lambda)
110112
config.password = 'password'
111113

112114
# Number of jobs to display per page
@@ -141,7 +143,21 @@ By default, Solid Queue Monitor does not require authentication to access the da
141143
For production environments, it's strongly recommended to enable authentication:
142144

143145
1. **Enable authentication**: Set `config.authentication_enabled = true` in the initializer
144-
2. **Configure secure credentials**: Set `username` and `password` to strong values in the initializer
146+
2. **Configure secure credentials** using any of these approaches:
147+
148+
```ruby
149+
# Static values
150+
config.username = 'admin'
151+
config.password = 'secure_password'
152+
153+
# Environment variables
154+
config.username = ENV['SOLID_QUEUE_MONITOR_USERNAME']
155+
config.password = ENV['SOLID_QUEUE_MONITOR_PASSWORD']
156+
157+
# Rails credentials (use a lambda for deferred evaluation)
158+
config.username = -> { Rails.application.credentials.dig(:solid_queue_monitor, :username) }
159+
config.password = -> { Rails.application.credentials.dig(:solid_queue_monitor, :password) }
160+
```
145161

146162
## Usage
147163

lib/generators/solid_queue_monitor/templates/initializer.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@
77

88
# Set the username for HTTP Basic Authentication (only used if authentication is enabled)
99
# config.username = 'admin'
10+
# config.username = ENV['SOLID_QUEUE_MONITOR_USERNAME']
11+
# config.username = -> { Rails.application.credentials.dig(:solid_queue_monitor, :username) }
1012

1113
# Set the password for HTTP Basic Authentication (only used if authentication is enabled)
1214
# config.password = 'password'
15+
# config.password = ENV['SOLID_QUEUE_MONITOR_PASSWORD']
16+
# config.password = -> { Rails.application.credentials.dig(:solid_queue_monitor, :password) }
1317

1418
# Number of jobs to display per page
1519
# config.jobs_per_page = 25

lib/solid_queue_monitor.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,23 @@
66
module SolidQueueMonitor
77
class Error < StandardError; end
88
class << self
9-
attr_accessor :username, :password, :jobs_per_page, :authentication_enabled,
9+
attr_writer :username, :password
10+
attr_accessor :jobs_per_page, :authentication_enabled,
1011
:auto_refresh_enabled, :auto_refresh_interval, :show_chart
12+
13+
def username
14+
resolve_value(@username)
15+
end
16+
17+
def password
18+
resolve_value(@password)
19+
end
20+
21+
private
22+
23+
def resolve_value(value)
24+
value.respond_to?(:call) ? value.call : value
25+
end
1126
end
1227

1328
@username = 'admin'

lib/solid_queue_monitor/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module SolidQueueMonitor
4-
VERSION = '1.2.0'
4+
VERSION = '1.2.1'
55
end

spec/services/solid_queue_monitor/authentication_service_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@
3737
expect(described_class.authenticate('wrong', 'wrong')).to be false
3838
end
3939
end
40+
41+
context 'when credentials are configured with callables' do
42+
before do
43+
SolidQueueMonitor.authentication_enabled = true
44+
SolidQueueMonitor.username = -> { 'lambda_user' }
45+
SolidQueueMonitor.password = -> { 'lambda_pass' }
46+
end
47+
48+
after do
49+
SolidQueueMonitor.authentication_enabled = false
50+
SolidQueueMonitor.username = 'admin'
51+
SolidQueueMonitor.password = 'password'
52+
end
53+
54+
it 'resolves callable values for authentication' do
55+
expect(described_class.authenticate('lambda_user', 'lambda_pass')).to be true
56+
end
57+
58+
it 'rejects incorrect credentials with callable values' do
59+
expect(described_class.authenticate('wrong', 'wrong')).to be false
60+
end
61+
end
4062
end
4163

4264
describe '.authentication_required?' do

0 commit comments

Comments
 (0)