sql-data-guard 0.1.7__tar.gz → 0.1.8__tar.gz
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.
- {sql_data_guard-0.1.7/src/sql_data_guard.egg-info → sql_data_guard-0.1.8}/PKG-INFO +1 -1
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/pyproject.toml +1 -1
- sql_data_guard-0.1.8/src/sql_data_guard/mcpwrapper/mcp_wrapper.py +86 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/src/sql_data_guard/restriction_verification.py +2 -2
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8/src/sql_data_guard.egg-info}/PKG-INFO +1 -1
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/src/sql_data_guard.egg-info/SOURCES.txt +1 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/test/test_sql_guard_validation_unit.py +1 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/LICENSE.md +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/README.md +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/setup.cfg +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/src/sql_data_guard/__init__.py +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/src/sql_data_guard/rest/__init__.py +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/src/sql_data_guard/rest/sql_data_guard_rest.py +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/src/sql_data_guard/restriction_validation.py +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/src/sql_data_guard/sql_data_guard.py +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/src/sql_data_guard/verification_context.py +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/src/sql_data_guard/verification_utils.py +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/src/sql_data_guard.egg-info/dependency_links.txt +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/src/sql_data_guard.egg-info/requires.txt +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/src/sql_data_guard.egg-info/top_level.txt +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/test/test_duckdb_unit.py +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/test/test_rest_api_unit.py +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/test/test_sql_guard_curr_unit.py +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/test/test_sql_guard_joins_unit.py +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/test/test_sql_guard_llm.py +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/test/test_sql_guard_unit.py +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/test/test_sql_guard_updates_unit.py +0 -0
- {sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/test/test_utils.py +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
import threading
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
import docker
|
|
8
|
+
from sql_data_guard import verify_sql
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def load_config() -> dict:
|
|
12
|
+
return json.load(open("/conf/config.json"))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def start_inner_container():
|
|
16
|
+
client = docker.from_env()
|
|
17
|
+
container = client.containers.run(
|
|
18
|
+
config["mcp-server"]["image"],
|
|
19
|
+
" ".join(config["mcp-server"]["args"]),
|
|
20
|
+
volumes=[
|
|
21
|
+
v.replace("$PWD", os.environ["PWD"])
|
|
22
|
+
for v in config["mcp-server"]["volumes"]
|
|
23
|
+
],
|
|
24
|
+
stdin_open=True,
|
|
25
|
+
auto_remove=True,
|
|
26
|
+
detach=True,
|
|
27
|
+
stdout=True,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
def stream_output():
|
|
31
|
+
for line in container.logs(stream=True):
|
|
32
|
+
sys.stdout.write(line.decode("utf-8"))
|
|
33
|
+
sys.stdout.flush()
|
|
34
|
+
|
|
35
|
+
threading.Thread(target=stream_output, daemon=True).start()
|
|
36
|
+
return container
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def main():
|
|
40
|
+
container = start_inner_container()
|
|
41
|
+
|
|
42
|
+
try:
|
|
43
|
+
socket = container.attach_socket(params={"stdin": True, "stream": True})
|
|
44
|
+
# noinspection PyProtectedMember
|
|
45
|
+
socket._sock.setblocking(True)
|
|
46
|
+
for line in sys.stdin:
|
|
47
|
+
line = input_line(line)
|
|
48
|
+
# noinspection PyProtectedMember
|
|
49
|
+
socket._sock.sendall(line.encode("utf-8"))
|
|
50
|
+
except (KeyboardInterrupt, EOFError):
|
|
51
|
+
pass
|
|
52
|
+
finally:
|
|
53
|
+
container.stop()
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def get_sql(json_line: dict) -> Optional[str]:
|
|
57
|
+
sys.stderr.write(f"json_line: {json_line}\n")
|
|
58
|
+
if json_line["method"] == "tools/call":
|
|
59
|
+
for tool in config["mcp-tools"]:
|
|
60
|
+
if tool["tool-name"] == json_line["params"]["name"]:
|
|
61
|
+
return json_line["params"]["arguments"][tool["arg-name"]]
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def input_line(line: str) -> str:
|
|
66
|
+
json_line = json.loads(line.encode("utf-8"))
|
|
67
|
+
sql = get_sql(json_line)
|
|
68
|
+
if sql:
|
|
69
|
+
result = verify_sql(
|
|
70
|
+
sql,
|
|
71
|
+
config["sql-data-guard"],
|
|
72
|
+
config["sql-data-guard"]["dialect"],
|
|
73
|
+
)
|
|
74
|
+
if not result["allowed"]:
|
|
75
|
+
sys.stderr.write(f"Blocked SQL: {sql}\nErrors: {list(result['errors'])}\n")
|
|
76
|
+
updated_sql = "SELECT 'Blocked by SQL Data Guard' AS message"
|
|
77
|
+
for error in result["errors"]:
|
|
78
|
+
updated_sql += f"\nUNION ALL SELECT '{error}' AS message"
|
|
79
|
+
json_line["params"]["arguments"]["query"] = updated_sql
|
|
80
|
+
line = json.dumps(json_line) + "\n"
|
|
81
|
+
return line
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
if __name__ == "__main__":
|
|
85
|
+
config = load_config()
|
|
86
|
+
main()
|
{sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/src/sql_data_guard/restriction_verification.py
RENAMED
|
@@ -3,8 +3,8 @@ from typing import List
|
|
|
3
3
|
import sqlglot
|
|
4
4
|
import sqlglot.expressions as expr
|
|
5
5
|
|
|
6
|
-
from
|
|
7
|
-
from
|
|
6
|
+
from .verification_context import VerificationContext
|
|
7
|
+
from .verification_utils import split_to_expressions
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
def verify_restrictions(
|
|
@@ -12,6 +12,7 @@ src/sql_data_guard.egg-info/SOURCES.txt
|
|
|
12
12
|
src/sql_data_guard.egg-info/dependency_links.txt
|
|
13
13
|
src/sql_data_guard.egg-info/requires.txt
|
|
14
14
|
src/sql_data_guard.egg-info/top_level.txt
|
|
15
|
+
src/sql_data_guard/mcpwrapper/mcp_wrapper.py
|
|
15
16
|
src/sql_data_guard/rest/__init__.py
|
|
16
17
|
src/sql_data_guard/rest/sql_data_guard_rest.py
|
|
17
18
|
test/test_duckdb_unit.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/src/sql_data_guard/rest/sql_data_guard_rest.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sql_data_guard-0.1.7 → sql_data_guard-0.1.8}/src/sql_data_guard.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|