dbviewer 0.7.5 → 0.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 27da0a6d3d08f2a6d1a597c1f7e688a54ffec7048e135b30a605ee3ace20370e
4
- data.tar.gz: 2e59f9c1c69b2bb87c7d9a351a045cfaea9709dc49ce7651d8ef24821db43aa7
3
+ metadata.gz: ce8d012a4b4e0bde526cf42fa8a40dd1402a2f787ae06381dbf3b6bfeef1dad1
4
+ data.tar.gz: 49a0b962162fadbdbe51feade176aaf51d211126f45295cf6df5b4f4614d019c
5
5
  SHA512:
6
- metadata.gz: 48a192e9bdd118358734a2b5008a87e7219fb224b95c897601b5e448c513027b4d14b816d9abcef3950540cb99cb97af991a3f58325359592179e8dc9e2d0752
7
- data.tar.gz: f3dacb78ba4309d724c7c469e4ff00457921e97d567f808a14cfe48efb38d45fadee7303f31c8f6e326037f8de27783302561acd0b84e4d42487bada7da8fed8
6
+ metadata.gz: 76520c547bb120caed2093b6138c55f818c6fd9bbbcdff534ea208af050e721b2319179b69710480330783db884d8f1e6bd661ed807c91599717a90811f449fd
7
+ data.tar.gz: ba7080bc4598a5e3cf07bede7181ff91e2ab687d43c5583b616f7fa8edc14c1cd871ef9e27764a7ef6cddd94617c4433949328e46f19ec88442d9cc1af2edfbf
data/README.md CHANGED
@@ -116,6 +116,9 @@ Dbviewer.configure do |config|
116
116
 
117
117
  # Authentication options
118
118
  # config.admin_credentials = { username: "admin", password: "your_secure_password" } # Basic HTTP auth credentials
119
+
120
+ # Disable DBViewer completely
121
+ # config.disabled = Rails.env.production? # Disable in production
119
122
  end
