Skip to content

Commit

Permalink
Fix credentials auth
Browse files Browse the repository at this point in the history
  • Loading branch information
pawurb committed Jan 4, 2025
1 parent 663cb45 commit 42869bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
27 changes: 11 additions & 16 deletions app/controllers/rails_pg_extras/web/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@

module RailsPgExtras::Web
class ApplicationController < ActionController::Base
def self.get_user
Rails.application.try(:credentials).try(:pg_extras).try(:user) || ENV["RAILS_PG_EXTRAS_USER"]
end

def self.get_password
Rails.application.try(:credentials).try(:pg_extras).try(:password) || ENV["RAILS_PG_EXTRAS_PASSWORD"]
end

before_action :validate_credentials!
layout "rails_pg_extras/web/application"

Expand All @@ -14,27 +22,14 @@ class ApplicationController < ActionController::Base

ACTIONS = %i[kill_all pg_stat_statements_reset add_extensions]

user = get_user
password = get_password

if user.present? && password.present?
http_basic_authenticate_with name: user, password: password
if get_user.present? && get_password.present?
http_basic_authenticate_with name: get_user, password: get_password
end

def validate_credentials!
if (get_user.blank? || get_password.blank?) && RailsPgExtras.configuration.public_dashboard != true
if (self.class.get_user.blank? || self.class.get_password.blank?) && RailsPgExtras.configuration.public_dashboard != true
raise "Missing credentials for rails-pg-extras dashboard! If you want to enable public dashboard please set RAILS_PG_EXTRAS_PUBLIC_DASHBOARD=true"
end
end

private

def get_user
Rails.application.try(:credentials).try(:pg_extras).try(:user) || ENV["RAILS_PG_EXTRAS_USER"]
end

def get_password
Rails.application.try(:credentials).try(:pg_extras).try(:password) || ENV["RAILS_PG_EXTRAS_PASSWORD"]
end
end
end
2 changes: 1 addition & 1 deletion lib/rails_pg_extras/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module RailsPgExtras
VERSION = "5.5.0"
VERSION = "5.5.1"
end

0 comments on commit 42869bb

Please sign in to comment.