[#1] Map BasicACL to/from GRPC message

Signed-off-by: Ivan Pchelintsev <i.pchelintsev@yadro.com>
This commit is contained in:
Ivan Pchelintsev 2024-05-15 11:51:57 +03:00
parent bb6e187b61
commit ee1bf29304
4 changed files with 33 additions and 3 deletions

View file

@ -1,3 +1,4 @@
using System.Runtime.InteropServices.ComTypes;
using FrostFS.SDK.ClientV2.Mappers.GRPC.Netmap;
using FrostFS.SDK.Cryptography;
using Google.Protobuf;
@ -10,6 +11,7 @@ public static class ContainerMapper
{
return new Container.Container
{
BasicAcl = (uint)container.BasicAcl,
PlacementPolicy = container.PlacementPolicy.ToGrpcMessage(),
Nonce = ByteString.CopyFrom(container.Nonce.ToBytes())
};
@ -17,7 +19,16 @@ public static class ContainerMapper
public static ModelsV2.Container ToModel(this Container.Container container)
{
return new ModelsV2.Container(container.PlacementPolicy.ToModel())
var basicAclName = Enum.GetName(typeof(ModelsV2.Enums.BasicACL), container.BasicAcl);
if (basicAclName is null)
{
throw new ArgumentException($"Unknown BasicACL rule. Value: '{container.BasicAcl}'.");
}
return new ModelsV2.Container(
Enum.Parse<ModelsV2.Enums.BasicACL>(basicAclName),
container.PlacementPolicy.ToModel()
)
{
Nonce = container.Nonce.ToUuid(),
Version = container.Version.ToModel()

View file

@ -36,7 +36,6 @@ public partial class Client
public async Task<PutResponse> CreateContainerAsync(Container.Container container)
{
container.BasicAcl = 0x1FBFBFFF;
container.OwnerId = _owner.ToGrpcMessage();
container.Version = Version.ToGrpcMessage();
var request = new PutRequest

View file

@ -5,12 +5,14 @@ namespace FrostFS.SDK.ModelsV2;
public class Container
{
public Guid Nonce { get; set; }
public Enums.BasicACL BasicAcl { get; set; }
public PlacementPolicy PlacementPolicy { get; set; }
public Version? Version { get; set; }
public Container(PlacementPolicy placementPolicy)
public Container(Enums.BasicACL basicAcl, PlacementPolicy placementPolicy)
{
Nonce = Guid.NewGuid();
BasicAcl = basicAcl;
PlacementPolicy = placementPolicy;
}
}

View file

@ -0,0 +1,18 @@
using System.ComponentModel;
namespace FrostFS.SDK.ModelsV2.Enums;
public enum BasicACL
{
[Description("Basic ACL for private container")]
Private = 0x1C8C8CCC,
[Description("Basic ACL for public RO container")]
PublicRO = 0x1FBF8CFF,
[Description("Basic ACL for public RW container")]
PublicRW = 0x1FBFBFFF,
[Description("Basic ACL for public append container")]
PublicAppend = 0x1FBF9FFF,
}