using System; using System.Linq; using System.Threading.Tasks; using Frostfs.V2.Apemanager; using Google.Protobuf; namespace FrostFS.SDK.Client.Services; internal sealed class ApeManagerServiceProvider : ContextAccessor { private readonly APEManagerService.APEManagerServiceClient? _apeManagerServiceClient; internal ApeManagerServiceProvider(APEManagerService.APEManagerServiceClient? apeManagerServiceClient, ClientContext context) : base(context) { _apeManagerServiceClient = apeManagerServiceClient; } internal async Task> AddChainAsync(PrmApeChainAdd args, CallContext ctx) { var binary = RuleSerializer.Serialize(args.Chain); AddChainRequest request = new() { Body = new() { Chain = new() { Raw = UnsafeByteOperations.UnsafeWrap(binary) }, Target = args.Target.GetChainTarget() } }; request.AddMetaHeader(args.XHeaders); request.Sign(ClientContext.Key); var response = await _apeManagerServiceClient!.AddChainAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken); Verifier.CheckResponse(response); return response.Body.ChainId.Memory; } internal async Task RemoveChainAsync(PrmApeChainRemove args, CallContext ctx) { RemoveChainRequest request = new() { Body = new() { ChainId = UnsafeByteOperations.UnsafeWrap(args.ChainId), Target = args.Target.GetChainTarget() } }; request.AddMetaHeader(args.XHeaders); request.Sign(ClientContext.Key); var response = await _apeManagerServiceClient!.RemoveChainAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken); Verifier.CheckResponse(response); } internal async Task ListChainAsync(PrmApeChainList args, CallContext ctx) { ListChainsRequest request = new() { Body = new() { Target = args.Target.GetChainTarget() } }; request.AddMetaHeader(args.XHeaders); request.Sign(ClientContext.Key); var response = await _apeManagerServiceClient!.ListChainsAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken); Verifier.CheckResponse(response); return [.. response.Body.Chains.Select(c => RuleSerializer.Deserialize([.. c.Raw]))]; } }