diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a6968c..4fa24e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [1.2.1] - 2026-03-17 + +### Added + +- 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)) +- Initializer template now shows ENV variable and Lambda examples for credentials + ## [1.2.0] - 2026-03-07 ### Changed diff --git a/Gemfile.lock b/Gemfile.lock index 2932e71..00bdca7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - solid_queue_monitor (1.2.0) + solid_queue_monitor (1.2.1) rails (>= 7.0) solid_queue (>= 0.1.0) diff --git a/README.md b/README.md index 7ee1038..bffb890 100644 --- a/README.md +++ b/README.md @@ -104,9 +104,11 @@ SolidQueueMonitor.setup do |config| config.authentication_enabled = false # Set the username for HTTP Basic Authentication (only used if authentication is enabled) + # Supports static values, ENV variables, or callables (Proc/Lambda) config.username = 'admin' # Set the password for HTTP Basic Authentication (only used if authentication is enabled) + # Supports static values, ENV variables, or callables (Proc/Lambda) config.password = 'password' # Number of jobs to display per page @@ -141,7 +143,21 @@ By default, Solid Queue Monitor does not require authentication to access the da For production environments, it's strongly recommended to enable authentication: 1. **Enable authentication**: Set `config.authentication_enabled = true` in the initializer -2. **Configure secure credentials**: Set `username` and `password` to strong values in the initializer +2. **Configure secure credentials** using any of these approaches: + +```ruby +# Static values +config.username = 'admin' +config.password = 'secure_password' + +# Environment variables +config.username = ENV['SOLID_QUEUE_MONITOR_USERNAME'] +config.password = ENV['SOLID_QUEUE_MONITOR_PASSWORD'] + +# Rails credentials (use a lambda for deferred evaluation) +config.username = -> { Rails.application.credentials.dig(:solid_queue_monitor, :username) } +config.password = -> { Rails.application.credentials.dig(:solid_queue_monitor, :password) } +``` ## Usage diff --git a/lib/generators/solid_queue_monitor/templates/initializer.rb b/lib/generators/solid_queue_monitor/templates/initializer.rb index 3e56296..14a0ae0 100644 --- a/lib/generators/solid_queue_monitor/templates/initializer.rb +++ b/lib/generators/solid_queue_monitor/templates/initializer.rb @@ -7,9 +7,13 @@ # Set the username for HTTP Basic Authentication (only used if authentication is enabled) # config.username = 'admin' + # config.username = ENV['SOLID_QUEUE_MONITOR_USERNAME'] + # config.username = -> { Rails.application.credentials.dig(:solid_queue_monitor, :username) } # Set the password for HTTP Basic Authentication (only used if authentication is enabled) # config.password = 'password' + # config.password = ENV['SOLID_QUEUE_MONITOR_PASSWORD'] + # config.password = -> { Rails.application.credentials.dig(:solid_queue_monitor, :password) } # Number of jobs to display per page # config.jobs_per_page = 25 diff --git a/lib/solid_queue_monitor.rb b/lib/solid_queue_monitor.rb index ddc7b83..daf912b 100644 --- a/lib/solid_queue_monitor.rb +++ b/lib/solid_queue_monitor.rb @@ -6,8 +6,23 @@ module SolidQueueMonitor class Error < StandardError; end class << self - attr_accessor :username, :password, :jobs_per_page, :authentication_enabled, + attr_writer :username, :password + attr_accessor :jobs_per_page, :authentication_enabled, :auto_refresh_enabled, :auto_refresh_interval, :show_chart + + def username + resolve_value(@username) + end + + def password + resolve_value(@password) + end + + private + + def resolve_value(value) + value.respond_to?(:call) ? value.call : value + end end @username = 'admin' diff --git a/lib/solid_queue_monitor/version.rb b/lib/solid_queue_monitor/version.rb index 82420dd..c15a1a8 100644 --- a/lib/solid_queue_monitor/version.rb +++ b/lib/solid_queue_monitor/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module SolidQueueMonitor - VERSION = '1.2.0' + VERSION = '1.2.1' end diff --git a/spec/services/solid_queue_monitor/authentication_service_spec.rb b/spec/services/solid_queue_monitor/authentication_service_spec.rb index cbb88cf..0d70020 100644 --- a/spec/services/solid_queue_monitor/authentication_service_spec.rb +++ b/spec/services/solid_queue_monitor/authentication_service_spec.rb @@ -37,6 +37,28 @@ expect(described_class.authenticate('wrong', 'wrong')).to be false end end + + context 'when credentials are configured with callables' do + before do + SolidQueueMonitor.authentication_enabled = true + SolidQueueMonitor.username = -> { 'lambda_user' } + SolidQueueMonitor.password = -> { 'lambda_pass' } + end + + after do + SolidQueueMonitor.authentication_enabled = false + SolidQueueMonitor.username = 'admin' + SolidQueueMonitor.password = 'password' + end + + it 'resolves callable values for authentication' do + expect(described_class.authenticate('lambda_user', 'lambda_pass')).to be true + end + + it 'rejects incorrect credentials with callable values' do + expect(described_class.authenticate('wrong', 'wrong')).to be false + end + end end describe '.authentication_required?' do