rails-pg-extras 4.1.0 → 4.2.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: d6ae59243330e4542bce1091be0c9569e358136526ea8e3905f51926bc7e301a
4
- data.tar.gz: 3981ba3942d85a69bc808665df427fa4401754861707bc93176adc1ad03b49cf
3
+ metadata.gz: a246db60fafffa7ad4ea212b8357332d4172a58963c7f919a27ecbe75bf8e1ec
4
+ data.tar.gz: c2c5eab77af273048b3cd55a20ea675e78a78d19c6192eefdb87018278756660
5
5
  SHA512:
6
- metadata.gz: bffcc20a98ee3e0b7e127ef96f268500cf49fd3e30a009cf1d1ffbe88246524763f8b4c76df389969febf4d78d5b3c6bc51edacd18a2d5581b4ea86e314aa6a9
7
- data.tar.gz: 100bef0be5f9a22e90c81a37f75288e8833e9e7dccfccbaf88d0b0bb6870f49d083e5322e4705ae4961a2b8d085496e85a7e5253c2d57396c229194591cf62d7
6
+ metadata.gz: b3a8c40da52f09d8f2a8f77f05561e39d069b43a86986029e907bec04933868e64211554a7d342156a902a31357119cef76ec6e33bb2d5c71d4847a6a7be0d56
7
+ data.tar.gz: e660e4dad9b7a0b95f796e648521210d302edc16aff16e582f1c548cb408b7ab4a17ef00e4c016ae4fcfbfeae3e7c0a1bd261793af43c4383bb09abdcc71b361
data/README.md CHANGED
@@ -121,6 +121,17 @@ You can enable UI using a Rails engine by adding the following code in `config/r
121
121
 
122
122
  You can enable HTTP basic auth by specifying `RAILS_PG_EXTRAS_USER` and `RAILS_PG_EXTRAS_PASSWORD` variables.
123
123
 
124
+ You can configure available web actions in `config/initializers/rails_pg_extras.rb`:
125
+
126
+ ```ruby
127
+ RailsPgExtras.configure do |config|
128
+ # Rails-pg-extras does not enable all the web actions by default. You can check all available actions via `RailsPgExtras::Web::ACTIONS`.
129
+ # For example, you may want to enable the dangerous `kill_all` action.
130
+
131
+ config.enabled_web_actions = %i[kill_all pg_stat_statements_reset enable_extensions]
132
+ end
133
+ ```
134
+
124
135
  ## Available methods
125
136
 
126
137
  ### `table_info`
@@ -1,5 +1,7 @@
1
1
  module RailsPgExtras::Web
2
2
  class ActionsController < RailsPgExtras::Web::ApplicationController
3
+ before_action :validate_action!
4
+
3
5
  def kill_all
4
6
  run(:kill_all)
5
7
  end
@@ -14,6 +16,12 @@ module RailsPgExtras::Web
14
16
 
15
17
  private
16
18
 
19
+ def validate_action!
20
+ unless RailsPgExtras::Web.action_enabled?(action_name)
21
+ render plain: "Action '#{action_name}' is not enabled!", status: :forbidden
22
+ end
23
+ end
24
+
17
25
  def run(action)
18
26
  begin
19
27
  RailsPgExtras.run_query(query_name: action, in_format: :raw)
@@ -5,9 +5,11 @@
5
5
  <% end %>
6
6
  </div>
7
7
 
8
- <%= link_to "Enable extensions", add_extensions_action_path,
9
- method: "post",
10
- data: {
11
- confirm: "This command will enable following extensions: #{unavailable_extensions.keys.join(', ')}. Do you want to proceeed?"
12
- }, class: 'border p-3 bg-green-500 text-white hover:bg-green-600 font-bold rounded' %>
8
+ <% if RailsPgExtras::Web.action_enabled?(:enable_extensions) %>
9
+ <%= link_to "Enable extensions", add_extensions_action_path,
10
+ method: "post",
11
+ data: {
12
+ confirm: "This command will enable following extensions: #{unavailable_extensions.keys.join(', ')}. Do you want to proceeed?"
13
+ }, class: 'border p-3 bg-green-500 text-white hover:bg-green-600 font-bold rounded' %>
14
+ <% end %>
13
15
 
@@ -5,17 +5,21 @@
5
5
 
6
6
  <h1 class="font-bold text-xl my-5">Actions</h1>
7
7
 
8
- <%= link_to "kill_all", kill_all_action_path,
9
- method: "post",
10
- data: {
11
- confirm: "This commands kills all the currently active connections to the database. Do you want to proceed?"
12
- },
13
- class: 'border p-3 bg-red-500 text-white hover:bg-red-600 font-bold rounded'
14
- %>
8
+ <% if RailsPgExtras::Web.action_enabled?(:kill_all) %>
9
+ <%= link_to "kill_all", kill_all_action_path,
10
+ method: "post",
11
+ data: {
12
+ confirm: "This commands kills all the currently active connections to the database. Do you want to proceed?"
13
+ },
14
+ class: 'border p-3 bg-red-500 text-white hover:bg-red-600 font-bold rounded'
15
+ %>
16
+ <% end %>
15
17
 
16
- <%= link_to "pg_stat_statements_reset", pg_stat_statements_reset_action_path,
17
- method: "post",
18
- data: {
19
- confirm: "This command discards all statistics gathered so far by pg_stat_statements. Do you want to proceed?"
20
- }, class: 'border p-3 bg-blue-500 text-white hover:bg-blue-600 font-bold rounded'
21
- %>
18
+ <% if RailsPgExtras::Web.action_enabled?(:pg_stat_statements_reset) %>
19
+ <%= link_to "pg_stat_statements_reset", pg_stat_statements_reset_action_path,
20
+ method: "post",
21
+ data: {
22
+ confirm: "This command discards all statistics gathered so far by pg_stat_statements. Do you want to proceed?"
23
+ }, class: 'border p-3 bg-blue-500 text-white hover:bg-blue-600 font-bold rounded'
24
+ %>
25
+ <% end %>
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails_pg_extras/web"
4
+
5
+ module RailsPgExtras
6
+ class Configuration
7
+ DEFAULT_CONFIG = { enabled_web_actions: Web::ACTIONS - [:kill_all] }
8
+
9
+ attr_reader :enabled_web_actions
10
+
11
+ def initialize(attrs)
12
+ self.enabled_web_actions = attrs[:enabled_web_actions]
13
+ end
14
+
15
+ def enabled_web_actions=(*actions)
16
+ @enabled_web_actions = actions.flatten.map(&:to_sym)
17
+ end
18
+ end
19
+
20
+ def self.configuration
21
+ @configuration ||= Configuration.new(Configuration::DEFAULT_CONFIG)
22
+ end
23
+
24
+ def self.configure
25
+ yield(configuration)
26
+ end
27
+ end
@@ -8,7 +8,7 @@ namespace :pg_extras do
8
8
  ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
9
9
  else
10
10
  db_config_file = File.read('config/database.yml')
11
- db_config = YAML::load(ERB.new(db_config_file).result)
11
+ db_config = YAML::load(ERB.new(db_config_file).result, aliases: true)
12
12
  ActiveRecord::Base.establish_connection(db_config[Rails.env])
13
13
  end
14
14
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsPgExtras
4
- VERSION = "4.1.0"
4
+ VERSION = "4.2.0"
5
5
  end
@@ -2,5 +2,10 @@ require "rails_pg_extras/web/engine"
2
2
 
3
3
  module RailsPgExtras
4
4
  module Web
5
+ ACTIONS = %i[kill_all pg_stat_statements_reset enable_extensions].freeze
6
+
7
+ def self.action_enabled?(action_name)
8
+ RailsPgExtras.configuration.enabled_web_actions.include?(action_name.to_sym)
9
+ end
5
10
  end
6
11
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'terminal-table'
4
4
  require 'ruby_pg_extras'
5
+ require 'rails_pg_extras/configuration'
5
6
  require 'rails_pg_extras/diagnose_data'
6
7
  require 'rails_pg_extras/diagnose_print'
7
8
  require 'rails_pg_extras/index_info'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-pg-extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 4.1.0
19
+ version: 4.2.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.1.0
26
+ version: 4.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,7 @@ files:
94
94
  - config/routes.rb
95
95
  - docker-compose.yml.sample
96
96
  - lib/rails_pg_extras.rb
97
+ - lib/rails_pg_extras/configuration.rb
97
98
  - lib/rails_pg_extras/diagnose_data.rb
98
99
  - lib/rails_pg_extras/diagnose_print.rb
99
100
  - lib/rails_pg_extras/index_info.rb