Skip to content

Commit

Permalink
Many improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
onuratakan committed Feb 18, 2024
1 parent 4b9ef1c commit 7b605e0
Show file tree
Hide file tree
Showing 26 changed files with 2,629 additions and 162 deletions.
7 changes: 3 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def get_document():

the_scope.dump(dumped_data, accesskey)
self.assertEqual(get_document(), the_scope.documentation)
the_scope.create_documentation()
the_scope.create_documentation_old()

print(the_scope.documentation)
self.assertEqual(get_document(), the_scope.documentation)
Expand Down Expand Up @@ -637,7 +637,7 @@ def get_document():

def create_document():
data = {"scope": "onur.my_function", }
response = requests.post("http://localhost:7777" + create_document_of_scope_url,
response = requests.post("http://localhost:7777" + create_document_of_scope_url_old,
auth=HTTPBasicAuth("", id),
data=data)
return response.json()
Expand Down Expand Up @@ -794,7 +794,6 @@ def my_function():
cloudpickle.dumps(my_function))

the_scope.dump(dumped_data, AccessKey(id))
self.assertEqual(the_scope.code, """def my_function():\n return "aaa"\n""")

def get_document():
data = {"scope": id}
Expand All @@ -804,7 +803,7 @@ def get_document():

get_document()
self.assertEqual(the_scope.code, None)
self.assertEqual(the_scope.python, None)

self.assertEqual(the_scope.source, None)
self.assertEqual(the_scope.type, None)
self.assertEqual(the_scope.documentation, None)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def my_function():

the_scope.dump(dumped_data, AccessKey(id))

the_scope.set_type("function")
self.assertEqual(the_scope.type, "function")

storage_2.pop()
Expand All @@ -405,9 +406,9 @@ def my_function():
cloudpickle.dumps(my_function))

the_scope.dump(dumped_data, AccessKey(id))
the_scope.set_code("dsadasdadasdsa")

print(the_scope.code)
self.assertEqual(the_scope.code, """def my_function():\n return "aaa"\n""")
self.assertEqual(the_scope.code, "dsadasdadasdsa")

storage_2.pop()

Expand All @@ -424,7 +425,7 @@ def my_function():

the_scope.dump(dumped_data, AccessKey(id))
self.assertEqual(the_scope.documentation, None)
the_scope.create_documentation()
the_scope.create_documentation_old()

print(the_scope.documentation)
self.assertEqual(the_scope.documentation, "Returns a function instance for a my_function method .")
Expand Down Expand Up @@ -560,7 +561,6 @@ def my_function():
cloudpickle.dumps(my_function))

the_scope.dump(dumped_data, AccessKey(id))
self.assertEqual(the_scope.code, """def my_function():\n return "aaa"\n""")

the_scope.delete()
self.assertEqual(the_scope.code, None)
Expand Down
2 changes: 1 addition & 1 deletion upsonic_on_prem/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

@app.route(status_url, methods=["GET"])
def status():
return jsonify(True)
return jsonify({"status": True, "result": True})



Expand Down
35 changes: 31 additions & 4 deletions upsonic_on_prem/api/operations/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,30 @@ def dump():
data = request.form.get("data")

the_scope = Scope(scope)
the_scope.dump(data, AccessKey(request.authorization.password), pass_str=True)

return jsonify({"status": True})
return jsonify(
{"status": True, "result": the_scope.dump(data, AccessKey(request.authorization.password), pass_str=True)})


@app.route(dump_code_url, methods=["POST"])
def dump_code():
scope = request.form.get("scope")
code = request.form.get("code")

the_scope = Scope(scope)

return jsonify({"status": True, "result": the_scope.set_code(code)})


@app.route(dump_type_url, methods=["POST"])
def dump_type():
scope = request.form.get("scope")
type = request.form.get("type")

the_scope = Scope(scope)

return jsonify({"status": True, "result": the_scope.set_type(type)})



@app.route(load_url, methods=["POST"])
Expand Down Expand Up @@ -45,9 +66,15 @@ def get_document_of_scope():
@app.route(create_document_of_scope_url, methods=["POST"])
def create_document_of_scope():
scope = request.form.get("scope")
Scope(scope).create_documentation()
return jsonify({"status": True})

return jsonify({"status": True, "result": Scope(scope).create_documentation()})


@app.route(create_document_of_scope_url_old, methods=["POST"])
def create_document_of_scope_old():
scope = request.form.get("scope")

return jsonify({"status": True, "result": Scope(scope).create_documentation_old()})

@app.route(get_type_of_scope_url, methods=["POST"])
def get_type_of_scope():
Expand Down
9 changes: 7 additions & 2 deletions upsonic_on_prem/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@


dump_url = "/dump"
dump_code_url = "/dump_code"
dump_type_url = "/dump_type"
load_url = "/load"

get_admins_url = "/get_admins"
Expand Down Expand Up @@ -50,6 +52,7 @@

get_document_of_scope_url = "/get_document_of_scope"
create_document_of_scope_url = "/create_document_of_scope"
create_document_of_scope_url_old = "/create_document_of_scope_old"

get_type_of_scope_url = "/get_type_of_scope"

Expand All @@ -73,7 +76,9 @@
user_urs = [load_url, dump_url, get_read_scopes_of_me_url, get_write_scopes_of_me_url, get_document_of_scope_url,
create_version_url,
get_dump_history_url, load_specific_dump_url, get_all_scopes_name_prefix_url,
get_type_of_scope_url, create_document_of_scope_url, get_all_scopes_user_url, delete_scope_url]
user_write_urls = [dump_url, create_document_of_scope_url, delete_scope_url, create_version_url]
get_type_of_scope_url, create_document_of_scope_url, create_document_of_scope_url_old,
get_all_scopes_user_url, delete_scope_url, dump_code_url, dump_type_url]
user_write_urls = [dump_url, create_document_of_scope_url, create_document_of_scope_url_old, delete_scope_url,
create_version_url, dump_code_url, dump_type_url]
user_read_urls = [load_url, get_document_of_scope_url, get_dump_history_url, get_type_of_scope_url,
load_specific_dump_url]
11 changes: 11 additions & 0 deletions upsonic_on_prem/dash/app/adapter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from allauth.account.adapter import DefaultAccountAdapter
from allauth.account.utils import perform_login


class CustomAccountAdapter(DefaultAccountAdapter):

def is_open_for_signup(self, request):

Check notice on line 7 in upsonic_on_prem/dash/app/adapter.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Method is not declared static

Method `is_open_for_signup` may be 'static'

Check notice on line 7 in upsonic_on_prem/dash/app/adapter.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Unused local symbols

Parameter 'request' value is not used
"""
Whether to allow sign ups.
"""
return False
185 changes: 185 additions & 0 deletions upsonic_on_prem/dash/app/api_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import json
import ast

from rich.console import Console

console = Console()

from dotenv import load_dotenv
import os
from cryptography.fernet import Fernet

load_dotenv(dotenv_path=".env")

admin_key = os.environ.get("admin_key")


class Upsonic_Cloud_Utils:

Check notice on line 20 in upsonic_on_prem/dash/app/api_integration.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

PEP 8 naming convention violation

Class names should use CapWords convention
def _log(self, message):

Check notice on line 21 in upsonic_on_prem/dash/app/api_integration.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Method is not declared static

Method `_log` may be 'static'
console.log(message)

def __enter__(self):
return self # pragma: no cover

def __exit__(self, exc_type, exc_val, exc_tb):
pass # pragma: no cover

def create_database(self, name):

Check notice on line 30 in upsonic_on_prem/dash/app/api_integration.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Method is not declared static

Method `create_database` may be 'static'
return (
"DB_" + name + "_"
+ (((Fernet.generate_key()).decode()).replace("-", "").replace("_", "").replace("=", ""))[
:50
]
) # pragma: no cover

def create_access_key(self, ):

Check notice on line 38 in upsonic_on_prem/dash/app/api_integration.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Method is not declared static

Method `create_access_key` may be 'static'
return (
"ACK_" + (((Fernet.generate_key()).decode()).replace("-", "").replace("_", "").replace("=", ""))[
:60
]
) # pragma: no cover

def create_read_only_access_key(self, ):

Check notice on line 45 in upsonic_on_prem/dash/app/api_integration.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Method is not declared static

Method `create_read_only_access_key` may be 'static'
return (
"R-ACK_" + (((Fernet.generate_key()).decode()).replace("-", "").replace("_", "").replace("=", ""))[
:60
]
) # pragma: no cover

def __init__(self):
import requests
from requests.auth import HTTPBasicAuth

self.verify = cloud_utils_ssl_verify

from upsonic import console

self.requests = requests
self.HTTPBasicAuth = HTTPBasicAuth

self._log(
f"[bold white]Upsonic Cloud Utils[bold white] initializing...",
)

from upsonic import encrypt, decrypt
self.encrypt = encrypt
self.decrypt = decrypt

self.api_url = cloud_utils_url
self.password = cloud_utils_access_key

self._log(
f"[bold green]Upsonic Cloud[bold green] active",
)

def _send_request(self, method, endpoint, data=None, make_json=True):
try:
response = self.requests.request(
method,
self.api_url + endpoint,
data=data,
auth=self.HTTPBasicAuth("", self.password),
verify=self.verify
)
try:
return response.text if not make_json else json.loads(response.text)
except: # pragma: no cover

Check notice on line 89 in upsonic_on_prem/dash/app/api_integration.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Unclear exception clauses

Too broad exception clause
print(f"Error on '{self.api_url + endpoint}': ", response.text)
return [None] # pragma: no cover
except:

Check notice on line 92 in upsonic_on_prem/dash/app/api_integration.py

View workflow job for this annotation

GitHub Actions / Qodana Community for Python

Unclear exception clauses

Too broad exception clause
print("Error: Remote is down")
return [None]

def get_database(self, access_key):
data = {"access_key": access_key}
result = self._send_request("POST", "/get/databases", data)
return result[0]

def get_content(self, database_name):
data = {"database_name": database_name}
result = self._send_request("POST", "/get/keys", data)
return result[0]

def get_a_content(self, database_name, key):
data = {"database_name": database_name, "key": key}
result = self._send_request("POST", "/get/key", data)
return result[0]

def count_content(self, database_name):
data = {"database_name": database_name}
result = self._send_request("POST", "/count/key", data)
return result[0]

def edit_content(self, database_name, key, value):
data = {"database_name": database_name, "key": key, "value": value}
result = self._send_request("POST", "/edit/key", data)
return result[0]

def delete_content(self, database_name, key, custom_user):
data = {"database_name": database_name, "key": key, "custom_user": custom_user}
result = self._send_request("POST", "/delete/key", data)
return result[0]

def rename_database(self, database_name, new_database_name):
data = {"database_name": database_name, "new_database_name": new_database_name}
result = self._send_request("POST", "/rename/database", data)
return result[0]

def delete_database(self, database_name, custom_user):
data = {"database_name": database_name, "custom_user": custom_user}
result = self._send_request("POST", "/delete/database", data)
return result[0]

def pop_database(self, database_name):
data = {"database_name": database_name}
result = self._send_request("POST", "/pop/database", data)
return result[0]

def get_access_keys(self, cloud_type):
data = {"cloud_type": cloud_type}
result = self._send_request("POST", "/get/access_key", data)
return result[0]

def add_access_keys(self, cloud_type, access_key):
data = {"cloud_type": cloud_type, "access_key": access_key}
result = self._send_request("POST", "/add/access_key", data)
return result[0]

def remove_access_keys(self, cloud_type, access_key):
data = {"cloud_type": cloud_type, "access_key": access_key}
result = self._send_request("POST", "/remove/access_key", data)
return result[0]

def check_access_keys(self, cloud_type, access_key):
data = {"cloud_type": cloud_type, "access_key": access_key}
result = self._send_request("POST", "/check/access_key", data)
return result[0]

def add_runner(self, uniq_name, database_name, encryption_key, access_key, cloud_type):
data = {"uniq_name": uniq_name, "database_name": database_name, "encryption_key": encryption_key,
"access_key": access_key, "cloud_type": cloud_type}
result = self._send_request("POST", "/add/runner", data)
return result[0]

def log_runner(self, uniq_name, database_name):
data = {"uniq_name": uniq_name, "database_name": database_name}
result = self._send_request("POST", "/log/runner", data)
return result[0]

def status_runner(self, uniq_name, database_name):
data = {"uniq_name": uniq_name, "database_name": database_name}
result = self._send_request("POST", "/status/runner", data)
return result[0]

def get_runner(self, uniq_name, database_name):
data = {"uniq_name": uniq_name, "database_name": database_name}
result = self._send_request("POST", "/get/runner", data)
return result[0]

def remove_runner(self, uniq_name, database_name):
data = {"uniq_name": uniq_name, "database_name": database_name}
result = self._send_request("POST", "/remove/runner", data)
return result[0]
Loading

0 comments on commit 7b605e0

Please sign in to comment.