2024-12-27 23:31:36 +00:00
|
|
|
using HermesSocketServer.Models;
|
2024-10-29 12:14:27 +00:00
|
|
|
using ILogger = Serilog.ILogger;
|
|
|
|
|
|
|
|
namespace HermesSocketServer.Requests
|
|
|
|
{
|
|
|
|
public class DeletePolicy : IRequest
|
|
|
|
{
|
|
|
|
public string Name => "delete_policy";
|
|
|
|
public string[] RequiredKeys => ["id"];
|
|
|
|
private ILogger _logger;
|
|
|
|
|
2024-12-27 23:31:36 +00:00
|
|
|
public DeletePolicy(ILogger logger)
|
2024-10-29 12:14:27 +00:00
|
|
|
{
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2024-12-28 17:24:02 +00:00
|
|
|
public Task<RequestResult> Grant(Channel channel, IDictionary<string, object> data)
|
2024-10-29 12:14:27 +00:00
|
|
|
{
|
2024-12-27 23:31:36 +00:00
|
|
|
string policyId = data["id"].ToString()!;
|
2024-12-27 22:29:54 +00:00
|
|
|
var policy = channel.Policies.Get(policyId);
|
|
|
|
if (policy != null) {
|
|
|
|
channel.Policies.Remove(policyId);
|
|
|
|
_logger.Information($"Deleted a policy by id [policy id: {data["id"]}]");
|
2024-12-28 17:24:02 +00:00
|
|
|
return Task.FromResult(RequestResult.Successful(policy.GroupId + "/" + policy.Path));
|
2024-12-27 22:29:54 +00:00
|
|
|
}
|
|
|
|
|
2024-12-28 17:24:02 +00:00
|
|
|
_logger.Warning($"Failed to find policy by id [id: {policyId}]");
|
2024-12-31 18:31:21 +00:00
|
|
|
return Task.FromResult(RequestResult.Failed("Policy ID does not exist."));
|
2024-10-29 12:14:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|