frostfs-sdk-csharp/src/FrostFS.SDK.ClientV2/Tools/RequestConstructor.cs
Pavel Gross fefa2da218 [#16] Unit tests
Signed-off-by: Pavel Gross <p.gross@yadro.com>
2024-07-09 17:56:44 +03:00

44 lines
1.3 KiB
C#

using System.Security.Cryptography;
using FrostFS.Refs;
using FrostFS.SDK.ClientV2.Mappers.GRPC;
using FrostFS.SDK.ModelsV2;
using FrostFS.SDK.ProtosV2.Interfaces;
using FrostFS.Session;
namespace FrostFS.SDK.ClientV2;
public static class RequestConstructor
{
public static void AddMetaHeader(this IRequest request, RequestMetaHeader? metaHeader = null)
{
if (request.MetaHeader is not null) return;
metaHeader ??= MetaHeader.Default().ToGrpcMessage();
request.MetaHeader = metaHeader;
}
public static void AddObjectSessionToken(
this IRequest request,
Session.SessionToken sessionToken,
ContainerID cid,
ObjectID oid,
ObjectSessionContext.Types.Verb verb,
ECDsa key)
{
if (request.MetaHeader.SessionToken is not null)
return;
request.MetaHeader.SessionToken = sessionToken;
var ctx = new ObjectSessionContext
{
Target = new ObjectSessionContext.Types.Target
{
Container = cid,
Objects = { oid }
},
Verb = verb
};
request.MetaHeader.SessionToken.Body.Object = ctx;
request.MetaHeader.SessionToken.Signature = key.SignMessagePart(request.MetaHeader.SessionToken.Body);
}
}