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:
Oleksandr Bezdieniezhnykh
2026-04-13 06:47:06 +03:00
parent ec5d15b4e7
commit 0c5686d149
8 changed files with 28 additions and 29 deletions
+1
View File
@@ -12,3 +12,4 @@ e2e-results/
test-results/
Logs/
*.enc
*.o
+1 -1
View File
@@ -12,4 +12,4 @@ RUN pip install --no-cache-dir -r requirements.txt
COPY . .
RUN python setup.py build_ext --inplace
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"]
+1 -1
View File
@@ -23,7 +23,7 @@ services:
build:
context: ..
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:
- "8080:8080"
depends_on:
+7 -7
View File
@@ -2,13 +2,13 @@ from setuptools import setup, Extension
from Cython.Build import cythonize
extensions = [
Extension('constants', ['constants.pyx']),
Extension('credentials', ['credentials.pyx']),
Extension('user', ['user.pyx']),
Extension('security', ['security.pyx']),
Extension('hardware_service', ['hardware_service.pyx']),
Extension('cdn_manager', ['cdn_manager.pyx']),
Extension('api_client', ['api_client.pyx']),
Extension('constants', ['src/constants.pyx']),
Extension('credentials', ['src/credentials.pyx']),
Extension('user', ['src/user.pyx']),
Extension('security', ['src/security.pyx']),
Extension('hardware_service', ['src/hardware_service.pyx']),
Extension('cdn_manager', ['src/cdn_manager.pyx']),
Extension('api_client', ['src/api_client.pyx']),
]
setup(
+2 -2
View File
@@ -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
View File
@@ -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
View File
@@ -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
View File
@@ -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')