44 lines
1.3 KiB
C#
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);
|
|
}
|
|
}
|