rails-pg-extras 4.7.1 → 4.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72b8f131bed595bb673bf156b928606550291257e8aae9109fc6de77d1896fb6
4
- data.tar.gz: 3d44cef92f9ca6fe8e656ee3b0aeeb47209c866f95668d5f6c06c0a22bacd8e3
3
+ metadata.gz: cefaae16c6d92e4b1bd9af3d7b1dea9d1d0eb0a25079abb0d84e231ecb66ff31
4
+ data.tar.gz: fae04146f9c957bbd1eb530712aed98ad9fbcc82dd6c9103b740cda5f8598c11
5
5
  SHA512:
6
- metadata.gz: 46372ddaab387dfe89baaa342868fc7fff062235ada8baa9f6fc16e6f88edae5fb45140f370dae3f12ee39d70546a156e70c064405a7ef3db532557255592def
7
- data.tar.gz: db200cafb3c1eec8749aaf4b73b48312f0072a0dbc043f7f200839f0b69ab0a1b9093338ce14b762df6f549a3d6cb5af866e03fcbb7994956599e7df506d4826
6
+ metadata.gz: 2485ffb0a15f39c3459f97a778ec13a407e3b5c5a7a9b54892502a475856cb46bad649c1f2abd99cf25fda038c0fed57d086583032433ccc9b70505ee1cade78
7
+ data.tar.gz: a169a25a29e1eaf614ef00d90ffb43025103edcda957b77fd1585fa19a5c9a4f7b96e9fb30270a2aaa391b7d90e6504a96af3396fd4c7a473011e87565b683be
data/README.md CHANGED
@@ -119,7 +119,7 @@ You can enable UI using a Rails engine by adding the following code in `config/r
119
119
  mount RailsPgExtras::Web::Engine, at: 'pg_extras'
120
120
  ```
121
121
 
122
- You can enable HTTP basic auth by specifying `RAILS_PG_EXTRAS_USER` and `RAILS_PG_EXTRAS_PASSWORD` variables.
122
+ You can enable HTTP basic auth by specifying `RAILS_PG_EXTRAS_USER` and `RAILS_PG_EXTRAS_PASSWORD` variables. Authentication is mandatory unless you specify `RAILS_PG_EXTRAS_PUBLIC_DASHBOARD=true` or setting `RailsPgExtras.configuration.public_dashboard` to `true`.
123
123
 
124
124
  You can configure available web actions in `config/initializers/rails_pg_extras.rb`:
125
125
 
@@ -3,6 +3,7 @@ require "rails_pg_extras/version"
3
3
 
4
4
  module RailsPgExtras::Web
5
5
  class ApplicationController < ActionController::Base
6
+ before_action :validate_credentials!
6
7
  layout "rails_pg_extras/web/application"
7
8
 
8
9
  REQUIRED_EXTENSIONS = {
@@ -14,7 +15,13 @@ module RailsPgExtras::Web
14
15
  ACTIONS = %i[kill_all pg_stat_statements_reset add_extensions]
15
16
 
16
17
  if ENV['RAILS_PG_EXTRAS_USER'].present? && ENV['RAILS_PG_EXTRAS_PASSWORD'].present?
17
- http_basic_authenticate_with name: ENV['RAILS_PG_EXTRAS_USER'], password: ENV['RAILS_PG_EXTRAS_PASSWORD']
18
+ http_basic_authenticate_with name: ENV.fetch('RAILS_PG_EXTRAS_USER'), password: ENV.fetch('RAILS_PG_EXTRAS_PASSWORD')
19
+ end
20
+
21
+ def validate_credentials!
22
+ if (ENV['RAILS_PG_EXTRAS_USER'].blank? || ENV['RAILS_PG_EXTRAS_PASSWORD'].blank?) && !RailsPgExtras.configuration.public_dashboard
23
+ raise "Missing credentials for rails-pg-extras dashboard! If you want to enable public dashboard please set RAILS_PG_EXTRAS_PUBLIC_DASHBOARD=true"
24
+ end
18
25
  end
19
26
  end
20
27
  end
@@ -4,12 +4,14 @@ require "rails_pg_extras/web"
4
4
 
5
5
  module RailsPgExtras
6
6
  class Configuration
7
- DEFAULT_CONFIG = { enabled_web_actions: Web::ACTIONS - [:kill_all] }
7
+ DEFAULT_CONFIG = { enabled_web_actions: Web::ACTIONS - [:kill_all], public_dashboard: ENV["RAILS_PG_EXTRAS_PUBLIC_DASHBOARD"] == "true" }
8
8
 
9
9
  attr_reader :enabled_web_actions
10
+ attr_accessor :public_dashboard
10
11
 
11
12
  def initialize(attrs)
12
13
  self.enabled_web_actions = attrs[:enabled_web_actions]
14
+ self.public_dashboard = attrs[:public_dashboard]
13
15
  end
14
16
 
15
17
  def enabled_web_actions=(*actions)
@@ -3,35 +3,25 @@
3
3
  require 'rails-pg-extras'
4
4
 
5
5
  namespace :pg_extras do
6
- task :establish_connection do
7
- if ENV['DATABASE_URL'].present?
8
- ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
9
- else
10
- db_config_file = File.read('config/database.yml')
11
- db_config = YAML.safe_load(ERB.new(db_config_file).result, aliases: true)
12
- ActiveRecord::Base.establish_connection(db_config[Rails.env])
13
- end
14
- end
15
-
16
6
  RailsPgExtras::QUERIES.each do |query_name|
17
7
  desc RubyPgExtras.description_for(query_name: query_name)
18
- task query_name.to_sym => :establish_connection do
8
+ task query_name.to_sym => :environment do
19
9
  RailsPgExtras.public_send(query_name)
20
10
  end
21
11
  end
22
12
 
23
13
  desc "Generate a PostgreSQL healthcheck report"
24
- task diagnose: :establish_connection do
14
+ task diagnose: :environment do
25
15
  RailsPgExtras.diagnose
26
16
  end
27
17
 
28
18
  desc "Display tables metadata metrics"
29
- task table_info: :establish_connection do
19
+ task table_info: :environment do
30
20
  RailsPgExtras.table_info
31
21
  end
32
22
 
33
23
  desc "Display indexes metadata metrics"
34
- task index_info: :establish_connection do
24
+ task index_info: :environment do
35
25
  RailsPgExtras.index_info
36
26
  end
37
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsPgExtras
4
- VERSION = "4.7.1"
4
+ VERSION = "4.9.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-pg-extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.7.1
4
+ version: 4.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-08 00:00:00.000000000 Z
11
+ date: 2022-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-pg-extras
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 4.7.1
19
+ version: 4.9.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 4.7.1
26
+ version: 4.9.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement