mirror of
https://github.com/azaion/loader.git
synced 2026-04-22 10:06:32 +00:00
Update project configuration and code structure
- Added '*.o' to .gitignore to exclude object files from version control. - Modified Dockerfile to specify the application directory for Uvicorn. - Updated setup.py to reflect the new source directory structure for Cython extensions. - Adjusted E2E Docker Compose command to include the application directory. - Refined type hints in ApiClient and Security classes for better clarity and consistency. These changes enhance the project's organization and improve the build process.
This commit is contained in:
+2
-2
@@ -15,8 +15,8 @@ cdef class ApiClient:
|
||||
cdef login(self)
|
||||
cdef set_token(self, str token)
|
||||
|
||||
cdef request(self, str method, str url, object payload, bint is_stream)
|
||||
cdef load_bytes(self, str filename, str folder)
|
||||
cdef request(self, str method, str url, str payload, bint is_stream)
|
||||
cdef bytes load_bytes(self, str filename, str folder)
|
||||
cdef upload_file(self, str filename, bytes resource, str folder)
|
||||
cdef load_big_file_cdn(self, str folder, str big_part)
|
||||
cpdef load_big_small_resource(self, str resource_name, str folder)
|
||||
|
||||
+4
-6
@@ -16,10 +16,6 @@ from user cimport User, RoleEnum
|
||||
|
||||
cdef class ApiClient:
|
||||
def __init__(self, str api_url):
|
||||
self.credentials = None
|
||||
self.user = None
|
||||
self.token = None
|
||||
self.cdn_manager = None
|
||||
self.api_url = api_url
|
||||
|
||||
cpdef set_credentials_from_dict(self, str email, str password):
|
||||
@@ -51,6 +47,8 @@ cdef class ApiClient:
|
||||
token = response.json()["token"]
|
||||
self.set_token(token)
|
||||
except HTTPError as e:
|
||||
if response is None:
|
||||
raise
|
||||
res = response.json()
|
||||
constants.logerror(str(res))
|
||||
if response.status_code == HTTPStatus.CONFLICT:
|
||||
@@ -93,7 +91,7 @@ cdef class ApiClient:
|
||||
r.raise_for_status()
|
||||
constants.log(f"Uploaded {filename} to {self.api_url}/{folder} successfully: {r.status_code}.")
|
||||
|
||||
cdef load_bytes(self, str filename, str folder):
|
||||
cdef bytes load_bytes(self, str filename, str folder):
|
||||
if self.credentials is None:
|
||||
raise Exception("No credentials set")
|
||||
cdef str hardware = HardwareService.get_hardware_info()
|
||||
@@ -112,7 +110,7 @@ cdef class ApiClient:
|
||||
constants.log(<str>f'Downloaded file: {filename}, {len(data)} bytes')
|
||||
return data
|
||||
|
||||
cdef request(self, str method, str url, object payload, bint is_stream):
|
||||
cdef request(self, str method, str url, str payload, bint is_stream):
|
||||
if self.token is None:
|
||||
self.login()
|
||||
headers = {
|
||||
|
||||
+6
-6
@@ -2,19 +2,19 @@ from credentials cimport Credentials
|
||||
|
||||
cdef class Security:
|
||||
@staticmethod
|
||||
cdef encrypt_to(input_stream, key)
|
||||
cdef bytes encrypt_to(bytes input_bytes, str key)
|
||||
|
||||
@staticmethod
|
||||
cdef decrypt_to(input_bytes, key)
|
||||
cdef bytes decrypt_to(bytes input_bytes, str key)
|
||||
|
||||
@staticmethod
|
||||
cdef get_hw_hash(str hardware)
|
||||
cdef str get_hw_hash(str hardware)
|
||||
|
||||
@staticmethod
|
||||
cdef get_api_encryption_key(Credentials credentials, str hardware_hash)
|
||||
cdef str get_api_encryption_key(Credentials credentials, str hardware_hash)
|
||||
|
||||
@staticmethod
|
||||
cdef get_resource_encryption_key()
|
||||
cdef str get_resource_encryption_key()
|
||||
|
||||
@staticmethod
|
||||
cdef calc_hash(str key)
|
||||
cdef str calc_hash(str key)
|
||||
+6
-6
@@ -11,7 +11,7 @@ BUFFER_SIZE = 64 * 1024 # 64 KB
|
||||
|
||||
cdef class Security:
|
||||
@staticmethod
|
||||
cdef encrypt_to(input_bytes, key):
|
||||
cdef bytes encrypt_to(bytes input_bytes, str key):
|
||||
cdef bytes aes_key = hashlib.sha256(key.encode('utf-8')).digest()
|
||||
iv = os.urandom(16)
|
||||
|
||||
@@ -25,7 +25,7 @@ cdef class Security:
|
||||
return iv + ciphertext
|
||||
|
||||
@staticmethod
|
||||
cdef decrypt_to(ciphertext_with_iv_bytes, key):
|
||||
cdef bytes decrypt_to(bytes ciphertext_with_iv_bytes, str key):
|
||||
cdef bytes aes_key = hashlib.sha256(key.encode('utf-8')).digest()
|
||||
iv = ciphertext_with_iv_bytes[:16]
|
||||
ciphertext_bytes = ciphertext_with_iv_bytes[16:]
|
||||
@@ -41,22 +41,22 @@ cdef class Security:
|
||||
return bytes(plaintext_bytes)
|
||||
|
||||
@staticmethod
|
||||
cdef get_hw_hash(str hardware):
|
||||
cdef str get_hw_hash(str hardware):
|
||||
cdef str key = f'Azaion_{hardware}_%$$$)0_'
|
||||
return Security.calc_hash(key)
|
||||
|
||||
@staticmethod
|
||||
cdef get_api_encryption_key(Credentials creds, str hardware_hash):
|
||||
cdef str get_api_encryption_key(Credentials creds, str hardware_hash):
|
||||
cdef str key = f'{creds.email}-{creds.password}-{hardware_hash}-#%@AzaionKey@%#---'
|
||||
return Security.calc_hash(key)
|
||||
|
||||
@staticmethod
|
||||
cdef get_resource_encryption_key():
|
||||
cdef str get_resource_encryption_key():
|
||||
cdef str key = '-#%@AzaionKey@%#---234sdfklgvhjbnn'
|
||||
return Security.calc_hash(key)
|
||||
|
||||
@staticmethod
|
||||
cdef calc_hash(str key):
|
||||
cdef str calc_hash(str key):
|
||||
str_bytes = key.encode('utf-8')
|
||||
hash_bytes = sha384(str_bytes).digest()
|
||||
cdef str h = base64.b64encode(hash_bytes).decode('utf-8')
|
||||
|
||||
Reference in New Issue
Block a user