[#1] Add presentation layer
Signed-off-by: Ivan Pchelintsev <i.pchelintsev@yadro.com>
This commit is contained in:
parent
2800fff041
commit
bb6e187b61
22 changed files with 778 additions and 79 deletions
|
@ -10,6 +10,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FrostFS.SDK.Cryptography",
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FrostFS.SDK.ModelsV2", "src\FrostFS.SDK.ModelsV2\FrostFS.SDK.ModelsV2.csproj", "{3F6E5EE6-2AAC-45BE-A5E2-B83D11F90CC3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FrostFS.SDK.Service", "src\FrostFS.SDK.Service\FrostFS.SDK.Service.csproj", "{5807CC9E-BDA3-48B1-9EF3-F76F0F522981}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -36,5 +38,9 @@ Global
|
|||
{3F6E5EE6-2AAC-45BE-A5E2-B83D11F90CC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3F6E5EE6-2AAC-45BE-A5E2-B83D11F90CC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3F6E5EE6-2AAC-45BE-A5E2-B83D11F90CC3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5807CC9E-BDA3-48B1-9EF3-F76F0F522981}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5807CC9E-BDA3-48B1-9EF3-F76F0F522981}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5807CC9E-BDA3-48B1-9EF3-F76F0F522981}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5807CC9E-BDA3-48B1-9EF3-F76F0F522981}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -1,31 +1,37 @@
|
|||
using System.Security.Cryptography;
|
||||
using FrostFS.Container;
|
||||
using FrostFS.Netmap;
|
||||
using FrostFS.Object;
|
||||
using FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
using FrostFS.SDK.Cryptography;
|
||||
using FrostFS.SDK.ModelsV2;
|
||||
using FrostFS.Session;
|
||||
using Grpc.Core;
|
||||
using Grpc.Net.Client;
|
||||
using Version = FrostFS.SDK.ModelsV2.Version;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2;
|
||||
|
||||
public partial class Client
|
||||
public partial class Client: IFrostFSClient
|
||||
{
|
||||
private readonly ECDsa _key;
|
||||
private GrpcChannel _channel;
|
||||
private Version _version = new (2, 13);
|
||||
private readonly ECDsa _key;
|
||||
private readonly OwnerId _owner;
|
||||
public readonly ModelsV2.Version Version = new (2, 13);
|
||||
|
||||
private ContainerService.ContainerServiceClient _containerServiceClient;
|
||||
private NetmapService.NetmapServiceClient _netmapServiceClient;
|
||||
private ObjectService.ObjectServiceClient _objectServiceClient;
|
||||
private SessionService.SessionServiceClient _sessionServiceClient;
|
||||
|
||||
public Client(string key, string host)
|
||||
{
|
||||
// TODO: Развязать клиент и реализацию GRPC
|
||||
_key = key.LoadWif();
|
||||
_owner = OwnerId.FromKey(_key);
|
||||
InitGrpcChannel(host);
|
||||
InitContainerClient();
|
||||
InitNetmapClient();
|
||||
InitObjectClient();
|
||||
InitSessionClient();
|
||||
CheckFrostFsVersionSupport();
|
||||
}
|
||||
|
@ -33,11 +39,8 @@ public partial class Client
|
|||
private void CheckFrostFsVersionSupport()
|
||||
{
|
||||
var localNodeInfo = GetLocalNodeInfoAsync().Result;
|
||||
var frostFsVersion = new Version(
|
||||
(int)localNodeInfo.Body.Version.Major,
|
||||
(int)localNodeInfo.Body.Version.Minor
|
||||
);
|
||||
if (!frostFsVersion.IsSupported(_version))
|
||||
var frostFsVersion = localNodeInfo.Body.Version.ToModel();
|
||||
if (!frostFsVersion.IsSupported(Version))
|
||||
{
|
||||
var msg = $"FrostFS {frostFsVersion} is not supported.";
|
||||
Console.WriteLine(msg);
|
||||
|
@ -86,6 +89,11 @@ public partial class Client
|
|||
{
|
||||
_netmapServiceClient = new NetmapService.NetmapServiceClient(_channel);
|
||||
}
|
||||
|
||||
private void InitObjectClient()
|
||||
{
|
||||
_objectServiceClient = new ObjectService.ObjectServiceClient(_channel);
|
||||
}
|
||||
|
||||
private void InitSessionClient()
|
||||
{
|
||||
|
|
11
sdk/src/FrostFS.SDK.ClientV2/Interfaces/IFrostFSClient.cs
Normal file
11
sdk/src/FrostFS.SDK.ClientV2/Interfaces/IFrostFSClient.cs
Normal file
|
@ -0,0 +1,11 @@
|
|||
using FrostFS.Refs;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2;
|
||||
|
||||
public interface IFrostFSClient
|
||||
{
|
||||
Task<Container.ListResponse> ListContainersAsync();
|
||||
Task<Container.PutResponse> CreateContainerAsync(Container.Container container);
|
||||
Task<Container.GetResponse> GetContainerAsync(ContainerID containerId);
|
||||
Task<Container.DeleteResponse> DeleteContainerAsync(ContainerID cid);
|
||||
}
|
26
sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Container.cs
Normal file
26
sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Container.cs
Normal file
|
@ -0,0 +1,26 @@
|
|||
using FrostFS.SDK.ClientV2.Mappers.GRPC.Netmap;
|
||||
using FrostFS.SDK.Cryptography;
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
|
||||
public static class ContainerMapper
|
||||
{
|
||||
public static Container.Container ToGrpcMessage(this ModelsV2.Container container)
|
||||
{
|
||||
return new Container.Container
|
||||
{
|
||||
PlacementPolicy = container.PlacementPolicy.ToGrpcMessage(),
|
||||
Nonce = ByteString.CopyFrom(container.Nonce.ToBytes())
|
||||
};
|
||||
}
|
||||
|
||||
public static ModelsV2.Container ToModel(this Container.Container container)
|
||||
{
|
||||
return new ModelsV2.Container(container.PlacementPolicy.ToModel())
|
||||
{
|
||||
Nonce = container.Nonce.ToUuid(),
|
||||
Version = container.Version.ToModel()
|
||||
};
|
||||
}
|
||||
}
|
16
sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/ContainerId.cs
Normal file
16
sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/ContainerId.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using FrostFS.SDK.ModelsV2;
|
||||
using FrostFS.Refs;
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
|
||||
public static class ContainerIdMapper
|
||||
{
|
||||
public static ContainerID ToGrpcMessage(this ContainerId containerId)
|
||||
{
|
||||
return new ContainerID
|
||||
{
|
||||
Value = ByteString.CopyFrom(containerId.ToHash())
|
||||
};
|
||||
}
|
||||
}
|
22
sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/MetaHeader.cs
Normal file
22
sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/MetaHeader.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
using FrostFS.SDK.ModelsV2;
|
||||
using FrostFS.Session;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
|
||||
public static class MetaHeaderMapper
|
||||
{
|
||||
public static RequestMetaHeader ToGrpcMessage(this MetaHeader metaHeader)
|
||||
{
|
||||
return new RequestMetaHeader
|
||||
{
|
||||
Version = new Refs.Version
|
||||
{
|
||||
Major = (uint)metaHeader.Version.Major,
|
||||
Minor = (uint)metaHeader.Version.Minor,
|
||||
|
||||
},
|
||||
Epoch = (uint)metaHeader.Epoch,
|
||||
Ttl = (uint)metaHeader.Ttl
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
using FrostFS.Netmap;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2.Mappers.GRPC.Netmap;
|
||||
|
||||
public static class PlacementPolicyMapper
|
||||
{
|
||||
public static PlacementPolicy ToGrpcMessage(this ModelsV2.Netmap.PlacementPolicy placementPolicy)
|
||||
{
|
||||
var pp = new PlacementPolicy
|
||||
{
|
||||
Filters = { },
|
||||
Selectors = { },
|
||||
Replicas = { },
|
||||
Unique = placementPolicy.Unique
|
||||
};
|
||||
foreach (var replica in placementPolicy.Replicas)
|
||||
{
|
||||
pp.Replicas.Add(replica.ToGrpcMessage());
|
||||
}
|
||||
|
||||
return pp;
|
||||
}
|
||||
|
||||
public static ModelsV2.Netmap.PlacementPolicy ToModel(this PlacementPolicy placementPolicy)
|
||||
{
|
||||
var replicas = new List<ModelsV2.Netmap.Replica>();
|
||||
foreach (var replica in placementPolicy.Replicas)
|
||||
{
|
||||
replicas.Add(replica.ToModel());
|
||||
}
|
||||
|
||||
return new ModelsV2.Netmap.PlacementPolicy(placementPolicy.Unique, replicas.ToArray());
|
||||
}
|
||||
}
|
20
sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Netmap/Replica.cs
Normal file
20
sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Netmap/Replica.cs
Normal file
|
@ -0,0 +1,20 @@
|
|||
using FrostFS.Netmap;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2.Mappers.GRPC.Netmap;
|
||||
|
||||
public static class ReplicaMapper
|
||||
{
|
||||
public static Replica ToGrpcMessage(this ModelsV2.Netmap.Replica replica)
|
||||
{
|
||||
return new Replica
|
||||
{
|
||||
Count = (uint)replica.Count,
|
||||
Selector = replica.Selector
|
||||
};
|
||||
}
|
||||
|
||||
public static ModelsV2.Netmap.Replica ToModel(this Replica replica)
|
||||
{
|
||||
return new ModelsV2.Netmap.Replica((int)replica.Count, replica.Selector);
|
||||
}
|
||||
}
|
16
sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/ObjectId.cs
Normal file
16
sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/ObjectId.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using FrostFS.SDK.ModelsV2;
|
||||
using FrostFS.Refs;
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
|
||||
public static class ObjectIdMapper
|
||||
{
|
||||
public static ObjectID ToGrpcMessage(this ObjectId objectId)
|
||||
{
|
||||
return new ObjectID
|
||||
{
|
||||
Value = ByteString.CopyFrom(objectId.ToHash())
|
||||
};
|
||||
}
|
||||
}
|
16
sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/OwnerId.cs
Normal file
16
sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/OwnerId.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using FrostFS.SDK.ModelsV2;
|
||||
using FrostFS.Refs;
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
|
||||
public static class OwnerIdMapper
|
||||
{
|
||||
public static OwnerID ToGrpcMessage(this OwnerId ownerId)
|
||||
{
|
||||
return new OwnerID
|
||||
{
|
||||
Value = ByteString.CopyFrom(ownerId.ToHash())
|
||||
};
|
||||
}
|
||||
}
|
18
sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Version.cs
Normal file
18
sdk/src/FrostFS.SDK.ClientV2/Mappers/GRPC/Version.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
namespace FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
|
||||
public static class VersionMapper
|
||||
{
|
||||
public static Refs.Version ToGrpcMessage(this ModelsV2.Version version)
|
||||
{
|
||||
return new Refs.Version
|
||||
{
|
||||
Major = (uint)version.Major,
|
||||
Minor = (uint)version.Minor
|
||||
};
|
||||
}
|
||||
|
||||
public static ModelsV2.Version ToModel(this Refs.Version version)
|
||||
{
|
||||
return new ModelsV2.Version((int)version.Major, (int)version.Minor);
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
using FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
using FrostFS.SDK.ModelsV2;
|
||||
using FrostFS.Session;
|
||||
|
||||
|
@ -5,22 +6,10 @@ namespace FrostFS.SDK.ClientV2;
|
|||
|
||||
public static class RequestConstructor
|
||||
{
|
||||
public static void AddMetaHeader(this IRequest request, MetaHeader? metaHeader = null)
|
||||
public static void AddMetaHeader(this IRequest request, RequestMetaHeader? metaHeader = null)
|
||||
{
|
||||
if (request.MetaHeader is not null) return;
|
||||
|
||||
metaHeader ??= MetaHeader.Default();
|
||||
|
||||
request.MetaHeader = new RequestMetaHeader
|
||||
{
|
||||
Version = new Refs.Version
|
||||
{
|
||||
Major = (uint)metaHeader.Version.Major,
|
||||
Minor = (uint)metaHeader.Version.Minor,
|
||||
|
||||
},
|
||||
Epoch = (uint)metaHeader.Epoch,
|
||||
Ttl = (uint)metaHeader.Ttl
|
||||
};
|
||||
metaHeader ??= MetaHeader.Default().ToGrpcMessage();
|
||||
request.MetaHeader = metaHeader;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,13 @@
|
|||
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;
|
||||
using FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2;
|
||||
|
||||
public partial class Client
|
||||
{
|
||||
public async Task<GetResponse> GetContainerAsync(ContainerId containerId)
|
||||
public async Task<GetResponse> GetContainerAsync(ContainerID cid)
|
||||
{
|
||||
var cid = new ContainerID
|
||||
{
|
||||
Value = ByteString.CopyFrom(containerId.ToHash())
|
||||
};
|
||||
var request = new GetRequest
|
||||
{
|
||||
Body = new GetRequest.Types.Body
|
||||
|
@ -34,10 +26,7 @@ public partial class Client
|
|||
{
|
||||
Body = new ListRequest.Types.Body
|
||||
{
|
||||
OwnerId = new OwnerID
|
||||
{
|
||||
Value = ByteString.CopyFrom(OwnerId.FromKey(_key).ToHash())
|
||||
}
|
||||
OwnerId = _owner.ToGrpcMessage()
|
||||
}
|
||||
};
|
||||
request.AddMetaHeader();
|
||||
|
@ -45,36 +34,11 @@ public partial class Client
|
|||
return await _containerServiceClient.ListAsync(request);
|
||||
}
|
||||
|
||||
public async Task<PutResponse> CreateContainerAsync(ModelsV2.Netmap.PlacementPolicy placementPolicy)
|
||||
public async Task<PutResponse> CreateContainerAsync(Container.Container container)
|
||||
{
|
||||
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
|
||||
}
|
||||
);
|
||||
}
|
||||
container.BasicAcl = 0x1FBFBFFF;
|
||||
container.OwnerId = _owner.ToGrpcMessage();
|
||||
container.Version = Version.ToGrpcMessage();
|
||||
var request = new PutRequest
|
||||
{
|
||||
Body = new PutRequest.Types.Body
|
||||
|
@ -88,12 +52,8 @@ public partial class Client
|
|||
return await _containerServiceClient.PutAsync(request);
|
||||
}
|
||||
|
||||
public async Task<DeleteResponse> DeleteContainerAsync(ContainerId containerId)
|
||||
public async Task<DeleteResponse> DeleteContainerAsync(ContainerID cid)
|
||||
{
|
||||
var cid = new ContainerID
|
||||
{
|
||||
Value = ByteString.CopyFrom(containerId.ToHash())
|
||||
};
|
||||
var request = new DeleteRequest
|
||||
{
|
||||
Body = new DeleteRequest.Types.Body
|
||||
|
|
43
sdk/src/FrostFS.SDK.ClientV2/Services/Object.cs
Normal file
43
sdk/src/FrostFS.SDK.ClientV2/Services/Object.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
using FrostFS.Object;
|
||||
using FrostFS.Refs;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2;
|
||||
|
||||
public partial class Client
|
||||
{
|
||||
public async Task<HeadResponse> GetObjectHeadAsync(ContainerID cid, ObjectID oid)
|
||||
{
|
||||
var request = new HeadRequest
|
||||
{
|
||||
Body = new HeadRequest.Types.Body
|
||||
{
|
||||
Address = new Address
|
||||
{
|
||||
ContainerId = cid,
|
||||
ObjectId = oid
|
||||
}
|
||||
},
|
||||
};
|
||||
request.AddMetaHeader();
|
||||
request.Sign(_key);
|
||||
return await _objectServiceClient.HeadAsync(request);
|
||||
}
|
||||
|
||||
public async Task<DeleteResponse> DeleteObjectAsync(ContainerID cid, ObjectID oid)
|
||||
{
|
||||
var request = new DeleteRequest
|
||||
{
|
||||
Body = new DeleteRequest.Types.Body
|
||||
{
|
||||
Address = new Address
|
||||
{
|
||||
ContainerId = cid,
|
||||
ObjectId = oid
|
||||
}
|
||||
}
|
||||
};
|
||||
request.AddMetaHeader();
|
||||
request.Sign(_key);
|
||||
return await _objectServiceClient.DeleteAsync(request);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using FrostFS.Refs;
|
||||
using FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
using FrostFS.SDK.ModelsV2;
|
||||
using FrostFS.Session;
|
||||
using Google.Protobuf;
|
||||
|
@ -13,10 +14,7 @@ public partial class Client
|
|||
{
|
||||
Body = new CreateRequest.Types.Body
|
||||
{
|
||||
OwnerId = new OwnerID
|
||||
{
|
||||
Value = ByteString.CopyFrom(OwnerId.FromKey(_key).ToHash())
|
||||
},
|
||||
OwnerId = _owner.ToGrpcMessage(),
|
||||
Expiration = expiration,
|
||||
}
|
||||
};
|
||||
|
|
16
sdk/src/FrostFS.SDK.ModelsV2/Container.cs
Normal file
16
sdk/src/FrostFS.SDK.ModelsV2/Container.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using FrostFS.SDK.ModelsV2.Netmap;
|
||||
|
||||
namespace FrostFS.SDK.ModelsV2;
|
||||
|
||||
public class Container
|
||||
{
|
||||
public Guid Nonce { get; set; }
|
||||
public PlacementPolicy PlacementPolicy { get; set; }
|
||||
public Version? Version { get; set; }
|
||||
|
||||
public Container(PlacementPolicy placementPolicy)
|
||||
{
|
||||
Nonce = Guid.NewGuid();
|
||||
PlacementPolicy = placementPolicy;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,12 @@ namespace FrostFS.SDK.ModelsV2.Netmap;
|
|||
|
||||
public class PlacementPolicy
|
||||
{
|
||||
public List<Replica> Replicas { get; set; }
|
||||
public bool Unique { get; set; }
|
||||
public Replica[] Replicas { get; init; }
|
||||
public bool Unique { get; init; }
|
||||
|
||||
public PlacementPolicy(bool unique, params Replica[] replicas)
|
||||
{
|
||||
Replicas = replicas;
|
||||
Unique = unique;
|
||||
}
|
||||
}
|
|
@ -3,5 +3,13 @@ namespace FrostFS.SDK.ModelsV2.Netmap;
|
|||
public class Replica
|
||||
{
|
||||
public int Count { get; set; }
|
||||
public string Selector { get; set; } = String.Empty;
|
||||
public string Selector { get; set; }
|
||||
|
||||
public Replica(int count, string? selector = null)
|
||||
{
|
||||
selector ??= string.Empty;
|
||||
|
||||
Count = count;
|
||||
Selector = selector;
|
||||
}
|
||||
}
|
32
sdk/src/FrostFS.SDK.ModelsV2/ObjectId.cs
Normal file
32
sdk/src/FrostFS.SDK.ModelsV2/ObjectId.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
using FrostFS.SDK.Cryptography;
|
||||
|
||||
namespace FrostFS.SDK.ModelsV2;
|
||||
|
||||
public class ObjectId
|
||||
{
|
||||
public string Value { get; }
|
||||
|
||||
public ObjectId(string id)
|
||||
{
|
||||
Value = id;
|
||||
}
|
||||
|
||||
public static ObjectId FromHash(byte[] hash)
|
||||
{
|
||||
if (hash.Length != Helper.Sha256HashLength)
|
||||
{
|
||||
throw new FormatException("ObjectID must be a sha256 hash.");
|
||||
}
|
||||
return new ObjectId(Base58.Encode(hash));
|
||||
}
|
||||
|
||||
public byte[] ToHash()
|
||||
{
|
||||
return Base58.Decode(Value);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Value;
|
||||
}
|
||||
}
|
396
sdk/src/FrostFS.SDK.ProtosV2/object/Extension.Message.cs
Normal file
396
sdk/src/FrostFS.SDK.ProtosV2/object/Extension.Message.cs
Normal file
|
@ -0,0 +1,396 @@
|
|||
using FrostFS.Session;
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace FrostFS.Object
|
||||
{
|
||||
public partial class GetRequest : IRequest
|
||||
{
|
||||
IMetaHeader IVerificableMessage.GetMetaHeader()
|
||||
{
|
||||
return MetaHeader;
|
||||
}
|
||||
|
||||
IVerificationHeader IVerificableMessage.GetVerificationHeader()
|
||||
{
|
||||
return VerifyHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetMetaHeader(IMetaHeader metaHeader)
|
||||
{
|
||||
MetaHeader = (RequestMetaHeader)metaHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetVerificationHeader(IVerificationHeader verificationHeader)
|
||||
{
|
||||
VerifyHeader = (RequestVerificationHeader)verificationHeader;
|
||||
}
|
||||
|
||||
public IMessage GetBody()
|
||||
{
|
||||
return Body;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class GetResponse : IResponse
|
||||
{
|
||||
IMetaHeader IVerificableMessage.GetMetaHeader()
|
||||
{
|
||||
return MetaHeader;
|
||||
}
|
||||
|
||||
IVerificationHeader IVerificableMessage.GetVerificationHeader()
|
||||
{
|
||||
return VerifyHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetMetaHeader(IMetaHeader metaHeader)
|
||||
{
|
||||
MetaHeader = (ResponseMetaHeader)metaHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetVerificationHeader(IVerificationHeader verificationHeader)
|
||||
{
|
||||
VerifyHeader = (ResponseVerificationHeader)verificationHeader;
|
||||
}
|
||||
|
||||
public IMessage GetBody()
|
||||
{
|
||||
return Body;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class PutRequest : IRequest
|
||||
{
|
||||
IMetaHeader IVerificableMessage.GetMetaHeader()
|
||||
{
|
||||
return MetaHeader;
|
||||
}
|
||||
|
||||
IVerificationHeader IVerificableMessage.GetVerificationHeader()
|
||||
{
|
||||
return VerifyHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetMetaHeader(IMetaHeader metaHeader)
|
||||
{
|
||||
MetaHeader = (RequestMetaHeader)metaHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetVerificationHeader(IVerificationHeader verificationHeader)
|
||||
{
|
||||
VerifyHeader = (RequestVerificationHeader)verificationHeader;
|
||||
}
|
||||
|
||||
public IMessage GetBody()
|
||||
{
|
||||
return Body;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class PutResponse : IResponse
|
||||
{
|
||||
IMetaHeader IVerificableMessage.GetMetaHeader()
|
||||
{
|
||||
return MetaHeader;
|
||||
}
|
||||
|
||||
IVerificationHeader IVerificableMessage.GetVerificationHeader()
|
||||
{
|
||||
return VerifyHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetMetaHeader(IMetaHeader metaHeader)
|
||||
{
|
||||
MetaHeader = (ResponseMetaHeader)metaHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetVerificationHeader(IVerificationHeader verificationHeader)
|
||||
{
|
||||
VerifyHeader = (ResponseVerificationHeader)verificationHeader;
|
||||
}
|
||||
|
||||
public IMessage GetBody()
|
||||
{
|
||||
return Body;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class DeleteRequest : IRequest
|
||||
{
|
||||
IMetaHeader IVerificableMessage.GetMetaHeader()
|
||||
{
|
||||
return MetaHeader;
|
||||
}
|
||||
|
||||
IVerificationHeader IVerificableMessage.GetVerificationHeader()
|
||||
{
|
||||
return VerifyHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetMetaHeader(IMetaHeader metaHeader)
|
||||
{
|
||||
MetaHeader = (RequestMetaHeader)metaHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetVerificationHeader(IVerificationHeader verificationHeader)
|
||||
{
|
||||
VerifyHeader = (RequestVerificationHeader)verificationHeader;
|
||||
}
|
||||
|
||||
public IMessage GetBody()
|
||||
{
|
||||
return Body;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class DeleteResponse : IResponse
|
||||
{
|
||||
IMetaHeader IVerificableMessage.GetMetaHeader()
|
||||
{
|
||||
return MetaHeader;
|
||||
}
|
||||
|
||||
IVerificationHeader IVerificableMessage.GetVerificationHeader()
|
||||
{
|
||||
return VerifyHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetMetaHeader(IMetaHeader metaHeader)
|
||||
{
|
||||
MetaHeader = (ResponseMetaHeader)metaHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetVerificationHeader(IVerificationHeader verificationHeader)
|
||||
{
|
||||
VerifyHeader = (ResponseVerificationHeader)verificationHeader;
|
||||
}
|
||||
|
||||
public IMessage GetBody()
|
||||
{
|
||||
return Body;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class HeadRequest : IRequest
|
||||
{
|
||||
IMetaHeader IVerificableMessage.GetMetaHeader()
|
||||
{
|
||||
return MetaHeader;
|
||||
}
|
||||
|
||||
IVerificationHeader IVerificableMessage.GetVerificationHeader()
|
||||
{
|
||||
return VerifyHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetMetaHeader(IMetaHeader metaHeader)
|
||||
{
|
||||
MetaHeader = (RequestMetaHeader)metaHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetVerificationHeader(IVerificationHeader verificationHeader)
|
||||
{
|
||||
VerifyHeader = (RequestVerificationHeader)verificationHeader;
|
||||
}
|
||||
|
||||
public IMessage GetBody()
|
||||
{
|
||||
return Body;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class HeadResponse : IResponse
|
||||
{
|
||||
IMetaHeader IVerificableMessage.GetMetaHeader()
|
||||
{
|
||||
return MetaHeader;
|
||||
}
|
||||
|
||||
IVerificationHeader IVerificableMessage.GetVerificationHeader()
|
||||
{
|
||||
return VerifyHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetMetaHeader(IMetaHeader metaHeader)
|
||||
{
|
||||
MetaHeader = (ResponseMetaHeader)metaHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetVerificationHeader(IVerificationHeader verificationHeader)
|
||||
{
|
||||
VerifyHeader = (ResponseVerificationHeader)verificationHeader;
|
||||
}
|
||||
|
||||
public IMessage GetBody()
|
||||
{
|
||||
return Body;
|
||||
}
|
||||
}
|
||||
public partial class SearchRequest : IRequest
|
||||
{
|
||||
IMetaHeader IVerificableMessage.GetMetaHeader()
|
||||
{
|
||||
return MetaHeader;
|
||||
}
|
||||
|
||||
IVerificationHeader IVerificableMessage.GetVerificationHeader()
|
||||
{
|
||||
return VerifyHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetMetaHeader(IMetaHeader metaHeader)
|
||||
{
|
||||
MetaHeader = (RequestMetaHeader)metaHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetVerificationHeader(IVerificationHeader verificationHeader)
|
||||
{
|
||||
VerifyHeader = (RequestVerificationHeader)verificationHeader;
|
||||
}
|
||||
|
||||
public IMessage GetBody()
|
||||
{
|
||||
return Body;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class SearchResponse : IResponse
|
||||
{
|
||||
IMetaHeader IVerificableMessage.GetMetaHeader()
|
||||
{
|
||||
return MetaHeader;
|
||||
}
|
||||
|
||||
IVerificationHeader IVerificableMessage.GetVerificationHeader()
|
||||
{
|
||||
return VerifyHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetMetaHeader(IMetaHeader metaHeader)
|
||||
{
|
||||
MetaHeader = (ResponseMetaHeader)metaHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetVerificationHeader(IVerificationHeader verificationHeader)
|
||||
{
|
||||
VerifyHeader = (ResponseVerificationHeader)verificationHeader;
|
||||
}
|
||||
|
||||
public IMessage GetBody()
|
||||
{
|
||||
return Body;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class GetRangeRequest : IRequest
|
||||
{
|
||||
IMetaHeader IVerificableMessage.GetMetaHeader()
|
||||
{
|
||||
return MetaHeader;
|
||||
}
|
||||
|
||||
IVerificationHeader IVerificableMessage.GetVerificationHeader()
|
||||
{
|
||||
return VerifyHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetMetaHeader(IMetaHeader metaHeader)
|
||||
{
|
||||
MetaHeader = (RequestMetaHeader)metaHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetVerificationHeader(IVerificationHeader verificationHeader)
|
||||
{
|
||||
VerifyHeader = (RequestVerificationHeader)verificationHeader;
|
||||
}
|
||||
|
||||
public IMessage GetBody()
|
||||
{
|
||||
return Body;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class GetRangeResponse : IResponse
|
||||
{
|
||||
IMetaHeader IVerificableMessage.GetMetaHeader()
|
||||
{
|
||||
return MetaHeader;
|
||||
}
|
||||
|
||||
IVerificationHeader IVerificableMessage.GetVerificationHeader()
|
||||
{
|
||||
return VerifyHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetMetaHeader(IMetaHeader metaHeader)
|
||||
{
|
||||
MetaHeader = (ResponseMetaHeader)metaHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetVerificationHeader(IVerificationHeader verificationHeader)
|
||||
{
|
||||
VerifyHeader = (ResponseVerificationHeader)verificationHeader;
|
||||
}
|
||||
|
||||
public IMessage GetBody()
|
||||
{
|
||||
return Body;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class GetRangeHashRequest : IRequest
|
||||
{
|
||||
IMetaHeader IVerificableMessage.GetMetaHeader()
|
||||
{
|
||||
return MetaHeader;
|
||||
}
|
||||
|
||||
IVerificationHeader IVerificableMessage.GetVerificationHeader()
|
||||
{
|
||||
return VerifyHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetMetaHeader(IMetaHeader metaHeader)
|
||||
{
|
||||
MetaHeader = (RequestMetaHeader)metaHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetVerificationHeader(IVerificationHeader verificationHeader)
|
||||
{
|
||||
VerifyHeader = (RequestVerificationHeader)verificationHeader;
|
||||
}
|
||||
|
||||
public IMessage GetBody()
|
||||
{
|
||||
return Body;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class GetRangeHashResponse : IResponse
|
||||
{
|
||||
IMetaHeader IVerificableMessage.GetMetaHeader()
|
||||
{
|
||||
return MetaHeader;
|
||||
}
|
||||
|
||||
IVerificationHeader IVerificableMessage.GetVerificationHeader()
|
||||
{
|
||||
return VerifyHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetMetaHeader(IMetaHeader metaHeader)
|
||||
{
|
||||
MetaHeader = (ResponseMetaHeader)metaHeader;
|
||||
}
|
||||
|
||||
void IVerificableMessage.SetVerificationHeader(IVerificationHeader verificationHeader)
|
||||
{
|
||||
VerifyHeader = (ResponseVerificationHeader)verificationHeader;
|
||||
}
|
||||
|
||||
public IMessage GetBody()
|
||||
{
|
||||
return Body;
|
||||
}
|
||||
}
|
||||
}
|
13
sdk/src/FrostFS.SDK.Service/FrostFS.SDK.Service.csproj
Normal file
13
sdk/src/FrostFS.SDK.Service/FrostFS.SDK.Service.csproj
Normal file
|
@ -0,0 +1,13 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\FrostFS.SDK.ClientV2\FrostFS.SDK.ClientV2.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
45
sdk/src/FrostFS.SDK.Service/Service.cs
Normal file
45
sdk/src/FrostFS.SDK.Service/Service.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using FrostFS.SDK.ClientV2;
|
||||
using FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
using FrostFS.SDK.ModelsV2;
|
||||
using Google.Protobuf;
|
||||
|
||||
namespace FrostFS.SDK.Service;
|
||||
|
||||
public class FrostFsService
|
||||
{
|
||||
private readonly IFrostFSClient _client;
|
||||
|
||||
public FrostFsService(IFrostFSClient client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public async Task<ContainerId[]> ListContainersAsync()
|
||||
{
|
||||
var containersIds = new List<ContainerId>();
|
||||
var listContainersResponse = await _client.ListContainersAsync();
|
||||
foreach (var cid in listContainersResponse.Body.ContainerIds)
|
||||
{
|
||||
containersIds.Add(ContainerId.FromHash(cid.Value.ToByteArray()));
|
||||
}
|
||||
|
||||
return containersIds.ToArray();
|
||||
}
|
||||
|
||||
public async Task<ContainerId> CreateContainerAsync(ModelsV2.Container container)
|
||||
{
|
||||
var createContainerResponse = await _client.CreateContainerAsync(container.ToGrpcMessage());
|
||||
return ContainerId.FromHash(createContainerResponse.Body.ContainerId.Value.ToByteArray());
|
||||
}
|
||||
|
||||
public async Task<ModelsV2.Container> GetContainerAsync(ContainerId containerId)
|
||||
{
|
||||
var getContainerResponse = await _client.GetContainerAsync(containerId.ToGrpcMessage());
|
||||
return getContainerResponse.Body.Container.ToModel();
|
||||
}
|
||||
|
||||
public async Task DeleteContainerAsync(ContainerId containerId)
|
||||
{
|
||||
var deleteContainerResponse = await _client.DeleteContainerAsync(containerId.ToGrpcMessage());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue