first iteration - base classes and methods Signed-off-by: Pavel Gross <p.gross@yadro.com>
62 lines
No EOL
1.9 KiB
C#
62 lines
No EOL
1.9 KiB
C#
using System.Threading.Tasks;
|
|
|
|
using FrostFS.SDK.ClientV2;
|
|
using FrostFS.SDK.ClientV2.Mappers.GRPC;
|
|
using FrostFS.Session;
|
|
|
|
namespace FrostFS.SDK.ClientV2;
|
|
|
|
internal sealed class SessionServiceProvider : ContextAccessor
|
|
{
|
|
private readonly SessionService.SessionServiceClient? _sessionServiceClient;
|
|
|
|
internal SessionServiceProvider(SessionService.SessionServiceClient? sessionServiceClient, EnvironmentContext context)
|
|
: base(context)
|
|
{
|
|
_sessionServiceClient = sessionServiceClient;
|
|
}
|
|
|
|
internal async Task<SessionToken> CreateSessionAsync(PrmSessionCreate args)
|
|
{
|
|
var ctx = args.Context!;
|
|
|
|
ctx.OwnerId ??= EnvironmentContext.Owner;
|
|
|
|
var request = new CreateRequest
|
|
{
|
|
Body = new CreateRequest.Types.Body
|
|
{
|
|
OwnerId = ctx.OwnerId!.ToMessage(),
|
|
Expiration = args.Expiration
|
|
}
|
|
};
|
|
|
|
request.AddMetaHeader(args.XHeaders);
|
|
request.Sign(ctx.Key!);
|
|
|
|
return await CreateSession(request, args.Context!).ConfigureAwait(false);
|
|
}
|
|
|
|
internal async Task<SessionToken> CreateSession(CreateRequest request, CallContext 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,
|
|
}
|
|
}
|
|
};
|
|
}
|
|
} |