erioon 0.0.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: erioon
3
- Version: 0.0.4
3
+ Version: 0.0.5
4
4
  Summary: Erioon SDF for Python
5
5
  Author: Zyber Pireci
6
6
  Author-email: zyber.pireci@erioon.com
@@ -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
- self.user_id = self._load_or_login()
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 _load_or_login(self):
58
+ def _do_login_and_cache(self):
55
59
  """
56
- Load cached user_id token from local storage or perform login if not cached.
60
+ Perform login to API and cache the metadata locally.
57
61
 
58
62
  Returns:
59
- str: User ID from token or fresh login.
60
-
61
- Raises:
62
- Exception: If login fails.
63
+ dict: Login metadata including user_id, database, cluster.
63
64
  """
64
- if os.path.exists(self.token_path):
65
- with open(self.token_path, "r") as f:
66
- token_data = json.load(f)
67
- user_id = token_data.get("user_id")
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 _do_login_and_cache(self):
70
+ def _load_or_login(self):
74
71
  """
75
- Perform login to API and cache the user_id token locally.
72
+ Load cached metadata or perform login.
76
73
 
77
74
  Returns:
78
- str: User ID from successful login.
79
-
80
- Raises:
81
- Exception: If login fails.
75
+ dict: Login metadata.
82
76
  """
83
- user_id = self._login()
84
- with open(self.token_path, "w") as f:
85
- json.dump({"user_id": user_id}, f)
86
- return user_id
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 with Erioon API using email and password.
87
+ Authenticate and return full login metadata.
91
88
 
92
89
  Returns:
93
- str: User ID on successful authentication.
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
- return response.text.strip()
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(self.user_id, db_info)
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()
@@ -8,6 +8,8 @@ class Collection:
8
8
  db_id,
9
9
  coll_id,
10
10
  metadata,
11
+ database,
12
+ cluster,
11
13
  base_url: str = "https://sdk.erioon.com",
12
14
  ):
13
15
  """
@@ -24,11 +26,17 @@ class Collection:
24
26
  self.db_id = db_id
25
27
  self.coll_id = coll_id
26
28
  self.metadata = metadata
29
+ self.database = database
30
+ self.cluster = cluster
27
31
  self.base_url = base_url.rstrip("/")
28
32
 
29
33
  def _print_loading(self) -> None:
30
34
  """Print a green loading message to the terminal."""
31
35
  print("Erioon is loading...")
36
+
37
+ def _is_read_only(self):
38
+ return self.database == "read"
39
+
32
40
 
33
41
  # ---------- READ ---------- #
34
42
  def get_all(self):
@@ -87,6 +95,9 @@ class Collection:
87
95
  result = collection.insert_one(new_doc)
88
96
  """
89
97
  self._print_loading()
98
+ if self._is_read_only():
99
+ return {"status": "KO", "error": "Method not allowed. Access is only read."}
100
+
90
101
  url = f"{self.base_url}/{self.user_id}/{self.db_id}/{self.coll_id}/insert_one"
91
102
  response = requests.post(url, json=document, headers={"Content-Type": "application/json"})
92
103
  try:
@@ -107,6 +118,9 @@ class Collection:
107
118
  result = collection.insert_many(docs)
108
119
  """
109
120
  self._print_loading()
121
+ if self._is_read_only():
122
+ return {"status": "KO", "error": "Method not allowed. Access is only read."}
123
+
110
124
  url = f"{self.base_url}/{self.user_id}/{self.db_id}/{self.coll_id}/insert_many"
111
125
  response = requests.post(url, json={"records": documents})
112
126
  try:
@@ -127,6 +141,9 @@ class Collection:
127
141
  result = collection.delete_one({"name": "John"})
128
142
  """
129
143
  self._print_loading()
144
+ if self._is_read_only():
145
+ return {"status": "KO", "error": "Method not allowed. Access is only read."}
146
+
130
147
  url = f"{self.base_url}/{self.user_id}/{self.db_id}/{self.coll_id}/delete_one"
131
148
  response = requests.delete(url, json=filter_query)
132
149
  try:
@@ -146,6 +163,9 @@ class Collection:
146
163
  result = collection.delete_many({"status": "inactive"})
147
164
  """
148
165
  self._print_loading()
166
+ if self._is_read_only():
167
+ return {"status": "KO", "error": "Method not allowed. Access is only read."}
168
+
149
169
  url = f"{self.base_url}/{self.user_id}/{self.db_id}/{self.coll_id}/delete_many"
150
170
  response = requests.delete(url, json=filter_query)
151
171
  try:
@@ -170,6 +190,9 @@ class Collection:
170
190
  )
171
191
  """
172
192
  self._print_loading()
193
+ if self._is_read_only():
194
+ return {"status": "KO", "error": "Method not allowed. Access is only read."}
195
+
173
196
  url = f"{self.base_url}/{self.user_id}/{self.db_id}/{self.coll_id}/update_query"
174
197
  response = requests.patch(url, json={"filter_query": filter_query, "update_query": update_query})
175
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
+
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: erioon
3
- Version: 0.0.4
3
+ Version: 0.0.5
4
4
  Summary: Erioon SDF for Python
5
5
  Author: Zyber Pireci
6
6
  Author-email: zyber.pireci@erioon.com
@@ -2,7 +2,7 @@ from setuptools import setup
2
2
 
3
3
  setup(
4
4
  name='erioon',
5
- version='0.0.4',
5
+ version='0.0.5',
6
6
  author='Zyber Pireci',
7
7
  author_email='zyber.pireci@erioon.com',
8
8
  description='Erioon SDF for Python',
File without changes
File without changes
File without changes
File without changes