-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote_connect.py
More file actions
77 lines (60 loc) · 2.06 KB
/
remote_connect.py
File metadata and controls
77 lines (60 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
"""
Remote connection example for RiceDB.
This script demonstrates connecting to a remote RiceDB instance
deployed on Kubernetes with Nginx Ingress.
"""
import os
from dotenv import load_dotenv
from ricedb.client.grpc_client import GrpcRiceDBClient
load_dotenv()
HOST = os.environ.get("HOST", "localhost")
PORT = int(os.environ.get("PORT", "50051"))
PASSWORD = os.environ.get("PASSWORD", "admin")
SSL = os.environ.get("SSL", "false").lower() == "true"
def main():
print(" RiceDB Remote Connection Example\n")
print(f"1 Connecting to {HOST}:{PORT} (SSL={SSL})...")
# Initialize client directly to see errors
client = GrpcRiceDBClient(host=HOST, port=PORT)
client.ssl = SSL
# Try with certifi properly
import certifi
import os
os.environ["GRPC_DEFAULT_SSL_ROOTS_FILE_PATH"] = certifi.where()
try:
# Calling connect directly will raise exception if it fails
client.connect()
print(f" Connected via gRPC")
# Login
print("\n2 Logging in as Admin...")
try:
client.login("admin", PASSWORD)
print(" Logged in successfully")
except Exception as e:
print(f" Login failed: {e}")
return
# Check health
print("\n3 Checking server health...")
health = client.health()
print(f" Status: {health.get('status')}")
print(f" Version: {health.get('version')}")
# Basic operation
print("\n4 Performing test insert...")
try:
result = client.insert_text(
node_id=999,
text="Remote connection test",
metadata={"source": "remote_script"},
user_id=1,
)
print(f" Insert result: {result.get('message', 'Success')}")
except Exception as e:
print(f" Insert failed: {e}")
except Exception as e:
print(f" Error: {e}")
finally:
client.disconnect()
print("\n Disconnected")
if __name__ == "__main__":
main()