mirror of
https://github.com/azaion/loader.git
synced 2026-04-22 23:26:32 +00:00
Add API client and CDN manager implementation
- Introduced `ApiClient` class for handling API interactions, including authentication and resource management. - Added `CDNManager` class for managing file uploads and downloads to/from a CDN. - Implemented security features for encryption and decryption of sensitive data. - Created supporting classes for credentials, user roles, and hardware information retrieval. - Established constants for configuration and logging. This commit lays the foundation for resource management and secure communication with the API and CDN services.
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
import os
|
||||
import platform
|
||||
import subprocess
|
||||
|
||||
import psutil
|
||||
cimport constants
|
||||
|
||||
cdef str _CACHED_HW_INFO = None
|
||||
|
||||
|
||||
def _get_cpu():
|
||||
try:
|
||||
with open("/proc/cpuinfo") as f:
|
||||
for line in f:
|
||||
if "model name" in line.lower():
|
||||
return line.split(":")[1].strip()
|
||||
except OSError:
|
||||
pass
|
||||
cdef str p = platform.processor()
|
||||
if p:
|
||||
return p
|
||||
return platform.machine()
|
||||
|
||||
|
||||
def _get_gpu():
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["lspci"], capture_output=True, text=True, timeout=5,
|
||||
)
|
||||
for line in result.stdout.splitlines():
|
||||
if "VGA" in line:
|
||||
parts = line.split(":")
|
||||
if len(parts) > 2:
|
||||
return parts[2].strip()
|
||||
return parts[-1].strip()
|
||||
except (OSError, subprocess.TimeoutExpired, FileNotFoundError):
|
||||
pass
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["system_profiler", "SPDisplaysDataType"],
|
||||
capture_output=True, text=True, timeout=5,
|
||||
)
|
||||
for line in result.stdout.splitlines():
|
||||
if "Chipset Model" in line:
|
||||
return line.split(":")[1].strip()
|
||||
except (OSError, subprocess.TimeoutExpired, FileNotFoundError):
|
||||
pass
|
||||
return "unknown"
|
||||
|
||||
|
||||
def _get_drive_serial():
|
||||
try:
|
||||
for block in sorted(os.listdir("/sys/block")):
|
||||
for candidate in [
|
||||
f"/sys/block/{block}/device/vpd_pg80",
|
||||
f"/sys/block/{block}/device/serial",
|
||||
f"/sys/block/{block}/serial",
|
||||
]:
|
||||
try:
|
||||
with open(candidate, "rb") as f:
|
||||
serial = f.read().strip(b"\x00\x14 \t\n\r\v\f").decode("utf-8", errors="ignore")
|
||||
if serial:
|
||||
return serial
|
||||
except OSError:
|
||||
continue
|
||||
except OSError:
|
||||
pass
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["ioreg", "-rd1", "-c", "IOPlatformExpertDevice"],
|
||||
capture_output=True, text=True, timeout=5,
|
||||
)
|
||||
for line in result.stdout.splitlines():
|
||||
if "IOPlatformSerialNumber" in line:
|
||||
return line.split('"')[-2]
|
||||
except (OSError, subprocess.TimeoutExpired, FileNotFoundError):
|
||||
pass
|
||||
return "unknown"
|
||||
|
||||
|
||||
cdef class HardwareService:
|
||||
|
||||
@staticmethod
|
||||
cdef str get_hardware_info():
|
||||
global _CACHED_HW_INFO
|
||||
|
||||
if _CACHED_HW_INFO is not None:
|
||||
constants.log(<str>"Using cached hardware info")
|
||||
return <str> _CACHED_HW_INFO
|
||||
|
||||
cdef str cpu = _get_cpu()
|
||||
cdef str gpu = _get_gpu()
|
||||
cdef str memory = str(psutil.virtual_memory().total // 1024)
|
||||
cdef str drive_serial = _get_drive_serial()
|
||||
|
||||
cdef str res = f'CPU: {cpu}. GPU: {gpu}. Memory: {memory}. DriveSerial: {drive_serial}'
|
||||
constants.log(<str>f'Gathered hardware: {res}')
|
||||
_CACHED_HW_INFO = res
|
||||
return res
|
||||
Reference in New Issue
Block a user