Compare commits

...

4 Commits

Author SHA1 Message Date
Tom
78bab88165 Moved Requests classes to another projects 2024-10-22 07:45:38 +00:00
Tom
a3f3f90817 Added policy message. 2024-10-22 07:45:06 +00:00
Tom
8183678bf0 Added more info to login acknowledgement 2024-10-22 07:44:46 +00:00
Tom
23d407b760 Modified ExpiresIn property to ExpiresAt 2024-10-22 07:44:20 +00:00
7 changed files with 19 additions and 83 deletions

View File

@ -1,9 +0,0 @@
namespace HermesSocketLibrary.Requests
{
public interface IRequest
{
string Name { get; }
Task<RequestResult> Grant(string sender, IDictionary<string, object>? data);
}
}

View File

@ -1,9 +0,0 @@
using HermesSocketLibrary.Socket.Data;
namespace HermesSocketLibrary.Requests
{
public interface IRequestManager
{
Task<RequestResult> Grant(string sender, RequestMessage? message);
}
}

View File

@ -1,41 +0,0 @@
using HermesSocketLibrary.Socket.Data;
using Serilog;
namespace HermesSocketLibrary.Requests
{
public class RequestManager : IRequestManager
{
private readonly IDictionary<string, IRequest> _requests;
private readonly ILogger _logger;
public RequestManager(IEnumerable<IRequest> requests, ILogger logger)
{
_logger = logger;
_requests = requests.ToDictionary(r => r.Name, r => r);
}
public async Task<RequestResult> Grant(string sender, RequestMessage? message)
{
if (message == null || message.Type == null)
return new RequestResult(false, null);
if (!_requests.TryGetValue(message.Type, out IRequest? request) || request == null)
{
_logger.Warning($"Did not find request type '{message.Type}'.");
return new RequestResult(false, null);
}
try
{
return await request.Grant(sender, message.Data);
}
catch (Exception e)
{
_logger.Error(e, $"Failed to grant a request of type '{message.Type}'.");
}
return new RequestResult(false, null);
}
}
}

View File

@ -1,16 +0,0 @@
namespace HermesSocketLibrary.Requests
{
public class RequestResult
{
public bool Success;
public object? Result;
public bool NotifyClientsOnAccount;
public RequestResult(bool success, object? result, bool notifyClientsOnAccount = true)
{
Success = success;
Result = result;
NotifyClientsOnAccount = notifyClientsOnAccount;
}
}
}

View File

@ -1,8 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace HermesSocketLibrary.Socket.Data
{
public class Connection
@ -13,7 +8,7 @@ namespace HermesSocketLibrary.Socket.Data
public string AccessToken { get; set; }
public string GrantType { get; set; }
public string Scope { get; set; }
public DateTime ExpiresIn { get; set; }
public DateTime ExpiresAt { get; set; }
public bool Default { get; set; }
}
}

View File

@ -1,3 +1,5 @@
using HermesSocketLibrary.Requests.Messages;
namespace HermesSocketLibrary.Socket.Data
{
public class LoginAckMessage
@ -9,9 +11,11 @@ namespace HermesSocketLibrary.Socket.Data
public bool WebLogin { get; set; }
public string DefaultTTSVoice { get; set; }
public IEnumerable<string> EnabledTTSVoices { get; set; }
public IList<string> EnabledTTSVoices { get; set; }
public IDictionary<string, string> TTSVoicesAvailable { get; set; }
public Connection[] Connections { get; set; }
public IList<TTSWordFilter> WordFilters { get; set; }
public IList<Connection> Connections { get; set; }
}
}

View File

@ -0,0 +1,12 @@
namespace HermesSocketServer.Models
{
public class PolicyMessage
{
public Guid Id { get; set; }
public string UserId { get; set; }
public Guid GroupId { get; set; }
public string Path { get; set; }
public int Usage { get; set; }
public int Span { get; set; }
}
}