[#1] Move files to top level directory
Signed-off-by: Ivan Pchelintsev <i.pchelintsev@yadro.com>
This commit is contained in:
parent
013d8a8436
commit
11eff4e23e
76 changed files with 0 additions and 0 deletions
102
src/FrostFS.SDK.ClientV2/Client.cs
Normal file
102
src/FrostFS.SDK.ClientV2/Client.cs
Normal file
|
@ -0,0 +1,102 @@
|
|||
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;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2;
|
||||
|
||||
public partial class Client: IFrostFSClient
|
||||
{
|
||||
private GrpcChannel _channel;
|
||||
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();
|
||||
}
|
||||
|
||||
private void CheckFrostFsVersionSupport()
|
||||
{
|
||||
var localNodeInfo = GetLocalNodeInfoAsync().Result;
|
||||
var frostFsVersion = localNodeInfo.Body.Version.ToModel();
|
||||
if (!frostFsVersion.IsSupported(Version))
|
||||
{
|
||||
var msg = $"FrostFS {frostFsVersion} is not supported.";
|
||||
Console.WriteLine(msg);
|
||||
throw new ApplicationException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitGrpcChannel(string host)
|
||||
{
|
||||
Uri uri;
|
||||
try
|
||||
{
|
||||
uri = new Uri(host);
|
||||
}
|
||||
catch (UriFormatException e)
|
||||
{
|
||||
var msg = $"Host '{host}' has invalid format. Error: {e.Message}";
|
||||
Console.WriteLine(msg);
|
||||
throw new ArgumentException(msg);
|
||||
}
|
||||
|
||||
ChannelCredentials grpcCredentials;
|
||||
switch (uri.Scheme)
|
||||
{
|
||||
case "https":
|
||||
grpcCredentials = ChannelCredentials.SecureSsl;
|
||||
break;
|
||||
case "http":
|
||||
grpcCredentials = ChannelCredentials.Insecure;
|
||||
break;
|
||||
default:
|
||||
var msg = $"Host '{host}' has invalid URI scheme: '{uri.Scheme}'.";
|
||||
Console.WriteLine(msg);
|
||||
throw new ArgumentException(msg);
|
||||
}
|
||||
|
||||
_channel = GrpcChannel.ForAddress(uri, new GrpcChannelOptions { Credentials = grpcCredentials });
|
||||
}
|
||||
|
||||
private void InitContainerClient()
|
||||
{
|
||||
_containerServiceClient = new ContainerService.ContainerServiceClient(_channel);
|
||||
}
|
||||
|
||||
private void InitNetmapClient()
|
||||
{
|
||||
_netmapServiceClient = new NetmapService.NetmapServiceClient(_channel);
|
||||
}
|
||||
|
||||
private void InitObjectClient()
|
||||
{
|
||||
_objectServiceClient = new ObjectService.ObjectServiceClient(_channel);
|
||||
}
|
||||
|
||||
private void InitSessionClient()
|
||||
{
|
||||
_sessionServiceClient = new SessionService.SessionServiceClient(_channel);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue