query_guard 0.1.0 → 0.3.0
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 +4 -4
- data/README.md +53 -0
- data/lib/query_guard/config.rb +2 -1
- data/lib/query_guard/version.rb +1 -1
- data/lib/query_guard.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6bfc3581737fdfb115f1f3d59eaa678f061af78c561e0a03782eb019a46d4b3f
|
|
4
|
+
data.tar.gz: dc3e1b303ca6044f7e18af3fc2dbbd309f2bd4e1c7aa4c0751cedc89a08dc2c1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9bee2280297b23e229235ba461ec6c2c978a927e7dbb8f3c26270def1a5615b229948b50c483f2f9ac4c08c8546d96af1e355f8ae41acb032b52acaff7ef98c9
|
|
7
|
+
data.tar.gz: ddd6d8b867f91afbe91e941864e0d2a656c3442aed5d7a579702e969358e52b9a38d9667956d3640e57593a9f45dd16406892ceac19f1938f96c6bfe787ce6bf
|
data/README.md
CHANGED
|
@@ -8,3 +8,56 @@ Add to your Gemfile:
|
|
|
8
8
|
|
|
9
9
|
```ruby
|
|
10
10
|
gem "query_guard"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## ⚙️ Configuration File
|
|
14
|
+
|
|
15
|
+
To enable and configure `QueryGuard` in your Rails application,
|
|
16
|
+
you need to create an initializer file with the configuration options below.
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
### 1️⃣ Create the configuration file
|
|
21
|
+
|
|
22
|
+
Run this command inside your Rails app:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
touch config/initializers/query_guard.rb
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 2️⃣ Add the following code inside that file:
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
# config/initializers/query_guard.rb
|
|
32
|
+
|
|
33
|
+
# Configure QueryGuard settings
|
|
34
|
+
QueryGuard.configure do |config|
|
|
35
|
+
# Environments where QueryGuard should be active
|
|
36
|
+
# By default: [:development, :test]
|
|
37
|
+
config.enabled_environments = %i[development test]
|
|
38
|
+
|
|
39
|
+
# Maximum number of SQL queries allowed per request
|
|
40
|
+
# Use nil to disable this limit
|
|
41
|
+
config.max_queries_per_request = 100
|
|
42
|
+
|
|
43
|
+
# Maximum duration (milliseconds) for a single SQL query
|
|
44
|
+
# Logs as a slow query if exceeded
|
|
45
|
+
config.max_duration_ms_per_query = 100.0
|
|
46
|
+
|
|
47
|
+
# Whether to flag or block SELECT * statements
|
|
48
|
+
config.block_select_star = true
|
|
49
|
+
|
|
50
|
+
# Ignore certain SQL patterns (e.g., schema and transaction queries)
|
|
51
|
+
config.ignored_sql = [
|
|
52
|
+
/^PRAGMA /i, # SQLite schema queries
|
|
53
|
+
/^BEGIN/i,
|
|
54
|
+
/^COMMIT/i
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
# Raise exception on violation instead of just logging
|
|
58
|
+
config.raise_on_violation = false
|
|
59
|
+
|
|
60
|
+
# Prefix for log messages in Rails logs
|
|
61
|
+
config.log_prefix = "[QueryGuard]"
|
|
62
|
+
end
|
|
63
|
+
```
|
data/lib/query_guard/config.rb
CHANGED
|
@@ -3,7 +3,8 @@ module QueryGuard
|
|
|
3
3
|
class Config
|
|
4
4
|
attr_accessor :enabled_environments, :max_queries_per_request,
|
|
5
5
|
:max_duration_ms_per_query, :block_select_star,
|
|
6
|
-
:ignored_sql, :raise_on_violation, :log_prefix
|
|
6
|
+
:ignored_sql, :raise_on_violation, :log_prefix,
|
|
7
|
+
:base_url, :api_key, :project, :env
|
|
7
8
|
|
|
8
9
|
def initialize
|
|
9
10
|
@enabled_environments = %i[development test]
|
data/lib/query_guard/version.rb
CHANGED
data/lib/query_guard.rb
CHANGED
|
@@ -8,6 +8,8 @@ require "query_guard/middleware"
|
|
|
8
8
|
|
|
9
9
|
module QueryGuard
|
|
10
10
|
class << self
|
|
11
|
+
attr_accessor :client, :config
|
|
12
|
+
|
|
11
13
|
def config
|
|
12
14
|
@config ||= Config.new
|
|
13
15
|
end
|
|
@@ -17,6 +19,17 @@ module QueryGuard
|
|
|
17
19
|
self
|
|
18
20
|
end
|
|
19
21
|
|
|
22
|
+
def configure
|
|
23
|
+
config ||= Config.new
|
|
24
|
+
yield(config)
|
|
25
|
+
client = Client.new(
|
|
26
|
+
base_url: config.base_url,
|
|
27
|
+
api_key: config.api_key,
|
|
28
|
+
project: config.project,
|
|
29
|
+
env: config.env
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
20
33
|
def install!(app = nil)
|
|
21
34
|
# Install SQL subscriber once
|
|
22
35
|
Subscriber.install!(config)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: query_guard
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chitradevi36
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-11-
|
|
11
|
+
date: 2025-11-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|