using System.Threading.Tasks; using FrostFS.SDK.ClientV2.Mappers.GRPC; using FrostFS.SDK.ClientV2.Parameters; using FrostFS.Session; namespace FrostFS.SDK.ClientV2; internal class SessionServiceProvider : ContextAccessor { private readonly SessionService.SessionServiceClient? _sessionServiceClient; internal SessionServiceProvider(SessionService.SessionServiceClient? sessionServiceClient, ClientEnvironment context) : base (context) { _sessionServiceClient = sessionServiceClient; } internal async Task CreateSessionAsync(PrmCreateSession args) { var request = new CreateRequest { Body = new CreateRequest.Types.Body { OwnerId = Context.Owner.ToGrpcMessage(), Expiration = args.Expiration } }; request.AddMetaHeader(args.XHeaders); request.Sign(Context.Key); return await CreateSession(request, args.Context!); } internal async Task CreateSession(CreateRequest request, Context ctx) { var response = await _sessionServiceClient!.CreateAsync(request, null, ctx.Deadline, 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, } } }; } }