Fixed issues with creating/deleting connection messages.
This commit is contained in:
@ -7,7 +7,7 @@ namespace HermesSocketServer.Requests
|
|||||||
public class CreateConnection : IRequest
|
public class CreateConnection : IRequest
|
||||||
{
|
{
|
||||||
public string Name => "create_connection";
|
public string Name => "create_connection";
|
||||||
public string[] RequiredKeys => ["name", "type", "clientId", "accessToken", "grantType", "scope", "expiration"];
|
public string[] RequiredKeys => ["name", "type", "client_id", "access_token", "grant_type", "scope", "expiration"];
|
||||||
private ILogger _logger;
|
private ILogger _logger;
|
||||||
|
|
||||||
public CreateConnection(ILogger logger)
|
public CreateConnection(ILogger logger)
|
||||||
@ -19,9 +19,9 @@ namespace HermesSocketServer.Requests
|
|||||||
{
|
{
|
||||||
string name = data["name"].ToString()!;
|
string name = data["name"].ToString()!;
|
||||||
string type = data["type"].ToString()!;
|
string type = data["type"].ToString()!;
|
||||||
string clientId = data["clientId"].ToString()!;
|
string clientId = data["client_id"].ToString()!;
|
||||||
string accessToken = data["accessToken"].ToString()!;
|
string accessToken = data["access_token"].ToString()!;
|
||||||
string grantType = data["grantType"].ToString()!;
|
string grantType = data["grant_type"].ToString()!;
|
||||||
string scope = data["scope"].ToString()!;
|
string scope = data["scope"].ToString()!;
|
||||||
if (!DateTime.TryParse(data["expiration"].ToString()!, out var expiresAt))
|
if (!DateTime.TryParse(data["expiration"].ToString()!, out var expiresAt))
|
||||||
return Task.FromResult(RequestResult.Failed("Expiration needs to be a date time string."));
|
return Task.FromResult(RequestResult.Failed("Expiration needs to be a date time string."));
|
||||||
|
@ -6,7 +6,7 @@ namespace HermesSocketServer.Requests
|
|||||||
public class DeleteConnection : IRequest
|
public class DeleteConnection : IRequest
|
||||||
{
|
{
|
||||||
public string Name => "delete_connection";
|
public string Name => "delete_connection";
|
||||||
public string[] RequiredKeys => ["id"];
|
public string[] RequiredKeys => ["name"];
|
||||||
private ILogger _logger;
|
private ILogger _logger;
|
||||||
|
|
||||||
public DeleteConnection(ILogger logger)
|
public DeleteConnection(ILogger logger)
|
||||||
@ -16,16 +16,16 @@ namespace HermesSocketServer.Requests
|
|||||||
|
|
||||||
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
|
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
|
||||||
{
|
{
|
||||||
var connectionId = data["id"].ToString()!;
|
var connectionName = data["name"].ToString()!;
|
||||||
|
|
||||||
var result = channel.Connections.Remove(connectionId);
|
var result = channel.Connections.Remove(connectionName);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
_logger.Information($"Deleted a connection by id [connection id: {connectionId}]");
|
_logger.Information($"Deleted a connection by name [connection name: {connectionName}]");
|
||||||
return Task.FromResult(RequestResult.Successful(null));
|
return Task.FromResult(RequestResult.Successful(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.Warning($"Connection Id does not exist [connection id: {connectionId}]");
|
_logger.Warning($"Connection Name does not exist [connection name: {connectionName}]");
|
||||||
return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache."));
|
return Task.FromResult(RequestResult.Failed("Something went wrong when updating the cache."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ namespace HermesSocketServer.Store
|
|||||||
Default = reader.GetBoolean(7),
|
Default = reader.GetBoolean(7),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
_logger.Information($"Loaded {_store.Count} groups from database.");
|
_logger.Information($"Loaded {_store.Count} connections from database.");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnInitialAdd(string key, Connection value)
|
protected override void OnInitialAdd(string key, Connection value)
|
||||||
|
Reference in New Issue
Block a user