erioon 0.0.4__py3-none-any.whl → 0.0.6__py3-none-any.whl

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/auth.py CHANGED
@@ -16,5 +16,5 @@ def Auth(credential_string):
16
16
  >>> client = Auth("<EMAIL>:<PASSWORD>")
17
17
  >>> print(client) # prints user_id if successful or error message if not
18
18
  """
19
- email, password = credential_string.split(":")
20
- return ErioonClient(email, password)
19
+ api, email, password = credential_string.split(":")
20
+ return ErioonClient(api ,email, password)
erioon/client.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import os
2
2
  import json
3
3
  import requests
4
+ from werkzeug.security import generate_password_hash
4
5
  from erioon.database import Database
5
6
 
6
7
  class ErioonClient:
@@ -18,7 +19,7 @@ class ErioonClient:
18
19
  token_path (str): Local path to cached authentication token.
19
20
  """
20
21
 
21
- def __init__(self, email, password, base_url="https://sdk.erioon.com"):
22
+ def __init__(self, api, email, password, base_url="https://sdk.erioon.com"):
22
23
  """
23
24
  Initialize ErioonClient instance, attempts to load cached token or perform login.
24
25
 
@@ -27,6 +28,7 @@ class ErioonClient:
27
28
  password (str): User password for authentication.
28
29
  base_url (str, optional): Base API URL. Defaults to "https://sdk.erioon.com".
29
30
  """
31
+ self.api = api
30
32
  self.email = email
31
33
  self.password = password
32
34
  self.base_url = base_url
@@ -35,7 +37,11 @@ class ErioonClient:
35
37
  self.token_path = os.path.expanduser(f"~/.erioon_token_{self._safe_filename(email)}")
36
38
 
37
39
  try:
38
- self.user_id = self._load_or_login()
40
+ metadata = self._load_or_login()
41
+ self.user_id = metadata.get("_id")
42
+ self.database = metadata.get("database")
43
+ self.cluster = metadata.get("cluster")
44
+ self.login_metadata = metadata
39
45
  except Exception as e:
40
46
  self.error = str(e)
41
47
 
@@ -51,60 +57,54 @@ class ErioonClient:
51
57
  """
52
58
  return "".join(c if c.isalnum() else "_" for c in text)
53
59
 
54
- def _load_or_login(self):
60
+ def _do_login_and_cache(self):
55
61
  """
56
- Load cached user_id token from local storage or perform login if not cached.
62
+ Perform login to API and cache the metadata locally.
57
63
 
58
64
  Returns:
59
- str: User ID from token or fresh login.
60
-
61
- Raises:
62
- Exception: If login fails.
65
+ dict: Login metadata including user_id, database, cluster.
63
66
  """
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()
67
+ metadata = self._login()
68
+ with open(self.token_path, "w") as f:
69
+ json.dump(metadata, f)
70
+ return metadata
72
71
 
73
- def _do_login_and_cache(self):
72
+ def _load_or_login(self):
74
73
  """
75
- Perform login to API and cache the user_id token locally.
74
+ Load cached metadata or perform login.
76
75
 
77
76
  Returns:
78
- str: User ID from successful login.
79
-
80
- Raises:
81
- Exception: If login fails.
77
+ dict: Login metadata.
82
78
  """
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
79
+ if os.path.exists(self.token_path):
80
+ with open(self.token_path, "r") as f:
81
+ metadata = json.load(f)
82
+ if "user_id" in metadata:
83
+ return metadata
84
+
85
+ return self._do_login_and_cache()
87
86
 
88
87
  def _login(self):
89
88
  """
90
- Authenticate with Erioon API using email and password.
89
+ Authenticate and return full login metadata.
91
90
 
92
91
  Returns:
