From 49764116a801b0c6919610961dec29f6499391e7 Mon Sep 17 00:00:00 2001 From: Onur Atakan ULUSOY Date: Wed, 13 Dec 2023 19:17:25 +0300 Subject: [PATCH] Added meta datas --- .gitignore | 1 + upsonic/remote/controller.py | 26 ++++++++++++++--- upsonic/remote/interface.py | 54 +++++++++++++++++++++++++++++------- 3 files changed, 67 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index e627109..59db2ab 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ Upsonic-*/ +upsonic_cache/ .vscode test_backup diff --git a/upsonic/remote/controller.py b/upsonic/remote/controller.py index 95d8eb1..0d3685d 100644 --- a/upsonic/remote/controller.py +++ b/upsonic/remote/controller.py @@ -26,11 +26,13 @@ def __enter__(self): def __exit__(self, exc_type, exc_val, exc_tb): pass # pragma: no cover - def __init__(self, database_name, api_url, password=None, enable_hashing:bool=False, verify=True, locking=False, client_id=None, cache=False, cache_counter=None, version=False, client_version=False, key_encyption=False): + def __init__(self, database_name, api_url, password=None, enable_hashing:bool=False, verify=True, locking=False, client_id=None, cache=False, cache_counter=None, version=False, client_version=False, key_encyption=False, meta_datas = True): import requests from requests.auth import HTTPBasicAuth + self.meta_datas = meta_datas + self.force_compress = False self.force_encrypt = False self.key_encyption = key_encyption @@ -303,12 +305,26 @@ def unlock_key(self, key): return False + def _update_set(self, key, meta): + if self.meta_datas: + return self.set(key+"_upsonic_meta", meta, update_operation=True, encryption_key=None) + + + + def set(self, key, value, encryption_key="a", compress=None, cache_policy=0, locking_operation=False, update_operation=False, version_tag=None, no_version=False): if not locking_operation: if self.lock_control(key): self.console.log(f"[bold red] '{key}' is locked") return None + the_type = type(value).__name__ + if the_type == "type": + the_type = "class" + + meta = {'type_of_value': the_type} + meta = json.dumps(meta) + compress = True if self.force_compress else compress @@ -336,7 +352,8 @@ def set(self, key, value, encryption_key="a", compress=None, cache_policy=0, loc copy_data = copy.copy(data) copy_data["key"] = copy_data["key"] + f"_upsonic_version_{version_tag}" self._send_request("POST", "/controller/set", copy_data) - + if not update_operation: + self._update_set(copy_data["key"], meta) elif self.version and not no_version: the_version_ = self.get_set_version_tag() @@ -346,10 +363,11 @@ def set(self, key, value, encryption_key="a", compress=None, cache_policy=0, loc self._send_request("POST", "/controller/set", copy_data) if not update_operation: - self._update_set(copy_data["key"]) + self._update_set(copy_data["key"], meta) - + if not update_operation: + self._update_set(key, meta) return self._send_request("POST", "/controller/set", data) def get(self, key, encryption_key="a", no_cache=False, version_tag=None, no_version=False): diff --git a/upsonic/remote/interface.py b/upsonic/remote/interface.py index 031edb8..ba53f07 100644 --- a/upsonic/remote/interface.py +++ b/upsonic/remote/interface.py @@ -29,7 +29,7 @@ def decrypt(key, message): -def Upsonic_Cloud_Free(database_name=None, access_key=None, locking=None, client_id=None, cache=None, cache_counter=5, version=None, client_version=None, key_encyption=None): +def Upsonic_Cloud_Free(database_name=None, access_key=None, locking=None, client_id=None, cache=None, cache_counter=5, version=None, client_version=None, key_encyption=None, meta_datas=None): if database_name == None: database_name = os.environ.get("database_key") if access_key == None: @@ -60,13 +60,20 @@ def Upsonic_Cloud_Free(database_name=None, access_key=None, locking=None, client if key_encyption == None: key_encyption = os.environ.get("key_encyption", "false").lower() == "true" + + + if meta_datas == None: + meta_datas = os.environ.get("meta_datas", "true").lower() == "true" + + + from upsonic import Upsonic_Remote return Upsonic_Remote( - database_name, "https://cloud_1.upsonic.co", access_key, verify=True, locking=locking, client_id=client_id, cache=cache, cache_counter=cache_counter, version=version, client_version=client_version, key_encyption=key_encyption + database_name, "https://cloud_1.upsonic.co", access_key, verify=True, locking=locking, client_id=client_id, cache=cache, cache_counter=cache_counter, version=version, client_version=client_version, key_encyption=key_encyption, meta_datas=meta_datas ) # pragma: no cover -def Upsonic_Cloud_Pro(database_name=None, access_key=None, locking=None, client_id=None, cache=None, cache_counter=5, version=None, client_version=None, key_encyption=None): +def Upsonic_Cloud_Pro(database_name=None, access_key=None, locking=None, client_id=None, cache=None, cache_counter=5, version=None, client_version=None, key_encyption=None, meta_datas=None): if database_name == None: database_name = os.environ.get("database_key") if access_key == None: @@ -95,13 +102,19 @@ def Upsonic_Cloud_Pro(database_name=None, access_key=None, locking=None, client_ if key_encyption == None: key_encyption = os.environ.get("key_encyption", "false").lower() == "true" + + if meta_datas == None: + meta_datas = os.environ.get("meta_datas", "true").lower() == "true" + + + from upsonic import Upsonic_Remote return Upsonic_Remote( - database_name, "https://cloud_2.upsonic.co", access_key, verify=True, locking=locking, client_id=client_id, cache=cache, cache_counter=cache_counter, version=version, client_version=client_version, key_encyption=key_encyption + database_name, "https://cloud_2.upsonic.co", access_key, verify=True, locking=locking, client_id=client_id, cache=cache, cache_counter=cache_counter, version=version, client_version=client_version, key_encyption=key_encyption, meta_datas=meta_datas ) # pragma: no cover -def Upsonic_Cloud_Premium(database_name=None, access_key=None, locking=None, client_id=None, cache=None, cache_counter=5, version=None, client_version=None, key_encyption=None): +def Upsonic_Cloud_Premium(database_name=None, access_key=None, locking=None, client_id=None, cache=None, cache_counter=5, version=None, client_version=None, key_encyption=None, meta_datas=None): if database_name == None: database_name = os.environ.get("database_key") if access_key == None: @@ -129,12 +142,19 @@ def Upsonic_Cloud_Premium(database_name=None, access_key=None, locking=None, cli if key_encyption == None: key_encyption = os.environ.get("key_encyption", "false").lower() == "true" + + + if meta_datas == None: + meta_datas = os.environ.get("meta_datas", "true").lower() == "true" + + + from upsonic import Upsonic_Remote return Upsonic_Remote( - database_name, "https://cloud_3.upsonic.co", access_key, verify=True, locking=locking, client_id=client_id, cache=cache, cache_counter=cache_counter, version=version, client_version=client_version, key_encyption=key_encyption + database_name, "https://cloud_3.upsonic.co", access_key, verify=True, locking=locking, client_id=client_id, cache=cache, cache_counter=cache_counter, version=version, client_version=client_version, key_encyption=key_encyption, meta_datas=meta_datas ) # pragma: no cover -def Upsonic_Cloud_Startup(database_name=None, access_key=None, locking=None, client_id=None, cache=None, cache_counter=5, version=None, client_version=None, key_encyption=None): +def Upsonic_Cloud_Startup(database_name=None, access_key=None, locking=None, client_id=None, cache=None, cache_counter=5, version=None, client_version=None, key_encyption=None, meta_datas=None): if database_name == None: database_name = os.environ.get("database_key") if access_key == None: @@ -163,15 +183,22 @@ def Upsonic_Cloud_Startup(database_name=None, access_key=None, locking=None, cli if key_encyption == None: key_encyption = os.environ.get("key_encyption", "false").lower() == "true" + + + if meta_datas == None: + meta_datas = os.environ.get("meta_datas", "true").lower() == "true" + + + from upsonic import Upsonic_Remote return Upsonic_Remote( - database_name, "https://cloud_4.upsonic.co", access_key, verify=True, locking=locking, client_id=client_id, cache=cache, cache_counter=cache_counter, version=version, client_version=client_version, key_encyption=key_encyption + database_name, "https://cloud_4.upsonic.co", access_key, verify=True, locking=locking, client_id=client_id, cache=cache, cache_counter=cache_counter, version=version, client_version=client_version, key_encyption=key_encyption, meta_datas=meta_datas ) # pragma: no cover -def Upsonic_Cloud_Readonly(database_name=None, access_key=None, locking=None, client_id=None, cache=None, cache_counter=5, version=None, client_version=None, key_encyption=None): +def Upsonic_Cloud_Readonly(database_name=None, access_key=None, locking=None, client_id=None, cache=None, cache_counter=5, version=None, client_version=None, key_encyption=None, meta_datas=None): if database_name == None: database_name = os.environ.get("database_key") if access_key == None: @@ -200,9 +227,16 @@ def Upsonic_Cloud_Readonly(database_name=None, access_key=None, locking=None, cl if key_encyption == None: key_encyption = os.environ.get("key_encyption", "false").lower() == "true" + + + if meta_datas == None: + meta_datas = os.environ.get("meta_datas", "true").lower() == "true" + + + from upsonic import Upsonic_Remote return Upsonic_Remote( - database_name, "https://cloud_0.upsonic.co", access_key, verify=True, locking=locking, client_id=client_id, cache=cache, cache_counter=cache_counter, version=version, client_version=client_version, key_encyption=key_encyption + database_name, "https://cloud_0.upsonic.co", access_key, verify=True, locking=locking, client_id=client_id, cache=cache, cache_counter=cache_counter, version=version, client_version=client_version, key_encyption=key_encyption, meta_datas=meta_datas ) # pragma: no cover