Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
dzaitsev
2025-05-02 16:11:49 +03:00
20 changed files with 131 additions and 189 deletions
@@ -39,7 +39,6 @@ public class AnnotationService : INotificationHandler<AnnotationsDeletedEvent>
IOptions<UIConfig> uiConfig, IOptions<UIConfig> uiConfig,
IGalleryService galleryService, IGalleryService galleryService,
IMediator mediator, IMediator mediator,
IHardwareService hardwareService,
IAzaionApi api) IAzaionApi api)
{ {
_dbFactory = dbFactory; _dbFactory = dbFactory;
+2 -13
View File
@@ -11,10 +11,10 @@ public interface IAzaionApi
ApiCredentials Credentials { get; } ApiCredentials Credentials { get; }
User CurrentUser { get; } User CurrentUser { get; }
void UpdateOffsets(UserQueueOffsets offsets); void UpdateOffsets(UserQueueOffsets offsets);
Stream GetResource(string filename, string folder); //Stream GetResource(string filename, string folder);
} }
public class AzaionApi(HttpClient client, ICache cache, ApiCredentials credentials, IHardwareService hardwareService) : IAzaionApi public class AzaionApi(HttpClient client, ICache cache, ApiCredentials credentials) : IAzaionApi
{ {
private string _jwtToken = null!; private string _jwtToken = null!;
const string APP_JSON = "application/json"; const string APP_JSON = "application/json";
@@ -32,17 +32,6 @@ public class AzaionApi(HttpClient client, ICache cache, ApiCredentials credentia
} }
} }
public Stream GetResource(string filename, string folder)
{
var hardware = cache.GetFromCache(SecurityConstants.HARDWARE_INFO_KEY, hardwareService.GetHardware);
var response = Send(new HttpRequestMessage(HttpMethod.Post, $"/resources/get/{folder}")
{
Content = new StringContent(JsonConvert.SerializeObject(new { filename, credentials.Password, hardware }), Encoding.UTF8, APP_JSON)
});
return response.Content.ReadAsStream();
}
public void UpdateOffsets(UserQueueOffsets offsets) public void UpdateOffsets(UserQueueOffsets offsets)
{ {
Put($"/users/queue-offsets/{CurrentUser.Email}", offsets); Put($"/users/queue-offsets/{CurrentUser.Email}", offsets);
@@ -8,96 +8,96 @@ namespace Azaion.CommonSecurity.Services;
public interface IHardwareService public interface IHardwareService
{ {
HardwareInfo GetHardware(); //HardwareInfo GetHardware();
} }
public class HardwareService : IHardwareService public class HardwareService : IHardwareService
{ {
private const string WIN32_GET_HARDWARE_COMMAND = // private const string WIN32_GET_HARDWARE_COMMAND =
"powershell -Command \"" + // "powershell -Command \"" +
"Get-CimInstance -ClassName Win32_Processor | Select-Object -ExpandProperty Name | Write-Output; " + // "Get-CimInstance -ClassName Win32_Processor | Select-Object -ExpandProperty Name | Write-Output; " +
"Get-CimInstance -ClassName Win32_VideoController | Select-Object -ExpandProperty Name | Write-Output; " + // "Get-CimInstance -ClassName Win32_VideoController | Select-Object -ExpandProperty Name | Write-Output; " +
"Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -ExpandProperty TotalVisibleMemorySize | Write-Output" + // "Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -ExpandProperty TotalVisibleMemorySize | Write-Output" +
"\""; // "\"";
//
// private const string UNIX_GET_HARDWARE_COMMAND =
// "/bin/bash -c \"free -g | grep Mem: | awk '{print $2}' && " +
// "lscpu | grep 'Model name:' | cut -d':' -f2 && " +
// "lspci | grep VGA | cut -d':' -f3\"";
private const string UNIX_GET_HARDWARE_COMMAND = // public HardwareInfo GetHardware()
"/bin/bash -c \"free -g | grep Mem: | awk '{print $2}' && " + // {
"lscpu | grep 'Model name:' | cut -d':' -f2 && " + // try
"lspci | grep VGA | cut -d':' -f3\""; // {
// var output = RunCommand(Environment.OSVersion.Platform == PlatformID.Win32NT
// ? WIN32_GET_HARDWARE_COMMAND
// : UNIX_GET_HARDWARE_COMMAND);
//
// var lines = output
// .Replace("TotalVisibleMemorySize=", "")
// .Replace("Name=", "")
// .Replace(" ", " ")
// .Trim()
// .Split(['\n', '\r'], StringSplitOptions.RemoveEmptyEntries)
// .Select(x => x.Trim())
// .ToArray();
//
// if (lines.Length < 3)
// throw new Exception("Can't get hardware info");
//
// var hardwareInfo = new HardwareInfo
// {
// CPU = lines[0],
// GPU = lines[1],
// Memory = lines[2],
// MacAddress = GetMacAddress()
// };
// return hardwareInfo;
// }
// catch (Exception ex)
// {
// Console.WriteLine(ex.Message);
// throw;
// }
// }
public HardwareInfo GetHardware() // private string GetMacAddress()
{ // {
try // var macAddress = NetworkInterface
{ // .GetAllNetworkInterfaces()
var output = RunCommand(Environment.OSVersion.Platform == PlatformID.Win32NT // .Where(nic => nic.OperationalStatus == OperationalStatus.Up)
? WIN32_GET_HARDWARE_COMMAND // .Select(nic => nic.GetPhysicalAddress().ToString())
: UNIX_GET_HARDWARE_COMMAND); // .FirstOrDefault();
//
// return macAddress ?? string.Empty;
// }
//
// private string RunCommand(string command)
// {
// try
// {
// using var process = new Process();
// process.StartInfo.FileName = Environment.OSVersion.Platform == PlatformID.Unix ? "/bin/bash" : "cmd.exe";
// process.StartInfo.Arguments = Environment.OSVersion.Platform == PlatformID.Unix
// ? $"-c \"{command}\""
// : $"/c {command}";
// process.StartInfo.RedirectStandardOutput = true;
// process.StartInfo.UseShellExecute = false;
// process.StartInfo.CreateNoWindow = true;
//
// process.Start();
// var result = process.StandardOutput.ReadToEnd();
// process.WaitForExit();
//
// return result.Trim();
// }
// catch
// {
// return string.Empty;
// }
// }
var lines = output // private static string ToHash(string str) =>
.Replace("TotalVisibleMemorySize=", "") // Convert.ToBase64String(SHA384.HashData(Encoding.UTF8.GetBytes(str)));
.Replace("Name=", "")
.Replace(" ", " ")
.Trim()
.Split(['\n', '\r'], StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.Trim())
.ToArray();
if (lines.Length < 3)
throw new Exception("Can't get hardware info");
var hardwareInfo = new HardwareInfo
{
CPU = lines[0],
GPU = lines[1],
Memory = lines[2],
MacAddress = GetMacAddress()
};
return hardwareInfo;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw;
}
}
private string GetMacAddress()
{
var macAddress = NetworkInterface
.GetAllNetworkInterfaces()
.Where(nic => nic.OperationalStatus == OperationalStatus.Up)
.Select(nic => nic.GetPhysicalAddress().ToString())
.FirstOrDefault();
return macAddress ?? string.Empty;
}
private string RunCommand(string command)
{
try
{
using var process = new Process();
process.StartInfo.FileName = Environment.OSVersion.Platform == PlatformID.Unix ? "/bin/bash" : "cmd.exe";
process.StartInfo.Arguments = Environment.OSVersion.Platform == PlatformID.Unix
? $"-c \"{command}\""
: $"/c {command}";
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.Start();
var result = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return result.Trim();
}
catch
{
return string.Empty;
}
}
private static string ToHash(string str) =>
Convert.ToBase64String(SHA384.HashData(Encoding.UTF8.GetBytes(str)));
} }
@@ -60,7 +60,8 @@ public class InferenceClient : IInferenceClient
private async Task ProcessClientCommands() private async Task ProcessClientCommands()
{ {
//TODO: implement always on ready to client's requests. Utilize RemoteCommand
await Task.CompletedTask;
} }
public void Stop() public void Stop()
+11 -10
View File
@@ -8,17 +8,18 @@ cimport constants
import yaml import yaml
from cdn_manager cimport CDNManager, CDNCredentials from cdn_manager cimport CDNManager, CDNCredentials
from hardware_service cimport HardwareService, HardwareInfo from hardware_service cimport HardwareService
from security cimport Security from security cimport Security
from user cimport User, RoleEnum from user cimport User, RoleEnum
cdef class ApiClient: cdef class ApiClient:
"""Handles API authentication and downloading of the AI model.""" """Handles API authentication and downloading of the AI model."""
def __init__(self): def __init__(self, str api_url):
self.credentials = None self.credentials = None
self.user = None self.user = None
self.token = None self.token = None
self.cdn_manager = None self.cdn_manager = None
self.api_url = api_url
cdef set_credentials(self, Credentials credentials): cdef set_credentials(self, Credentials credentials):
self.credentials = credentials self.credentials = credentials
@@ -33,12 +34,13 @@ cdef class ApiClient:
self.cdn_manager = CDNManager(creds) self.cdn_manager = CDNManager(creds)
cdef login(self): cdef login(self):
response = requests.post(f"{constants.API_URL}/login", response = requests.post(f"{self.api_url}/login",
json={"email": self.credentials.email, "password": self.credentials.password}) json={"email": self.credentials.email, "password": self.credentials.password})
response.raise_for_status() response.raise_for_status()
token = response.json()["token"] token = response.json()["token"]
self.set_token(token) self.set_token(token)
cdef set_token(self, str token): cdef set_token(self, str token):
self.token = token self.token = token
claims = jwt.decode(token, options={"verify_signature": False}) claims = jwt.decode(token, options={"verify_signature": False})
@@ -73,23 +75,22 @@ cdef class ApiClient:
cdef upload_file(self, str filename, bytes resource, str folder): cdef upload_file(self, str filename, bytes resource, str folder):
if self.token is None: if self.token is None:
self.login() self.login()
url = f"{constants.API_URL}/resources/{folder}" url = f"{self.api_url}/resources/{folder}"
headers = { "Authorization": f"Bearer {self.token}" } headers = { "Authorization": f"Bearer {self.token}" }
files = {'data': (filename, resource)} files = {'data': (filename, resource)}
try: try:
r = requests.post(url, headers=headers, files=files, allow_redirects=True) r = requests.post(url, headers=headers, files=files, allow_redirects=True)
r.raise_for_status() r.raise_for_status()
constants.log(f"Uploaded {filename} to {constants.API_URL}/{folder} successfully: {r.status_code}.") constants.log(f"Uploaded {filename} to {self.api_url}/{folder} successfully: {r.status_code}.")
except Exception as e: except Exception as e:
constants.log(f"Upload fail: {e}") constants.log(f"Upload fail: {e}")
cdef load_bytes(self, str filename, str folder): cdef load_bytes(self, str filename, str folder):
hardware_service = HardwareService() hardware_service = HardwareService()
cdef HardwareInfo hardware = hardware_service.get_hardware_info() cdef str hardware = hardware_service.get_hardware_info()
if self.token is None: if self.token is None:
self.login() self.login()
url = f"{constants.API_URL}/resources/get/{folder}" url = f"{self.api_url}/resources/get/{folder}"
headers = { headers = {
"Authorization": f"Bearer {self.token}", "Authorization": f"Bearer {self.token}",
"Content-Type": "application/json" "Content-Type": "application/json"
@@ -98,7 +99,7 @@ cdef class ApiClient:
payload = json.dumps( payload = json.dumps(
{ {
"password": self.credentials.password, "password": self.credentials.password,
"hardware": hardware.to_json_object(), "hardware": hardware,
"fileName": filename "fileName": filename
}, indent=4) }, indent=4)
response = requests.post(url, data=payload, headers=headers, stream=True) response = requests.post(url, data=payload, headers=headers, stream=True)
-2
View File
@@ -28,8 +28,6 @@ tmp_ret = collect_all('pynvml')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2] datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
tmp_ret = collect_all('boto3') tmp_ret = collect_all('boto3')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2] datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
tmp_ret = collect_all('re')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
tmp_ret = collect_all('jwt') tmp_ret = collect_all('jwt')
datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2] datas += tmp_ret[0]; binaries += tmp_ret[1]; hiddenimports += tmp_ret[2]
-1
View File
@@ -31,7 +31,6 @@ venv\Scripts\pyinstaller --name=azaion-inference ^
--collect-all pycuda ^ --collect-all pycuda ^
--collect-all pynvml ^ --collect-all pynvml ^
--collect-all boto3 ^ --collect-all boto3 ^
--collect-all re ^
--collect-all jwt ^ --collect-all jwt ^
--hidden-import constants ^ --hidden-import constants ^
--hidden-import annotation ^ --hidden-import annotation ^
+2 -1
View File
@@ -1 +1,2 @@
zmq_port: 5131 zmq_port: 5131
api_url: https://api.azaion.com
+2 -1
View File
@@ -1 +1,2 @@
zmq_port: 5127 zmq_port: 5127
api_url: http://localhost:5219
-1
View File
@@ -4,7 +4,6 @@ cdef int QUEUE_MAXSIZE # Maximum size of the command queue
cdef str COMMANDS_QUEUE # Name of the commands queue in rabbit cdef str COMMANDS_QUEUE # Name of the commands queue in rabbit
cdef str ANNOTATIONS_QUEUE # Name of the annotations queue in rabbit cdef str ANNOTATIONS_QUEUE # Name of the annotations queue in rabbit
cdef str API_URL # Base URL for the external API
cdef str QUEUE_CONFIG_FILENAME # queue config filename to load from api cdef str QUEUE_CONFIG_FILENAME # queue config filename to load from api
cdef str AI_ONNX_MODEL_FILE cdef str AI_ONNX_MODEL_FILE
-1
View File
@@ -6,7 +6,6 @@ cdef int QUEUE_MAXSIZE = 1000 # Maximum size of the command queue
cdef str COMMANDS_QUEUE = "azaion-commands" cdef str COMMANDS_QUEUE = "azaion-commands"
cdef str ANNOTATIONS_QUEUE = "azaion-annotations" cdef str ANNOTATIONS_QUEUE = "azaion-annotations"
cdef str API_URL = "https://api.azaion.com" # Base URL for the external API
cdef str QUEUE_CONFIG_FILENAME = "secured-config.json" cdef str QUEUE_CONFIG_FILENAME = "secured-config.json"
cdef str AI_ONNX_MODEL_FILE = "azaion.onnx" cdef str AI_ONNX_MODEL_FILE = "azaion.onnx"
+1 -6
View File
@@ -1,11 +1,6 @@
cdef class HardwareInfo:
cdef str cpu, gpu, memory, mac_address
cdef to_json_object(self)
cdef class HardwareService: cdef class HardwareService:
cdef bint is_windows cdef bint is_windows
cdef get_mac_address(self, interface=*)
@staticmethod @staticmethod
cdef has_nvidia_gpu() cdef has_nvidia_gpu()
cdef HardwareInfo get_hardware_info(self) cdef str get_hardware_info(self)
+12 -33
View File
@@ -1,25 +1,6 @@
import re
import subprocess import subprocess
import psutil
import pynvml import pynvml
cdef class HardwareInfo:
def __init__(self, str cpu, str gpu, str memory, str mac_address):
self.cpu = cpu
self.gpu = gpu
self.memory = memory
self.mac_address = mac_address
cdef to_json_object(self):
return {
"CPU": self.cpu,
"GPU": self.gpu,
"MacAddress": self.mac_address,
"Memory": self.memory
}
def __str__(self):
return f'CPU: {self.cpu}. GPU: {self.gpu}. Memory: {self.memory}. MAC Address: {self.mac_address}'
cdef class HardwareService: cdef class HardwareService:
"""Handles hardware information retrieval and hash generation.""" """Handles hardware information retrieval and hash generation."""
@@ -35,15 +16,6 @@ cdef class HardwareService:
print('Error during os type checking') print('Error during os type checking')
self.is_windows = False self.is_windows = False
cdef get_mac_address(self, interface="Ethernet"):
addresses = psutil.net_if_addrs()
for interface_name, interface_info in addresses.items():
if interface_name == interface:
for addr in interface_info:
if addr.family == psutil.AF_LINK:
return addr.address.replace('-', '')
return None
@staticmethod @staticmethod
cdef has_nvidia_gpu(): cdef has_nvidia_gpu():
try: try:
@@ -67,13 +39,14 @@ cdef class HardwareService:
print('Failed to shutdown pynvml cause probably no NVidia GPU') print('Failed to shutdown pynvml cause probably no NVidia GPU')
pass pass
cdef HardwareInfo get_hardware_info(self): cdef str get_hardware_info(self):
if self.is_windows: if self.is_windows:
os_command = ( os_command = (
"powershell -Command \"" "powershell -Command \""
"Get-CimInstance -ClassName Win32_Processor | Select-Object -ExpandProperty Name | Write-Output; " "Get-CimInstance -ClassName Win32_Processor | Select-Object -ExpandProperty Name | Write-Output; "
"Get-CimInstance -ClassName Win32_VideoController | Select-Object -ExpandProperty Name | Write-Output; " "Get-CimInstance -ClassName Win32_VideoController | Select-Object -ExpandProperty Name | Write-Output; "
"Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -ExpandProperty TotalVisibleMemorySize | Write-Output" "Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -ExpandProperty TotalVisibleMemorySize | Write-Output; "
"(Get-Disk | Where-Object {$_.IsSystem -eq $true}).SerialNumber"
"\"" "\""
) )
else: else:
@@ -81,16 +54,22 @@ cdef class HardwareService:
"/bin/bash -c \" lscpu | grep 'Model name:' | cut -d':' -f2 && " "/bin/bash -c \" lscpu | grep 'Model name:' | cut -d':' -f2 && "
"lspci | grep VGA | cut -d':' -f3 && " "lspci | grep VGA | cut -d':' -f3 && "
"free -g | grep Mem: | awk '{print $2}' && \"" "free -g | grep Mem: | awk '{print $2}' && \""
"udevadm info --query=property --name=\"/dev/$(lsblk -no pkname \"$(findmnt -n -o SOURCE --target /)\")\" | grep -E 'ID_SERIAL=|ID_SERIAL_SHORT=' | cut -d'=' -f2- | head -n1 && "
) )
# in case of subprocess error do: # in case of subprocess error do:
# cdef bytes os_command_bytes = os_command.encode('utf-8') # cdef bytes os_command_bytes = os_command.encode('utf-8')
# and use os_command_bytes # and use os_command_bytes
result = subprocess.check_output(os_command, shell=True).decode('utf-8') result = subprocess.check_output(os_command, shell=True).decode('utf-8')
lines = [line.strip() for line in result.splitlines() if line.strip()] lines = [line.strip() for line in result.splitlines() if line.strip()]
cdef str cpu = lines[0].replace("Name=", "").replace(" ", " ") cdef str cpu = lines[0].replace("Name=", "").replace(" ", " ")
cdef str gpu = lines[1].replace("Name=", "").replace(" ", " ") cdef str gpu = lines[1].replace("Name=", "").replace(" ", " ")
cdef str memory = lines[2].replace("TotalVisibleMemorySize=", "").replace(" ", " ") # could be multiple gpus
cdef str mac_address = self.get_mac_address()
return HardwareInfo(cpu, gpu, memory, mac_address) len_lines = len(lines)
cdef str memory = lines[len_lines-2].replace("TotalVisibleMemorySize=", "").replace(" ", " ")
cdef str drive_serial = lines[len_lines-1]
cdef str res = f'CPU: {cpu}. GPU: {gpu}. Memory: {memory}. DriveSerial: {drive_serial}'
return res
+7 -2
View File
@@ -23,8 +23,13 @@ cdef class CommandProcessor:
cdef Inference inference cdef Inference inference
def __init__(self): def __init__(self):
self.api_client = ApiClient() with open(<str>constants.CONFIG_FILE, "r") as f:
self.remote_handler = RemoteCommandHandler(self.on_command) config = yaml.safe_load(f)
zmq_port = config["zmq_port"]
api_url = config["api_url"]
self.api_client = ApiClient(api_url)
self.remote_handler = RemoteCommandHandler(zmq_port, self.on_command)
self.inference_queue = Queue(maxsize=constants.QUEUE_MAXSIZE) self.inference_queue = Queue(maxsize=constants.QUEUE_MAXSIZE)
self.remote_handler.start() self.remote_handler.start()
self.running = True self.running = True
+3 -6
View File
@@ -6,16 +6,13 @@ cimport constants
import yaml import yaml
cdef class RemoteCommandHandler: cdef class RemoteCommandHandler:
def __init__(self, object on_command): def __init__(self, int zmq_port, object on_command):
self._on_command = on_command self._on_command = on_command
self._context = zmq.Context.instance() self._context = zmq.Context.instance()
self._router = self._context.socket(zmq.ROUTER) self._router = self._context.socket(zmq.ROUTER)
self._router.setsockopt(zmq.LINGER, 0) self._router.setsockopt(zmq.LINGER, 0)
with open(<str>constants.CONFIG_FILE, "r") as f: self._router.bind(f'tcp://*:{zmq_port}')
config = yaml.safe_load(f)
port = config["zmq_port"]
self._router.bind(f'tcp://*:{port}')
self._dealer = self._context.socket(zmq.DEALER) self._dealer = self._context.socket(zmq.DEALER)
self._dealer.setsockopt(zmq.LINGER, 0) self._dealer.setsockopt(zmq.LINGER, 0)
@@ -31,7 +28,7 @@ cdef class RemoteCommandHandler:
for _ in range(4): # 4 worker threads for _ in range(4): # 4 worker threads
worker = Thread(target=self._worker_loop, daemon=True) worker = Thread(target=self._worker_loop, daemon=True)
self._workers.append(worker) self._workers.append(worker)
print(f'Listening to commands on port {port}...') print(f'Listening to commands on port {zmq_port}...')
cdef start(self): cdef start(self):
self._proxy_thread.start() self._proxy_thread.start()
+1 -2
View File
@@ -1,5 +1,4 @@
from credentials cimport Credentials from credentials cimport Credentials
from hardware_service cimport HardwareInfo
cdef class Security: cdef class Security:
@staticmethod @staticmethod
@@ -9,7 +8,7 @@ cdef class Security:
cdef decrypt_to(input_bytes, key) cdef decrypt_to(input_bytes, key)
@staticmethod @staticmethod
cdef get_hw_hash(HardwareInfo hardware) cdef get_hw_hash(str hardware)
@staticmethod @staticmethod
cdef get_api_encryption_key(Credentials credentials, str hardware_hash) cdef get_api_encryption_key(Credentials credentials, str hardware_hash)
+2 -4
View File
@@ -3,8 +3,6 @@ import hashlib
import os import os
from hashlib import sha384 from hashlib import sha384
from credentials cimport Credentials from credentials cimport Credentials
from hardware_service cimport HardwareInfo
from cryptography.hazmat.backends import default_backend from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives import padding from cryptography.hazmat.primitives import padding
@@ -48,8 +46,8 @@ cdef class Security:
return bytes(plaintext_bytes) return bytes(plaintext_bytes)
@staticmethod @staticmethod
cdef get_hw_hash(HardwareInfo hardware): cdef get_hw_hash(str hardware):
cdef str key = f'Azaion_{hardware.mac_address}_{hardware.cpu}_{hardware.gpu}' cdef str key = f'Azaion_{hardware}_%$$$)0_'
return Security.calc_hash(key) return Security.calc_hash(key)
@staticmethod @staticmethod
@@ -202,7 +202,7 @@ class Api:
payload = json.dumps( payload = json.dumps(
{ {
"password": self.credentials.password, "password": self.credentials.password,
"hardware": hardware.to_json_object(), "hardware": hardware,
"fileName": filename "fileName": filename
}, indent=4) }, indent=4)
response = requests.post(url, data=payload, headers=headers, stream=True, timeout=20) response = requests.post(url, data=payload, headers=headers, stream=True, timeout=20)
+1 -3
View File
@@ -46,7 +46,6 @@ public partial class App
private static readonly Guid KeyPressTaskId = Guid.NewGuid(); private static readonly Guid KeyPressTaskId = Guid.NewGuid();
private readonly ICache _cache = new MemoryCache(); private readonly ICache _cache = new MemoryCache();
private readonly IHardwareService _hardwareService = new HardwareService();
private IAzaionApi _azaionApi = null!; private IAzaionApi _azaionApi = null!;
private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
@@ -97,7 +96,7 @@ public partial class App
login.CredentialsEntered += (_, credentials) => login.CredentialsEntered += (_, credentials) =>
{ {
_inferenceClient.Send(RemoteCommand.Create(CommandType.Login, credentials)); _inferenceClient.Send(RemoteCommand.Create(CommandType.Login, credentials));
_azaionApi = new AzaionApi(new HttpClient { BaseAddress = new Uri(SecurityConstants.API_URL) }, _cache, credentials, _hardwareService); _azaionApi = new AzaionApi(new HttpClient { BaseAddress = new Uri(SecurityConstants.API_URL) }, _cache, credentials);
try try
{ {
@@ -176,7 +175,6 @@ public partial class App
.ConfigureServices((context, services) => .ConfigureServices((context, services) =>
{ {
services.AddSingleton<MainSuite>(); services.AddSingleton<MainSuite>();
services.AddSingleton<IHardwareService, HardwareService>();
services.Configure<AppConfig>(context.Configuration); services.Configure<AppConfig>(context.Configuration);
services.ConfigureSection<QueueConfig>(context.Configuration); services.ConfigureSection<QueueConfig>(context.Configuration);
-16
View File
@@ -1,16 +0,0 @@
using Azaion.Common.Services;
using Azaion.CommonSecurity.Services;
using Xunit;
namespace Azaion.Annotator.Test;
public class HardwareServiceTest
{
[Fact]
public void GetHardware_Test()
{
var hardwareService = new HardwareService();
var hw = hardwareService.GetHardware();
Console.WriteLine(hw);
}
}