[#1] Define SDK structure
TODO: Вынести маппинг модель -> grpc в отдельный слой Signed-off-by: Ivan Pchelintsev <i.pchelintsev@yadro.com>
This commit is contained in:
parent
905f683bf1
commit
2800fff041
57 changed files with 5760 additions and 0 deletions
130
sdk/src/FrostFS.SDK.ClientV2/Services/Container.cs
Normal file
130
sdk/src/FrostFS.SDK.ClientV2/Services/Container.cs
Normal file
|
@ -0,0 +1,130 @@
|
|||
using FrostFS.Container;
|
||||
using FrostFS.Netmap;
|
||||
using FrostFS.Refs;
|
||||
using FrostFS.SDK.Cryptography;
|
||||
using FrostFS.SDK.ModelsV2;
|
||||
using Google.Protobuf;
|
||||
using Version = FrostFS.Refs.Version;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2;
|
||||
|
||||
public partial class Client
|
||||
{
|
||||
public async Task<GetResponse> GetContainerAsync(ContainerId containerId)
|
||||
{
|
||||
var cid = new ContainerID
|
||||
{
|
||||
Value = ByteString.CopyFrom(containerId.ToHash())
|
||||
};
|
||||
var request = new GetRequest
|
||||
{
|
||||
Body = new GetRequest.Types.Body
|
||||
{
|
||||
ContainerId = cid
|
||||
},
|
||||
};
|
||||
request.AddMetaHeader();
|
||||
request.Sign(_key);
|
||||
return await _containerServiceClient.GetAsync(request);
|
||||
}
|
||||
|
||||
public async Task<ListResponse> ListContainersAsync()
|
||||
{
|
||||
var request = new ListRequest
|
||||
{
|
||||
Body = new ListRequest.Types.Body
|
||||
{
|
||||
OwnerId = new OwnerID
|
||||
{
|
||||
Value = ByteString.CopyFrom(OwnerId.FromKey(_key).ToHash())
|
||||
}
|
||||
}
|
||||
};
|
||||
request.AddMetaHeader();
|
||||
request.Sign(_key);
|
||||
return await _containerServiceClient.ListAsync(request);
|
||||
}
|
||||
|
||||
public async Task<PutResponse> CreateContainerAsync(ModelsV2.Netmap.PlacementPolicy placementPolicy)
|
||||
{
|
||||
var container = new Container.Container
|
||||
{
|
||||
Version = new Version
|
||||
{
|
||||
Major = 2,
|
||||
Minor = 13
|
||||
},
|
||||
OwnerId = new OwnerID
|
||||
{
|
||||
Value = ByteString.CopyFrom(OwnerId.FromKey(_key).ToHash())
|
||||
},
|
||||
PlacementPolicy = new PlacementPolicy
|
||||
{
|
||||
Filters = { },
|
||||
Selectors = { },
|
||||
Replicas = { }
|
||||
},
|
||||
Nonce = ByteString.CopyFrom(Guid.NewGuid().ToBytes())
|
||||
};
|
||||
foreach (var replica in placementPolicy.Replicas)
|
||||
{
|
||||
container.PlacementPolicy.Replicas.Add(new Replica
|
||||
{
|
||||
Count = (uint)replica.Count,
|
||||
Selector = replica.Selector
|
||||
}
|
||||
);
|
||||
}
|
||||
var request = new PutRequest
|
||||
{
|
||||
Body = new PutRequest.Types.Body
|
||||
{
|
||||
Container = container,
|
||||
Signature = _key.SignRFC6979(container),
|
||||
}
|
||||
};
|
||||
request.AddMetaHeader();
|
||||
request.Sign(_key);
|
||||
return await _containerServiceClient.PutAsync(request);
|
||||
}
|
||||
|
||||
public async Task<DeleteResponse> DeleteContainerAsync(ContainerId containerId)
|
||||
{
|
||||
var cid = new ContainerID
|
||||
{
|
||||
Value = ByteString.CopyFrom(containerId.ToHash())
|
||||
};
|
||||
var request = new DeleteRequest
|
||||
{
|
||||
Body = new DeleteRequest.Types.Body
|
||||
{
|
||||
ContainerId = cid,
|
||||
Signature = _key.SignRFC6979(cid.Value)
|
||||
}
|
||||
};
|
||||
request.AddMetaHeader();
|
||||
request.Sign(_key);
|
||||
return await _containerServiceClient.DeleteAsync(request);
|
||||
}
|
||||
|
||||
// private void PrepareContainerSessionToken(RequestMetaHeader meta, SessionToken sessionToken, ContainerID? cid,
|
||||
// ContainerSessionContext.Types.Verb verb)
|
||||
// {
|
||||
// if (meta.SessionToken is not null) return;
|
||||
// meta.SessionToken = sessionToken;
|
||||
// var ctx = new ContainerSessionContext
|
||||
// {
|
||||
// Verb = verb
|
||||
// };
|
||||
// if (cid is null)
|
||||
// {
|
||||
// ctx.Wildcard = true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ctx.ContainerId = cid;
|
||||
// }
|
||||
// meta.SessionToken.Body.Container = ctx;
|
||||
// meta.SessionToken.Signature = _key.SignMessagePart(meta.SessionToken.Body);
|
||||
// }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue