mirror of
https://github.com/azaion/loader.git
synced 2026-04-22 07:06:33 +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:
@@ -12,3 +12,4 @@ e2e-results/
|
|||||||
test-results/
|
test-results/
|
||||||
Logs/
|
Logs/
|
||||||
*.enc
|
*.enc
|
||||||
|
*.o
|
||||||
|
|||||||
+1
-1
@@ -12,4 +12,4 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|||||||
COPY . .
|
COPY . .
|
||||||
RUN python setup.py build_ext --inplace
|
RUN python setup.py build_ext --inplace
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
|
CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080", "--app-dir", "src"]
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ services:
|
|||||||
build:
|
build:
|
||||||
context: ..
|
context: ..
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
command: bash -c "rm -rf /app/models/* && mkdir -p /app/models && python -m uvicorn main:app --host 0.0.0.0 --port 8080"
|
command: bash -c "rm -rf /app/models/* && mkdir -p /app/models && python -m uvicorn main:app --host 0.0.0.0 --port 8080 --app-dir src"
|
||||||
ports:
|
ports:
|
||||||
- "8080:8080"
|
- "8080:8080"
|
||||||
depends_on:
|
depends_on:
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ from setuptools import setup, Extension
|
|||||||
from Cython.Build import cythonize
|
from Cython.Build import cythonize
|
||||||
|
|
||||||
extensions = [
|
extensions = [
|
||||||
Extension('constants', ['constants.pyx']),
|
Extension('constants', ['src/constants.pyx']),
|
||||||
Extension('credentials', ['credentials.pyx']),
|
Extension('credentials', ['src/credentials.pyx']),
|
||||||
Extension('user', ['user.pyx']),
|
Extension('user', ['src/user.pyx']),
|
||||||
Extension('security', ['security.pyx']),
|
Extension('security', ['src/security.pyx']),
|
||||||
Extension('hardware_service', ['hardware_service.pyx']),
|
Extension('hardware_service', ['src/hardware_service.pyx']),
|
||||||
Extension('cdn_manager', ['cdn_manager.pyx']),
|
Extension('cdn_manager', ['src/cdn_manager.pyx']),
|
||||||
Extension('api_client', ['api_client.pyx']),
|
Extension('api_client', ['src/api_client.pyx']),
|
||||||
]
|
]
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
|
|||||||
+2
-2
@@ -15,8 +15,8 @@ cdef class ApiClient:
|
|||||||
cdef login(self)
|
cdef login(self)
|
||||||
cdef set_token(self, str token)
|
cdef set_token(self, str token)
|
||||||
|
|
||||||
cdef request(self, str method, str url, object payload, bint is_stream)
|
cdef request(self, str method, str url, str payload, bint is_stream)
|
||||||
cdef load_bytes(self, str filename, str folder)
|
cdef bytes load_bytes(self, str filename, str folder)
|
||||||
cdef upload_file(self, str filename, bytes resource, str folder)
|
cdef upload_file(self, str filename, bytes resource, str folder)
|
||||||
cdef load_big_file_cdn(self, str folder, str big_part)
|
cdef load_big_file_cdn(self, str folder, str big_part)
|
||||||
cpdef load_big_small_resource(self, str resource_name, str folder)
|
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:
|
cdef class ApiClient:
|
||||||
def __init__(self, str api_url):
|
def __init__(self, str api_url):
|
||||||
self.credentials = None
|
|
||||||
self.user = None
|
|
||||||
self.token = None
|
|
||||||
self.cdn_manager = None
|
|
||||||
self.api_url = api_url
|
self.api_url = api_url
|
||||||
|
|
||||||
cpdef set_credentials_from_dict(self, str email, str password):
|
cpdef set_credentials_from_dict(self, str email, str password):
|
||||||
@@ -51,6 +47,8 @@ cdef class ApiClient:
|
|||||||
token = response.json()["token"]
|
token = response.json()["token"]
|
||||||
self.set_token(token)
|
self.set_token(token)
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
|
if response is None:
|
||||||
|
raise
|
||||||
res = response.json()
|
res = response.json()
|
||||||
constants.logerror(str(res))
|
constants.logerror(str(res))
|
||||||
if response.status_code == HTTPStatus.CONFLICT:
|
if response.status_code == HTTPStatus.CONFLICT:
|
||||||
@@ -93,7 +91,7 @@ cdef class ApiClient:
|
|||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
constants.log(f"Uploaded {filename} to {self.api_url}/{folder} successfully: {r.status_code}.")
|
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:
|
if self.credentials is None:
|
||||||
raise Exception("No credentials set")
|
raise Exception("No credentials set")
|
||||||
cdef str hardware = HardwareService.get_hardware_info()
|
cdef str hardware = HardwareService.get_hardware_info()
|
||||||
@@ -112,7 +110,7 @@ cdef class ApiClient:
|
|||||||
constants.log(<str>f'Downloaded file: {filename}, {len(data)} bytes')
|
constants.log(<str>f'Downloaded file: {filename}, {len(data)} bytes')
|
||||||
return data
|
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:
|
if self.token is None:
|
||||||
self.login()
|
self.login()
|
||||||
headers = {
|
headers = {
|
||||||
|
|||||||
+6
-6
@@ -2,19 +2,19 @@ from credentials cimport Credentials
|
|||||||
|
|
||||||
cdef class Security:
|
cdef class Security:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
cdef encrypt_to(input_stream, key)
|
cdef bytes encrypt_to(bytes input_bytes, str key)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
cdef decrypt_to(input_bytes, key)
|
cdef bytes decrypt_to(bytes input_bytes, str key)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
cdef get_hw_hash(str hardware)
|
cdef str get_hw_hash(str hardware)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
cdef get_api_encryption_key(Credentials credentials, str hardware_hash)
|
cdef str get_api_encryption_key(Credentials credentials, str hardware_hash)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
cdef get_resource_encryption_key()
|
cdef str get_resource_encryption_key()
|
||||||
|
|
||||||
@staticmethod
|
@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:
|
cdef class Security:
|
||||||
@staticmethod
|
@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()
|
cdef bytes aes_key = hashlib.sha256(key.encode('utf-8')).digest()
|
||||||
iv = os.urandom(16)
|
iv = os.urandom(16)
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ cdef class Security:
|
|||||||
return iv + ciphertext
|
return iv + ciphertext
|
||||||
|
|
||||||
@staticmethod
|
@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()
|
cdef bytes aes_key = hashlib.sha256(key.encode('utf-8')).digest()
|
||||||
iv = ciphertext_with_iv_bytes[:16]
|
iv = ciphertext_with_iv_bytes[:16]
|
||||||
ciphertext_bytes = ciphertext_with_iv_bytes[16:]
|
ciphertext_bytes = ciphertext_with_iv_bytes[16:]
|
||||||
@@ -41,22 +41,22 @@ cdef class Security:
|
|||||||
return bytes(plaintext_bytes)
|
return bytes(plaintext_bytes)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
cdef get_hw_hash(str hardware):
|
cdef str get_hw_hash(str hardware):
|
||||||
cdef str key = f'Azaion_{hardware}_%$$$)0_'
|
cdef str key = f'Azaion_{hardware}_%$$$)0_'
|
||||||
return Security.calc_hash(key)
|
return Security.calc_hash(key)
|
||||||
|
|
||||||
@staticmethod
|
@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@%#---'
|
cdef str key = f'{creds.email}-{creds.password}-{hardware_hash}-#%@AzaionKey@%#---'
|
||||||
return Security.calc_hash(key)
|
return Security.calc_hash(key)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
cdef get_resource_encryption_key():
|
cdef str get_resource_encryption_key():
|
||||||
cdef str key = '-#%@AzaionKey@%#---234sdfklgvhjbnn'
|
cdef str key = '-#%@AzaionKey@%#---234sdfklgvhjbnn'
|
||||||
return Security.calc_hash(key)
|
return Security.calc_hash(key)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
cdef calc_hash(str key):
|
cdef str calc_hash(str key):
|
||||||
str_bytes = key.encode('utf-8')
|
str_bytes = key.encode('utf-8')
|
||||||
hash_bytes = sha384(str_bytes).digest()
|
hash_bytes = sha384(str_bytes).digest()
|
||||||
cdef str h = base64.b64encode(hash_bytes).decode('utf-8')
|
cdef str h = base64.b64encode(hash_bytes).decode('utf-8')
|
||||||
|
|||||||
Reference in New Issue
Block a user