93
- str: User ID on successful authentication.
94
-
95
- Raises:
96
- Exception: If credentials are invalid.
92
+ dict: Metadata with user_id, database, cluster, etc.
97
93
  """
98
94
  url = f"{self.base_url}/login_with_credentials"
99
- payload = {"email": self.email, "password": self.password}
95
+ hashed_key = generate_password_hash(self.api)
96
+ payload = {"api_key": hashed_key,"email": self.email, "password": self.password}
100
97
  headers = {"Content-Type": "application/json"}
101
98
 
102
99
  response = requests.post(url, json=payload, headers=headers)
103
100
  if response.status_code == 200:
104
- return response.text.strip()
101
+ data = response.json()
102
+ self.login_metadata = data
103
+ return data
105
104
  else:
106
105
  raise Exception("Invalid account")
107
106
 
107
+
108
108
  def _clear_cached_token(self):
109
109
  """
110
110
  Remove cached token file and reset user_id to None.
@@ -172,7 +172,12 @@ class ErioonClient:
172
172
 
173
173
  if response.status_code == 200:
174
174
  db_info = response.json()
175
- return Database(self.user_id, db_info)
175
+ return Database(
176
+ user_id=self.user_id,
177
+ metadata=db_info,
178
+ database=self.database,
179
+ cluster=self.cluster
180
+ )
176
181
  else:
177
182
  try:
178
183
  error_json = response.json()
erioon/collection.py CHANGED
@@ -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:
erioon/database.py CHANGED
@@ -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.6
4
4
  Summary: Erioon SDF for Python
5
5
  Author: Zyber Pireci
6
6
  Author-email: zyber.pireci@erioon.com
@@ -0,0 +1,9 @@
1
+ erioon/auth.py,sha256=zSMRnkoU2-5khZNYhcWb48PtYTbtYYbAI--ydrFeMbo,714
2
+ erioon/client.py,sha256=xFdzTJgZNo3RU7FStEqXVCKI8EjmOxlQG5HXjKm6nMU,6816
3
+ erioon/collection.py,sha256=i0mmOj79D02suXhTtfJA8yH-oM7JiHyehh574JHlJn0,7686
4
+ erioon/database.py,sha256=IjtZYJtQ-8shojxYwNKnN1ZaRwwWZfOhw3PDAgapE8w,1185
5
+ erioon-0.0.6.dist-info/LICENSE,sha256=xwnq3DNlZpQyteOK9HvtHRhMdYviXTTaCDljEodFRnQ,569
6
+ erioon-0.0.6.dist-info/METADATA,sha256=sJILmB27Ztfcpzt7cj0RFF1e6QBe9WrLpCGD6V58Sc4,715
7
+ erioon-0.0.6.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
8
+ erioon-0.0.6.dist-info/top_level.txt,sha256=yjKEg85X5Q5ot46IMML_xukvIGG5YfdrLWcemjalItc,7
9
+ erioon-0.0.6.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- erioon/auth.py,sha256=-a8g7JZKsQ_yir_iZMYbfhiBJT0hYDmfJSj6B1u3M84,704
2
- erioon/client.py,sha256=5VKxfHUdChwFRA1bRWCt6p10y1SF7XR1PWp6wt7qQgg,6532
3
- erioon/collection.py,sha256=f5Uw7-Y7-Il8uocUBVshNLTots2Ja3GQEO887vmImr4,6830
4
- erioon/database.py,sha256=n3arbUCYzJ1WAIh_1hgjJjUuCpyRVRP1quXGkTVgrsQ,953
5
- erioon-0.0.4.dist-info/LICENSE,sha256=xwnq3DNlZpQyteOK9HvtHRhMdYviXTTaCDljEodFRnQ,569
6
- erioon-0.0.4.dist-info/METADATA,sha256=mp2Pb68frefC8uz7pceZnKW7_NBaW5FmiGZdkS-Wffo,715
7
- erioon-0.0.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
8
- erioon-0.0.4.dist-info/top_level.txt,sha256=yjKEg85X5Q5ot46IMML_xukvIGG5YfdrLWcemjalItc,7
9
- erioon-0.0.4.dist-info/RECORD,,
File without changes