TODO: Вынести маппинг модель -> grpc в отдельный слой Signed-off-by: Ivan Pchelintsev <i.pchelintsev@yadro.com>
47 lines
No EOL
1.3 KiB
C#
47 lines
No EOL
1.3 KiB
C#
using FrostFS.Refs;
|
|
using FrostFS.SDK.ModelsV2;
|
|
using FrostFS.Session;
|
|
using Google.Protobuf;
|
|
|
|
namespace FrostFS.SDK.ClientV2;
|
|
|
|
public partial class Client
|
|
{
|
|
public async Task<SessionToken> CreateSessionAsync(ulong expiration)
|
|
{
|
|
var request = new CreateRequest
|
|
{
|
|
Body = new CreateRequest.Types.Body
|
|
{
|
|
OwnerId = new OwnerID
|
|
{
|
|
Value = ByteString.CopyFrom(OwnerId.FromKey(_key).ToHash())
|
|
},
|
|
Expiration = expiration,
|
|
}
|
|
};
|
|
request.AddMetaHeader();
|
|
request.Sign(_key);
|
|
return await CreateSession(request);
|
|
}
|
|
|
|
public async Task<SessionToken> CreateSession(CreateRequest request)
|
|
{
|
|
var resp = await _sessionServiceClient.CreateAsync(request);
|
|
return new SessionToken
|
|
{
|
|
Body = new SessionToken.Types.Body
|
|
{
|
|
Id = resp.Body.Id,
|
|
SessionKey = resp.Body.SessionKey,
|
|
OwnerId = request.Body.OwnerId,
|
|
Lifetime = new SessionToken.Types.Body.Types.TokenLifetime
|
|
{
|
|
Exp = request.Body.Expiration,
|
|
Iat = resp.MetaHeader.Epoch,
|
|
Nbf = resp.MetaHeader.Epoch,
|
|
}
|
|
}
|
|
};
|
|
}
|
|
} |