rails-pg-extras 4.0.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: a182232adb71ba714ab127505aa21e410291536a6f6992fed863e6beba4d11d6
4
- data.tar.gz: c219ee40b92eed9f873dc7a6fbe8e0cd80dd13e70cdd7048827b639d9dbd2f6f
3
+ metadata.gz: a246db60fafffa7ad4ea212b8357332d4172a58963c7f919a27ecbe75bf8e1ec
4
+ data.tar.gz: c2c5eab77af273048b3cd55a20ea675e78a78d19c6192eefdb87018278756660
5
5
  SHA512:
6
- metadata.gz: 82e1cd92bf47fb1588d49bb59fbf10ad5cd24c5878b5fec4025db301707936e6196f8af2ed27d384a5259349be5a6dbfdfc678b1e08ad029a37cc0de178d96ba
7
- data.tar.gz: 2d7189e0a3953323e5872ad817f015d3f023c90832fe9cf76d42485956f2868089bc9ae00532c377d54dc7f1f764832093cf19778d0f3be02f053eb9d19b9ad1
6
+ metadata.gz: b3a8c40da52f09d8f2a8f77f05561e39d069b43a86986029e907bec04933868e64211554a7d342156a902a31357119cef76ec6e33bb2d5c71d4847a6a7be0d56
7
+ data.tar.gz: e660e4dad9b7a0b95f796e648521210d302edc16aff16e582f1c548cb408b7ab4a17ef00e4c016ae4fcfbfeae3e7c0a1bd261793af43c4383bb09abdcc71b361
data/README.md CHANGED
@@ -10,7 +10,7 @@ You can read this blog post for detailed step by step tutorial on how to [optimi
10
10
 
11
11
  Optionally you can enable a visual interface:
12
12
 
13
- ![Web interface](https://github.com/pawurb/rails-pg-extras/raw/master/rails-pg-extras-web.png)
13
+ ![Web interface](https://github.com/pawurb/rails-pg-extras/raw/master/pg-extras-ui.png)
14
14
 
15
15
  Alternative versions:
16
16
 
@@ -119,7 +119,18 @@ 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
- On production environment 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.
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
+ ```
123
134
 
124
135
  ## Available methods
125
136
 
@@ -1,5 +1,7 @@
1
1
  module RailsPgExtras::Web
2
- class ActionsController < ApplicationController
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)
@@ -13,7 +13,7 @@ module RailsPgExtras::Web
13
13
 
14
14
  ACTIONS = %i[kill_all pg_stat_statements_reset add_extensions]
15
15
 
16
- if Rails.env.production? && ENV['RAILS_PG_EXTRAS_USER'].present? && ENV['RAILS_PG_EXTRAS_PASSWORD'].present?
16
+ if ENV['RAILS_PG_EXTRAS_USER'].present? && ENV['RAILS_PG_EXTRAS_PASSWORD'].present?
17
17
  http_basic_authenticate_with name: ENV['RAILS_PG_EXTRAS_USER'], password: ENV['RAILS_PG_EXTRAS_PASSWORD']
18
18
  end
19
19
  end
@@ -1,5 +1,5 @@
1
1
  module RailsPgExtras::Web
2
- class QueriesController < ApplicationController
2
+ class QueriesController < RailsPgExtras::Web::ApplicationController
3
3
  before_action :load_queries
4
4
  helper_method :unavailable_extensions
5
5
 
@@ -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.0.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'
data/pg-extras-ui.png ADDED
Binary file
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.0.0
4
+ version: 4.2.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-03-09 00:00:00.000000000 Z
11
+ date: 2022-03-12 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.0.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.0.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
@@ -105,8 +106,8 @@ files:
105
106
  - lib/rails_pg_extras/version.rb
106
107
  - lib/rails_pg_extras/web.rb
107
108
  - lib/rails_pg_extras/web/engine.rb
109
+ - pg-extras-ui.png
108
110
  - rails-pg-extras-diagnose.png
109
- - rails-pg-extras-web.png
110
111
  - rails-pg-extras.gemspec
111
112
  - spec/smoke_spec.rb
112
113
  - spec/spec_helper.rb
Binary file