using System.Threading.Tasks; using FrostFS.Session; namespace FrostFS.SDK.Client; internal sealed class SessionServiceProvider : ContextAccessor { private readonly SessionService.SessionServiceClient? _sessionServiceClient; internal SessionServiceProvider(SessionService.SessionServiceClient? sessionServiceClient, ClientContext context) : base(context) { _sessionServiceClient = sessionServiceClient; } internal async Task CreateSessionAsync(PrmSessionCreate args, CallContext ctx) { var request = new CreateRequest { Body = new CreateRequest.Types.Body { OwnerId = ClientContext.Owner.OwnerID, Expiration = args.Expiration } }; request.AddMetaHeader(args.XHeaders); request.Sign(ClientContext.Key.ECDsaKey); return await CreateSession(request, ctx).ConfigureAwait(false); } internal async Task CreateSession(CreateRequest request, CallContext ctx) { var response = await _sessionServiceClient!.CreateAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken); Verifier.CheckResponse(response); return new SessionToken { Body = new SessionToken.Types.Body { Id = response.Body.Id, SessionKey = response.Body.SessionKey, OwnerId = request.Body.OwnerId, Lifetime = new SessionToken.Types.Body.Types.TokenLifetime { Exp = request.Body.Expiration, Iat = response.MetaHeader.Epoch, Nbf = response.MetaHeader.Epoch, } } }; } }