frostfs-sdk-csharp/src/FrostFS.SDK.ClientV2/Services/Container.cs
Ivan Pchelintsev 70ba87bc60 [#1] Read from stream asynchronously
Signed-off-by: Ivan Pchelintsev <i.pchelintsev@yadro.com>
2024-05-22 14:29:20 +03:00

75 lines
No EOL
2.2 KiB
C#

using FrostFS.Container;
using FrostFS.SDK.ClientV2.Mappers.GRPC;
using FrostFS.SDK.ModelsV2;
namespace FrostFS.SDK.ClientV2;
public partial class Client
{
public async Task<ModelsV2.Container> GetContainerAsync(ContainerId cid)
{
var request = new GetRequest
{
Body = new GetRequest.Types.Body
{
ContainerId = cid.ToGrpcMessage()
},
};
request.AddMetaHeader();
request.Sign(_key);
var response = await _containerServiceClient.GetAsync(request);
return response.Body.Container.ToModel();
}
//TODO: Return iterator
public async Task<ContainerId[]> ListContainersAsync()
{
var request = new ListRequest
{
Body = new ListRequest.Types.Body
{
OwnerId = OwnerId.ToGrpcMessage()
}
};
request.AddMetaHeader();
request.Sign(_key);
var response = await _containerServiceClient.ListAsync(request);
return response.Body.ContainerIds.Select(
cid => ContainerId.FromHash(cid.Value.ToByteArray())
).ToArray();
}
public async Task<ContainerId> CreateContainerAsync(ModelsV2.Container container)
{
var cntnr = container.ToGrpcMessage();
cntnr.OwnerId = OwnerId.ToGrpcMessage();
cntnr.Version = Version.ToGrpcMessage();
var request = new PutRequest
{
Body = new PutRequest.Types.Body
{
Container = cntnr,
Signature = _key.SignRFC6979(cntnr),
}
};
request.AddMetaHeader();
request.Sign(_key);
var response = await _containerServiceClient.PutAsync(request);
return ContainerId.FromHash(response.Body.ContainerId.Value.ToByteArray());
}
public async Task DeleteContainerAsync(ContainerId cid)
{
var request = new DeleteRequest
{
Body = new DeleteRequest.Types.Body
{
ContainerId = cid.ToGrpcMessage(),
Signature = _key.SignRFC6979(cid.ToGrpcMessage().Value)
}
};
request.AddMetaHeader();
request.Sign(_key);
await _containerServiceClient.DeleteAsync(request);
}
}