Skip to content

Commit

Permalink
Added meta datas
Browse files Browse the repository at this point in the history
  • Loading branch information
onuratakan committed Dec 13, 2023
1 parent 70022e1 commit 4976411
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Upsonic-*/
upsonic_cache/
.vscode

test_backup
Expand Down
26 changes: 22 additions & 4 deletions upsonic/remote/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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):
Expand Down
54 changes: 44 additions & 10 deletions upsonic/remote/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 4976411

Please sign in to comment.