frostfs-sdk-csharp/src/FrostFS.SDK.ClientV2/Models/Containers/FrostFsContainerInfo.cs
Pavel Gross d7dbbf8da8
All checks were successful
DCO / DCO (pull_request) Successful in 34s
[#24] Client: Add Ape manager
Signed-off-by: Pavel Gross <p.gross@yadro.com>
2024-09-23 10:20:40 +03:00

107 lines
No EOL
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using FrostFS.SDK.ClientV2;
using FrostFS.SDK.Cryptography;
using FrostFS.SDK.ClientV2.Mappers.GRPC;
using Google.Protobuf;
namespace FrostFS.SDK;
public class FrostFsContainerInfo
{
private FrostFS.Container.Container.Types.Attribute[]? grpsAttributes;
private List<FrostFsAttribute>? attributes;
private FrostFsPlacementPolicy? placementPolicy;
private Guid? nonce;
private Container.Container container;
public FrostFsContainerInfo(
BasicAcl basicAcl,
FrostFsPlacementPolicy placementPolicy,
List<FrostFsAttribute>? attributes = null,
FrostFsVersion? version = null,
FrostFsOwner? owner = null,
Guid? nonce = null)
{
BasicAcl = basicAcl;
this.placementPolicy = placementPolicy;
this.attributes = attributes;
Version = version;
Owner = owner;
this.nonce = nonce;
}
internal FrostFsContainerInfo(Container.Container container)
{
this.container = container;
}
public Guid Nonce
{
get
{
nonce ??= container?.Nonce != null ? container.Nonce.ToUuid() : Guid.NewGuid();
return nonce.Value;
}
}
public BasicAcl BasicAcl { get; private set; }
public FrostFsPlacementPolicy? PlacementPolicy
{
get
{
placementPolicy ??= container.PlacementPolicy?.ToModel();
return placementPolicy;
}
}
public List<FrostFsAttribute>? Attributes
{
get
{
if (attributes == null && grpsAttributes != null)
attributes = grpsAttributes.Select(a => new FrostFsAttribute(a.Key, a.Value)).ToList();
return attributes;
}
}
public FrostFsVersion? Version { get; private set; }
public FrostFsOwner? Owner { get; private set; }
internal Container.Container.Types.Attribute[]? GetGrpsAttributes()
{
grpsAttributes ??= Attributes?
.Select(a => new Container.Container.Types.Attribute { Key = a.Key, Value = a.Value })
.ToArray();
return grpsAttributes;
}
internal Container.Container GetContainer()
{
if (this.container == null)
{
this.container = new Container.Container()
{
BasicAcl = (uint)BasicAcl,
PlacementPolicy = PlacementPolicy.ToMessage(),
Nonce = ByteString.CopyFrom(Nonce.ToBytes()),
OwnerId = Owner?.OwnerID,
Version = Version?.Version
};
var attribs = GetGrpsAttributes();
if (attribs != null)
this.container.Attributes.AddRange(attribs);
}
return this.container;
}
}