From ee1bf293048d01b8751b975a1d52b390620a8907 Mon Sep 17 00:00:00 2001 From: Ivan Pchelintsev Date: Wed, 15 May 2024 11:51:57 +0300 Subject: [PATCH] [#1] Map BasicACL to/from GRPC message Signed-off-by: Ivan Pchelintsev --- .../Mappers/GRPC/Container.cs | 13 ++++++++++++- .../FrostFS.SDK.ClientV2/Services/Container.cs | 1 - sdk/src/FrostFS.SDK.ModelsV2/Container.cs | 4 +++- sdk/src/FrostFS.SDK.ModelsV2/Enums/BasicACL.cs | 18 ++++++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 sdk/src/FrostFS.SDK.ModelsV2/Enums/BasicACL.cs diff --git a/sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Container.cs b/sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Container.cs index d6553bc..bb69aa0 100644 --- a/sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Container.cs +++ b/sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Container.cs @@ -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(basicAclName), + container.PlacementPolicy.ToModel() + ) { Nonce = container.Nonce.ToUuid(), Version = container.Version.ToModel() diff --git a/sdk/src/FrostFS.SDK.ClientV2/Services/Container.cs b/sdk/src/FrostFS.SDK.ClientV2/Services/Container.cs index e85c4c9..aaa9ed9 100644 --- a/sdk/src/FrostFS.SDK.ClientV2/Services/Container.cs +++ b/sdk/src/FrostFS.SDK.ClientV2/Services/Container.cs @@ -36,7 +36,6 @@ public partial class Client public async Task CreateContainerAsync(Container.Container container) { - container.BasicAcl = 0x1FBFBFFF; container.OwnerId = _owner.ToGrpcMessage(); container.Version = Version.ToGrpcMessage(); var request = new PutRequest diff --git a/sdk/src/FrostFS.SDK.ModelsV2/Container.cs b/sdk/src/FrostFS.SDK.ModelsV2/Container.cs index a2fee21..7d798d3 100644 --- a/sdk/src/FrostFS.SDK.ModelsV2/Container.cs +++ b/sdk/src/FrostFS.SDK.ModelsV2/Container.cs @@ -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; } } \ No newline at end of file diff --git a/sdk/src/FrostFS.SDK.ModelsV2/Enums/BasicACL.cs b/sdk/src/FrostFS.SDK.ModelsV2/Enums/BasicACL.cs new file mode 100644 index 0000000..2964f0b --- /dev/null +++ b/sdk/src/FrostFS.SDK.ModelsV2/Enums/BasicACL.cs @@ -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, +} \ No newline at end of file