renmove ResourceEnum, use filename only

add ToHash for encryption Key
This commit is contained in:
Alex Bezdieniezhnykh
2024-11-22 12:13:37 +02:00
parent 8be7625542
commit f5e466108a
16 changed files with 103 additions and 85 deletions
+5 -5
View File
@@ -35,14 +35,14 @@ public enum ExceptionEnum
WrongEmail = 37,
[Description("Hardware mismatch! You are not authorized to access this resource from this hardware.")]
[Description("HardwareInfo mismatch! You are not authorized to access this resource from this hardware.")]
HardwareIdMismatch = 40,
[Description("Hardware Id should be at least 8 characters.")]
HardwareIdLength = 45,
[Description("HardwareInfo should contain information about this hardware.")]
BadHardware = 45,
[Description("Wrong resource type.")]
WrongResourceType = 50,
[Description("Wrong resource file name.")]
WrongResourceName = 50,
[Description("No file provided.")]
NoFileProvided = 60,
-1
View File
@@ -3,5 +3,4 @@ namespace Azaion.Common.Configs;
public class ResourcesConfig
{
public string ResourcesFolder { get; set; } = null!;
public Dictionary<string, string> Resources { get; set; } = null!;
}
+11
View File
@@ -0,0 +1,11 @@
namespace Azaion.Common.Entities;
public class HardwareInfo
{
public string CPU { get; set; } = null!;
public string GPU { get; set; } = null!;
public string MacAddress { get; set; } = null!;
public string Memory { get; set; } = null!;
public string? Hash { get; set; } = null!;
}
-9
View File
@@ -1,9 +0,0 @@
namespace Azaion.Common.Entities;
public enum ResourceEnum
{
None = 0,
AnnotatorDll = 10,
AIModelRKNN = 20,
AIModelONNX = 30,
}
+2 -1
View File
@@ -5,6 +5,7 @@ public class User
public Guid Id { get; set; }
public string Email { get; set; } = null!;
public string PasswordHash { get; set; } = null!;
public string HardwareId { get; set; } = null!;
public string? Hardware { get; set; }
public string? HardwareHash { get; set; }
public RoleEnum Role { get; set; }
}
+3 -3
View File
@@ -26,15 +26,15 @@ public static class EnumExtensions
}
/// <summary> Get attribute for enum's member, usually is used for getting Description attribute </summary>
public static TAttrib GetEnumAttrib<T, TAttrib>(this T value) where T: Enum
private static TAttrib GetEnumAttrib<T, TAttrib>(this T value) where T: Enum
{
var field = value.GetType().GetField(value.ToString());
if (field == null)
return default;
return default!;
return field.GetCustomAttributes(typeof(TAttrib), false)
.Cast<TAttrib>()
.FirstOrDefault();
.FirstOrDefault()!;
}
/// <summary>
+9 -10
View File
@@ -6,8 +6,8 @@ namespace Azaion.Common.Requests;
public class GetResourceRequest
{
public string Password { get; set; } = null!;
public string HardwareId { get; set; } = null!;
public ResourceEnum ResourceEnum { get; set; }
public HardwareInfo Hardware { get; set; } = null!;
public string FileName { get; set; } = null!;
}
public class GetResourceRequestValidator : AbstractValidator<GetResourceRequest>
@@ -19,14 +19,13 @@ public class GetResourceRequestValidator : AbstractValidator<GetResourceRequest>
.WithErrorCode(ExceptionEnum.PasswordLengthIncorrect.ToString())
.WithMessage(_ => BusinessException.GetMessage(ExceptionEnum.PasswordLengthIncorrect));
RuleFor(r => r.HardwareId)
.MinimumLength(8)
.WithErrorCode(ExceptionEnum.HardwareIdLength.ToString())
.WithMessage(_ => BusinessException.GetMessage(ExceptionEnum.HardwareIdLength));
RuleFor(r => r.Hardware)
.NotEmpty()
.WithMessage(_ => BusinessException.GetMessage(ExceptionEnum.BadHardware));
RuleFor(r => r.ResourceEnum)
.NotEqual(ResourceEnum.None)
.WithErrorCode(ExceptionEnum.WrongResourceType.ToString())
.WithMessage(_ => BusinessException.GetMessage(ExceptionEnum.WrongResourceType));
RuleFor(r => r.FileName)
.NotEmpty()
.WithErrorCode(ExceptionEnum.WrongResourceName.ToString())
.WithMessage(_ => BusinessException.GetMessage(ExceptionEnum.WrongResourceName));
}
}