erioon 0.0.3__tar.gz → 0.0.5__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.
- {erioon-0.0.3 → erioon-0.0.5}/PKG-INFO +1 -1
- {erioon-0.0.3 → erioon-0.0.5}/erioon/client.py +34 -32
- {erioon-0.0.3 → erioon-0.0.5}/erioon/collection.py +24 -4
- {erioon-0.0.3 → erioon-0.0.5}/erioon/database.py +8 -3
- {erioon-0.0.3 → erioon-0.0.5}/erioon.egg-info/PKG-INFO +1 -1
- {erioon-0.0.3 → erioon-0.0.5}/setup.py +1 -1
- {erioon-0.0.3 → erioon-0.0.5}/LICENSE +0 -0
- {erioon-0.0.3 → erioon-0.0.5}/README.md +0 -0
- {erioon-0.0.3 → erioon-0.0.5}/erioon/auth.py +0 -0
- {erioon-0.0.3 → erioon-0.0.5}/erioon.egg-info/SOURCES.txt +0 -0
- {erioon-0.0.3 → erioon-0.0.5}/erioon.egg-info/dependency_links.txt +0 -0
- {erioon-0.0.3 → erioon-0.0.5}/erioon.egg-info/requires.txt +0 -0
- {erioon-0.0.3 → erioon-0.0.5}/erioon.egg-info/top_level.txt +0 -0
- {erioon-0.0.3 → erioon-0.0.5}/setup.cfg +0 -0
@@ -35,7 +35,11 @@ class ErioonClient:
|
|
35
35
|
self.token_path = os.path.expanduser(f"~/.erioon_token_{self._safe_filename(email)}")
|
36
36
|
|
37
37
|
try:
|
38
|
-
|
38
|
+
metadata = self._load_or_login()
|
39
|
+
self.user_id = metadata.get("_id")
|
40
|
+
self.database = metadata.get("database")
|
41
|
+
self.cluster = metadata.get("cluster")
|
42
|
+
self.login_metadata = metadata
|
39
43
|
except Exception as e:
|
40
44
|
self.error = str(e)
|
41
45
|
|
@@ -51,49 +55,39 @@ class ErioonClient:
|
|
51
55
|
"""
|
52
56
|
return "".join(c if c.isalnum() else "_" for c in text)
|
53
57
|
|
54
|
-
def
|
58
|
+
def _do_login_and_cache(self):
|
55
59
|
"""
|
56
|
-
|
60
|
+
Perform login to API and cache the metadata locally.
|
57
61
|
|
58
62
|
Returns:
|
59
|
-
|
60
|
-
|
61
|
-
Raises:
|
62
|
-
Exception: If login fails.
|
63
|
+
dict: Login metadata including user_id, database, cluster.
|
63
64
|
"""
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
if user_id:
|
69
|
-
return user_id
|
70
|
-
|
71
|
-
return self._do_login_and_cache()
|
65
|
+
metadata = self._login()
|
66
|
+
with open(self.token_path, "w") as f:
|
67
|
+
json.dump(metadata, f)
|
68
|
+
return metadata
|
72
69
|
|
73
|
-
def
|
70
|
+
def _load_or_login(self):
|
74
71
|
"""
|
75
|
-
|
72
|
+
Load cached metadata or perform login.
|
76
73
|
|
77
74
|
Returns:
|
78
|
-
|
79
|
-
|
80
|
-
Raises:
|
81
|
-
Exception: If login fails.
|
75
|
+
dict: Login metadata.
|
82
76
|
"""
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
77
|
+
if os.path.exists(self.token_path):
|
78
|
+
with open(self.token_path, "r") as f:
|
79
|
+
metadata = json.load(f)
|
80
|
+
if "user_id" in metadata:
|
81
|
+
return metadata
|
82
|
+
|
83
|
+
return self._do_login_and_cache()
|
87
84
|
|
88
85
|
def _login(self):
|
89
86
|
"""
|
90
|
-
Authenticate
|
87
|
+
Authenticate and return full login metadata.
|
91
88
|
|
92
89
|
Returns:
|
93
|
-
|
94
|
-
|
95
|
-
Raises:
|
96
|
-
Exception: If credentials are invalid.
|
90
|
+
dict: Metadata with user_id, database, cluster, etc.
|
97
91
|
"""
|
98
92
|
url = f"{self.base_url}/login_with_credentials"
|
99
93
|
payload = {"email": self.email, "password": self.password}
|
@@ -101,10 +95,13 @@ class ErioonClient:
|
|
101
95
|
|
102
96
|
response = requests.post(url, json=payload, headers=headers)
|
103
97
|
if response.status_code == 200:
|
104
|
-
|
98
|
+
data = response.json()
|
99
|
+
self.login_metadata = data
|
100
|
+
return data
|
105
101
|
else:
|
106
102
|
raise Exception("Invalid account")
|
107
103
|
|
104
|
+
|
108
105
|
def _clear_cached_token(self):
|
109
106
|
"""
|
110
107
|
Remove cached token file and reset user_id to None.
|
@@ -172,7 +169,12 @@ class ErioonClient:
|
|
172
169
|
|
173
170
|
if response.status_code == 200:
|
174
171
|
db_info = response.json()
|
175
|
-
return Database(
|
172
|
+
return Database(
|
173
|
+
user_id=self.user_id,
|
174
|
+
metadata=db_info,
|
175
|
+
database=self.database,
|
176
|
+
cluster=self.cluster
|
177
|
+
)
|
176
178
|
else:
|
177
179
|
try:
|
178
180
|
error_json = response.json()
|
@@ -1,8 +1,5 @@
|
|
1
1
|
import json
|
2
2
|
import requests
|
3
|
-
from colorama import Fore, Style, init
|
4
|
-
|
5
|
-
init(autoreset=True)
|
6
3
|
|
7
4
|
class Collection:
|
8
5
|
def __init__(
|
@@ -11,6 +8,8 @@ class Collection:
|
|
11
8
|
db_id,
|
12
9
|
coll_id,
|
13
10
|
metadata,
|
11
|
+
database,
|
12
|
+
cluster,
|
14
13
|
base_url: str = "https://sdk.erioon.com",
|
15
14
|
):
|
16
15
|
"""
|
@@ -27,11 +26,17 @@ class Collection:
|
|
27
26
|
self.db_id = db_id
|
28
27
|
self.coll_id = coll_id
|
29
28
|
self.metadata = metadata
|
29
|
+
self.database = database
|
30
|
+
self.cluster = cluster
|
30
31
|
self.base_url = base_url.rstrip("/")
|
31
32
|
|
32
33
|
def _print_loading(self) -> None:
|
33
34
|
"""Print a green loading message to the terminal."""
|
34
|
-
print(
|
35
|
+
print("Erioon is loading...")
|
36
|
+
|
37
|
+
def _is_read_only(self):
|
38
|
+
return self.database == "read"
|
39
|
+
|
35
40
|
|
36
41
|
# ---------- READ ---------- #
|
37
42
|
def get_all(self):
|
@@ -90,6 +95,9 @@ class Collection:
|
|
90
95
|
result = collection.insert_one(new_doc)
|
91
96
|
"""
|
92
97
|
self._print_loading()
|
98
|
+
if self._is_read_only():
|
99
|
+
return {"status": "KO", "error": "Method not allowed. Access is only read."}
|
100
|
+
|
93
101
|
url = f"{self.base_url}/{self.user_id}/{self.db_id}/{self.coll_id}/insert_one"
|
94
102
|
response = requests.post(url, json=document, headers={"Content-Type": "application/json"})
|
95
103
|
try:
|
@@ -110,6 +118,9 @@ class Collection:
|
|
110
118
|
result = collection.insert_many(docs)
|
111
119
|
"""
|
112
120
|
self._print_loading()
|
121
|
+
if self._is_read_only():
|
122
|
+
return {"status": "KO", "error": "Method not allowed. Access is only read."}
|
123
|
+
|
113
124
|
url = f"{self.base_url}/{self.user_id}/{self.db_id}/{self.coll_id}/insert_many"
|
114
125
|
response = requests.post(url, json={"records": documents})
|
115
126
|
try:
|
@@ -130,6 +141,9 @@ class Collection:
|
|
130
141
|
result = collection.delete_one({"name": "John"})
|
131
142
|
"""
|
132
143
|
self._print_loading()
|
144
|
+
if self._is_read_only():
|
145
|
+
return {"status": "KO", "error": "Method not allowed. Access is only read."}
|
146
|
+
|
133
147
|
url = f"{self.base_url}/{self.user_id}/{self.db_id}/{self.coll_id}/delete_one"
|
134
148
|
response = requests.delete(url, json=filter_query)
|
135
149
|
try:
|
@@ -149,6 +163,9 @@ class Collection:
|
|
149
163
|
result = collection.delete_many({"status": "inactive"})
|
150
164
|
"""
|
151
165
|
self._print_loading()
|
166
|
+
if self._is_read_only():
|
167
|
+
return {"status": "KO", "error": "Method not allowed. Access is only read."}
|
168
|
+
|
152
169
|
url = f"{self.base_url}/{self.user_id}/{self.db_id}/{self.coll_id}/delete_many"
|
153
170
|
response = requests.delete(url, json=filter_query)
|
154
171
|
try:
|
@@ -173,6 +190,9 @@ class Collection:
|
|
173
190
|
)
|
174
191
|
"""
|
175
192
|
self._print_loading()
|
193
|
+
if self._is_read_only():
|
194
|
+
return {"status": "KO", "error": "Method not allowed. Access is only read."}
|
195
|
+
|
176
196
|
url = f"{self.base_url}/{self.user_id}/{self.db_id}/{self.coll_id}/update_query"
|
177
197
|
response = requests.patch(url, json={"filter_query": filter_query, "update_query": update_query})
|
178
198
|
try:
|
@@ -2,10 +2,12 @@ import json
|
|
2
2
|
from erioon.collection import Collection
|
3
3
|
|
4
4
|
class Database:
|
5
|
-
def __init__(self, user_id, metadata):
|
5
|
+
def __init__(self, user_id, metadata, database=None, cluster=None):
|
6
6
|
self.user_id = user_id
|
7
7
|
self.metadata = metadata
|
8
8
|
self.db_id = metadata.get("database_info", {}).get("_id")
|
9
|
+
self.database = database
|
10
|
+
self.cluster = cluster
|
9
11
|
|
10
12
|
def __getitem__(self, collection_id):
|
11
13
|
try:
|
@@ -19,7 +21,9 @@ class Database:
|
|
19
21
|
user_id=self.user_id,
|
20
22
|
db_id=self.db_id,
|
21
23
|
coll_id=collection_id,
|
22
|
-
metadata=coll_meta
|
24
|
+
metadata=coll_meta,
|
25
|
+
database = self.database,
|
26
|
+
cluster = self.cluster
|
23
27
|
)
|
24
28
|
except Exception:
|
25
29
|
return "Connection error"
|
@@ -28,4 +32,5 @@ class Database:
|
|
28
32
|
return json.dumps(self.metadata, indent=4)
|
29
33
|
|
30
34
|
def __repr__(self):
|
31
|
-
return f"<Database db_id={self.db_id}>"
|
35
|
+
return f"<Database db_id={self.db_id}, cluster={self.cluster}, database={self.database}>"
|
36
|
+
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|