Add Application configuration #11

Merged
Wesser merged 128 commits from feat/add-setup into release/v1.0.0 2024-06-01 07:35:30 +03:00
3 changed files with 39 additions and 0 deletions
Showing only changes of commit 0e9bb04b96 - Show all commits

View File

@ -0,0 +1,9 @@
using System;
namespace Mirea.Api.Endpoint.Common.Interfaces;
public interface ISetupToken
{
bool MatchToken(ReadOnlySpan<byte> token);
void SetToken(ReadOnlySpan<byte> token);
}

View File

@ -0,0 +1,28 @@
using Mirea.Api.Endpoint.Common.Interfaces;
using System;
namespace Mirea.Api.Endpoint.Configuration.General;
public class SetupTokenService : ISetupToken
{
public ReadOnlyMemory<byte>? Token { get; private set; }
public bool MatchToken(ReadOnlySpan<byte> token)
{
if (Token == null || token.Length != Token.Value.Length)
return false;
var token2 = Token.Value.Span;
int result = 0;
for (int i = 0; i < Token.Value.Length; i++)
result |= token2[i] ^ token[i];
return result == 0;
}
public void SetToken(ReadOnlySpan<byte> token)
{
Token = token.ToArray();
}
}

View File

@ -8,6 +8,7 @@ using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Mirea.Api.DataAccess.Application;
using Mirea.Api.DataAccess.Persistence;
using Mirea.Api.Endpoint.Common.Interfaces;
using Mirea.Api.Endpoint.Common.Services;
using Mirea.Api.Endpoint.Configuration;
using Mirea.Api.Endpoint.Configuration.General;
@ -50,6 +51,7 @@ public class Program
builder.Services.AddPersistence(builder.Configuration.Get<GeneralConfig>()?.DbSettings?.ConnectionStringSql ?? string.Empty);
builder.Services.AddControllers();
builder.Services.AddSingleton<ISetupToken, SetupTokenService>();
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll", policy =>