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-27 23:31:36 +00:00
|
|
|
public async 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"]}]");
|
|
|
|
return RequestResult.Successful(policy.GroupId + "/" + policy.Path);
|
|
|
|
}
|
|
|
|
|
|
|
|
_logger.Warning("Failed to find policy by id ");
|
|
|
|
return RequestResult.Failed("Cannot find the policy by id.");
|
2024-10-29 12:14:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|