120
123
  ```
121
124
 
@@ -123,6 +126,34 @@ You can also create this file manually if you prefer.
123
126
 
124
127
  The configuration is accessed through `Dbviewer.configuration` throughout the codebase. You can also access it via `Dbviewer.config` which is an alias for backward compatibility.
125
128
 
129
+ ### Disabling DBViewer Completely
130
+
131
+ You can completely disable DBViewer access by setting the `disabled` configuration option to `true`. When disabled, all DBViewer routes will return 404 (Not Found) responses:
132
+
133
+ ```ruby
134
+ # config/initializers/dbviewer.rb
135
+ Dbviewer.configure do |config|
136
+ # Completely disable DBViewer in production
137
+ config.disabled = Rails.env.production?
138
+
139
+ # Or disable unconditionally
140
+ # config.disabled = true
141
+ end
142
+ ```
143
+
144
+ This is useful for:
145
+
146
+ - **Production environments** where you want to completely disable access to database viewing tools
147
+ - **Security compliance** where database admin tools must be disabled in certain environments
148
+ - **Performance** where you want to eliminate any potential overhead from DBViewer routes
149
+
150
+ When disabled:
151
+
152
+ - All DBViewer routes return 404 (Not Found) responses
153
+ - No database connections are validated
154
+ - No DBViewer middleware or concerns are executed
155
+ - The application behaves as if DBViewer was never mounted
156
+
126
157
  ### Multiple Database Connections
127
158
 
128
159
  DBViewer supports working with multiple database connections in your application. This is useful for applications that connect to multiple databases or use different connection pools.
@@ -195,6 +226,7 @@ DBViewer includes several security features to protect your database:
195
226
  - **Pattern Detection**: Detection of SQL injection patterns and suspicious constructs
196
227
  - **Error Handling**: Informative error messages without exposing sensitive information
197
228
  - **HTTP Basic Authentication**: Protect access with username and password authentication
229
+ - **Complete Disabling**: Completely disable DBViewer in production or sensitive environments
198
230
 
199
231
  ### Basic Authentication
200
232
 
@@ -212,6 +244,19 @@ end
212
244
  When credentials are provided, all DBViewer routes will be protected by HTTP Basic Authentication.
213
245
  Without valid credentials, users will be prompted for a username and password before they can access any DBViewer page.
214
246
 
247
+ ### Complete Disabling
248
+
249
+ For maximum security in production environments, you can completely disable DBViewer:
250
+
251
+ ```ruby
252
+ Dbviewer.configure do |config|
253
+ # Completely disable DBViewer in production
254
+ config.disabled = Rails.env.production?
255
+ end
256
+ ```
257
+
258
+ When disabled, all DBViewer routes return 404 responses, making it appear as if the tool was never installed. This is the recommended approach for production systems where database admin tools should not be accessible.
259
+
215
260
  ## 📝 Security Note
216
261
 
217
262
  ⚠️ **Warning**: This engine provides direct access to your database contents, which contains sensitive information. Always protect it with HTTP Basic Authentication by configuring strong credentials as shown above.
@@ -0,0 +1,26 @@
1
+ module Dbviewer
2
+ module DatabaseConnectionValidation
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_action :validate_database_connection
7
+ end
8
+
9
+ private
10
+
11
+ # Validate database connections on first access to DBViewer
12
+ def validate_database_connection
13
+ return if @database_validated
14
+
15
+ begin
16
+ connection_errors = Dbviewer.validate_connections!
17
+ if connection_errors.any?
18
+ Rails.logger.warn "DBViewer: Some database connections failed: #{connection_errors.map { |e| e[:error] }.join(', ')}"
19
+ end
20
+ @database_validated = true
21
+ rescue => e
22
+ render json: { error: "Database connection failed: #{e.message}" }, status: :service_unavailable and return
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ module Dbviewer
2
+ module DisabledStateValidation
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ before_action :check_if_dbviewer_disabled
7
+ end
8
+
9
+ private
10
+
11
+ # Check if DBViewer is completely disabled
12
+ def check_if_dbviewer_disabled
13
+ if Dbviewer.configuration.disabled
14
+ Rails.logger.info "DBViewer: Access denied - DBViewer is disabled"
15
+ render plain: "Not Found", status: :not_found and return
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,6 +1,8 @@
1
1
  module Dbviewer
2
2
  class ApplicationController < ActionController::Base
3
3
  include Dbviewer::DatabaseOperations
4
+ include Dbviewer::DisabledStateValidation
5
+ include Dbviewer::DatabaseConnectionValidation
4
6
 
5
7
  before_action :authenticate_with_basic_auth
6
8
  before_action :set_tables
@@ -51,6 +51,14 @@ module Dbviewer
51
51
  # The key of the current active connection
52
52
  attr_accessor :current_connection
53
53
 
54
+ # Whether to validate database connections during application startup
55
+ # Set to false in production/CI environments to avoid startup failures
56
+ attr_accessor :validate_connections_on_startup
57
+
58
+ # Completely disable DBViewer access when set to true
59
+ # When enabled, all DBViewer routes will return 404 responses
60
+ attr_accessor :disabled
61
+
54
62
  def initialize
55
63
  @per_page_options = [ 10, 20, 50, 100 ]
56
64
  @default_per_page = 20
@@ -65,6 +73,8 @@ module Dbviewer
65
73
  @enable_query_logging = true
66
74
  @admin_credentials = nil
67
75
  @default_order_column = "updated_at"
76
+ @validate_connections_on_startup = false # Default to false for safer deployments
77
+ @disabled = false # Default to false - DBViewer is enabled by default
68
78
  @database_connections = {
69
79
  default: {
70
80
  connection_class: "ActiveRecord::Base",
@@ -187,13 +187,20 @@ module Dbviewer
187
187
  connection_config = Dbviewer.configuration.database_connections[@connection_key]
188
188
 
189
189
  if connection_config && connection_config[:connection_class]
190
- @connection = connection_config[:connection_class].constantize.connection
190
+ begin
191
+ @connection = connection_config[:connection_class].constantize.connection
192
+ @adapter_name = @connection.adapter_name.downcase
193
+ Rails.logger.info "DBViewer: Successfully connected to #{connection_config[:name] || @connection_key} database (#{@adapter_name})"
194
+ rescue => e
195
+ Rails.logger.error "DBViewer: Failed to connect to #{connection_config[:name] || @connection_key}: #{e.message}"
196
+ raise "DBViewer database connection failed: #{e.message}"
197
+ end
191
198
  else
192
199
  Rails.logger.warn "DBViewer: Using default connection for key: #{@connection_key}"
193
200
  @connection = ActiveRecord::Base.connection
201
+ @adapter_name = @connection.adapter_name.downcase
194
202
  end
195
203
 
196
- @adapter_name = @connection.adapter_name.downcase
197
204
  @connection
198
205
  end
199
206
  end
@@ -1,3 +1,3 @@
1
1
  module Dbviewer
2
- VERSION = "0.7.5"
2
+ VERSION = "0.7.6"
3
3
  end
data/lib/dbviewer.rb CHANGED
@@ -56,7 +56,21 @@ module Dbviewer
56
56
  # This class method will be called by the engine when it's appropriate
57
57
  def setup
58
58
  configure_query_logger
59
- validate_database_connections
59
+ # Database connections will be validated when first accessed
60
+ Rails.logger.info "DBViewer: Initialized successfully (database connections will be validated on first access)"
61
+ end
62
+
63
+ # Validate database connections on-demand (called when first accessing DBViewer)
64
+ def validate_connections!
65
+ connection_errors = configuration.database_connections.filter_map do |key, config|
66
+ validate_single_connection(key, config)
67
+ end
68
+
69
+ if connection_errors.length == configuration.database_connections.length
70
+ raise "DBViewer could not connect to any configured database. Please check your database configuration."
71
+ end
72
+
73
+ connection_errors
60
74
  end
61
75
 
62
76
  private
@@ -69,15 +83,6 @@ module Dbviewer
69
83
  )
70
84
  end
71
85
 
72
- # Validate all configured database connections
73
- def validate_database_connections
74
- connection_errors = configuration.database_connections.filter_map do |key, config|
75
- validate_single_connection(key, config)
76
- end
77
-
78
- raise_if_all_connections_failed(connection_errors)
79
- end
80
-
81
86
  # Validate a single database connection
82
87
  # @param key [Symbol] The connection key
83
88
  # @param config [Hash] The connection configuration
@@ -125,13 +130,5 @@ module Dbviewer
125
130
  def store_resolved_connection(config, connection_class)
126
131
  config[:connection] = connection_class
127
132
  end
128
-
129
- # Raise an error if all database connections failed
130
- # @param connection_errors [Array] Array of connection error hashes
131
- def raise_if_all_connections_failed(connection_errors)
132
- if connection_errors.length == configuration.database_connections.length
133
- raise "DBViewer could not connect to any configured database"
134
- end
135
- end
136
133
  end
137
134
  end
@@ -33,4 +33,13 @@ Dbviewer.configure do |config|
33
33
 
34
34
  # Set the default active connection
35
35
  # config.current_connection = :primary
36
+
37
+ # Whether to validate database connections during application startup
38
+ # Set to true in development, false in production to avoid deployment issues
39
+ config.validate_connections_on_startup = Rails.env.development?
40
+
41
+ # Completely disable DBViewer access when set to true
42
+ # When enabled, all DBViewer routes will return 404 responses
43
+ # Useful for production environments where you want to completely disable the tool
44
+ # config.disabled = Rails.env.production?
36
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbviewer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wailan Tirajoh
@@ -77,9 +77,11 @@ files:
77
77
  - app/assets/stylesheets/dbviewer/table.css
78
78
  - app/controllers/concerns/dbviewer/connection_management.rb
79
79
  - app/controllers/concerns/dbviewer/data_export.rb
80
+ - app/controllers/concerns/dbviewer/database_connection_validation.rb
80
81
  - app/controllers/concerns/dbviewer/database_information.rb
81
82
  - app/controllers/concerns/dbviewer/database_operations.rb
82
83
  - app/controllers/concerns/dbviewer/datatable_support.rb
84
+ - app/controllers/concerns/dbviewer/disabled_state_validation.rb
83
85
  - app/controllers/concerns/dbviewer/pagination_concern.rb
84
86
  - app/controllers/concerns/dbviewer/query_operations.rb
85
87
  - app/controllers/concerns/dbviewer/relationship_management.rb