frostfs-sdk-csharp/src/FrostFS.SDK.Client/Services/SessionServiceProvider.cs
Pavel Gross 9bb7b5eff8
All checks were successful
lint-build / dotnet8.0 (pull_request) Successful in 55s
DCO / DCO (pull_request) Successful in 1m4s
lint-build / dotnet8.0 (push) Successful in 1m13s
[#28] Clients: Make immutable parameters
Signed-off-by: Pavel Gross <p.gross@yadro.com>
2024-12-02 19:33:45 +03:00

56 lines
No EOL
1.7 KiB
C#

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