frostfs-sdk-csharp/src/FrostFS.SDK.ClientV2/Services/SessionServiceProvider.cs
Pavel Gross 7b9c19f37c
All checks were successful
DCO / DCO (pull_request) Successful in 47s
[#17] Client: Add extra parameter
API methods' parameters types with optional session, polling settings, xHeaders etc. and corresponding handlers have been added

Signed-off-by: Pavel Gross <p.gross@yadro.com>
2024-07-18 15:33:40 +03:00

57 lines
No EOL
1.8 KiB
C#

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<SessionToken> 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<SessionToken> 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,
}
}
};
}
}