[#13] Client: Use code analyzers
Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
d7dbbf8da8
commit
d1271df207
102 changed files with 2168 additions and 733 deletions
|
@ -3,22 +3,22 @@ using System.Collections.Generic;
|
|||
using System.Collections.Specialized;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using FrostFS.SDK.ClientV2;
|
||||
using FrostFS.Container;
|
||||
using FrostFS.Refs;
|
||||
using FrostFS.SDK.ClientV2;
|
||||
using FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
using FrostFS.SDK.Cryptography;
|
||||
using FrostFS.Refs;
|
||||
using FrostFS.Session;
|
||||
|
||||
namespace FrostFS.SDK.ClientV2;
|
||||
|
||||
internal class ContainerServiceProvider(ContainerService.ContainerServiceClient service, ClientEnvironment context) : ContextAccessor(context), ISessionProvider
|
||||
internal sealed class ContainerServiceProvider(ContainerService.ContainerServiceClient service, ClientEnvironment context) : ContextAccessor(context), ISessionProvider
|
||||
{
|
||||
readonly SessionProvider sessions = new(context);
|
||||
|
||||
public async ValueTask<SessionToken> GetOrCreateSession(ISessionToken args, Context ctx)
|
||||
{
|
||||
return await sessions.GetOrCreateSession(args, ctx);
|
||||
return await sessions.GetOrCreateSession(args, ctx).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
internal async Task<FrostFsContainerInfo> GetContainerAsync(PrmContainerGet args)
|
||||
|
@ -35,22 +35,29 @@ internal class ContainerServiceProvider(ContainerService.ContainerServiceClient
|
|||
internal async IAsyncEnumerable<FrostFsContainerId> ListContainersAsync(PrmContainerGetAll args)
|
||||
{
|
||||
var ctx = args.Context!;
|
||||
ctx.OwnerId ??= Context.Owner;
|
||||
ctx.Key ??= Context.Key?.ECDsaKey;
|
||||
|
||||
if (ctx.Key == null)
|
||||
throw new InvalidObjectException(nameof(ctx.Key));
|
||||
if (ctx.OwnerId == null)
|
||||
throw new InvalidObjectException(nameof(ctx.OwnerId));
|
||||
|
||||
var request = new ListRequest
|
||||
{
|
||||
Body = new ()
|
||||
Body = new()
|
||||
{
|
||||
OwnerId = ctx.OwnerId.ToMessage()
|
||||
OwnerId = ctx.OwnerId.ToMessage()
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
request.AddMetaHeader(args.XHeaders);
|
||||
request.Sign(ctx.Key);
|
||||
|
||||
var response = await service.ListAsync(request, null, ctx.Deadline, ctx.CancellationToken);
|
||||
|
||||
|
||||
Verifier.CheckResponse(response);
|
||||
|
||||
|
||||
foreach (var cid in response.Body.ContainerIds)
|
||||
{
|
||||
yield return new FrostFsContainerId(Base58.Encode(cid.Value.ToByteArray()));
|
||||
|
@ -63,42 +70,52 @@ internal class ContainerServiceProvider(ContainerService.ContainerServiceClient
|
|||
|
||||
var grpcContainer = args.Container.GetContainer();
|
||||
|
||||
grpcContainer.OwnerId ??= ctx.OwnerId.ToMessage();
|
||||
grpcContainer.Version ??= ctx.Version.ToMessage();
|
||||
grpcContainer.OwnerId ??= ctx.OwnerId?.ToMessage();
|
||||
grpcContainer.Version ??= ctx.Version?.ToMessage();
|
||||
|
||||
if (ctx.Key == null)
|
||||
throw new InvalidObjectException(nameof(ctx.Key));
|
||||
if (grpcContainer.OwnerId == null)
|
||||
throw new InvalidObjectException(nameof(grpcContainer.OwnerId));
|
||||
if (grpcContainer.Version == null)
|
||||
throw new InvalidObjectException(nameof(grpcContainer.Version));
|
||||
|
||||
var request = new PutRequest
|
||||
{
|
||||
Body = new PutRequest.Types.Body
|
||||
{
|
||||
Container = grpcContainer,
|
||||
Signature = ctx.Key.SignRFC6979(grpcContainer)
|
||||
Signature = ctx.Key.SignRFC6979(grpcContainer)
|
||||
}
|
||||
};
|
||||
|
||||
var sessionToken = await GetOrCreateSession(args, ctx);
|
||||
var sessionToken = await GetOrCreateSession(args, ctx).ConfigureAwait(false);
|
||||
|
||||
sessionToken.CreateContainerTokenContext(
|
||||
null,
|
||||
ContainerSessionContext.Types.Verb.Put,
|
||||
ctx.Key,
|
||||
ctx.GetPublicKeyCache());
|
||||
ctx.GetPublicKeyCache()!);
|
||||
|
||||
request.AddMetaHeader(args.XHeaders, sessionToken);
|
||||
|
||||
request.Sign(ctx.Key);
|
||||
|
||||
var response = await service.PutAsync(request, null, ctx.Deadline, ctx.CancellationToken);
|
||||
|
||||
|
||||
Verifier.CheckResponse(response);
|
||||
|
||||
await WaitForContainer(WaitExpects.Exists, response.Body.ContainerId, args.WaitParams, ctx);
|
||||
|
||||
return new FrostFsContainerId(response.Body.ContainerId);
|
||||
await WaitForContainer(WaitExpects.Exists, response.Body.ContainerId, args.WaitParams, ctx).ConfigureAwait(false);
|
||||
|
||||
return new FrostFsContainerId(response.Body.ContainerId);
|
||||
}
|
||||
|
||||
internal async Task DeleteContainerAsync(PrmContainerDelete args)
|
||||
{
|
||||
var ctx = args.Context!;
|
||||
if (ctx.Key == null)
|
||||
throw new InvalidObjectException(nameof(ctx.Key));
|
||||
|
||||
var request = new DeleteRequest
|
||||
{
|
||||
Body = new DeleteRequest.Types.Body
|
||||
|
@ -108,13 +125,13 @@ internal class ContainerServiceProvider(ContainerService.ContainerServiceClient
|
|||
}
|
||||
};
|
||||
|
||||
var sessionToken = await GetOrCreateSession(args, ctx);
|
||||
var sessionToken = await GetOrCreateSession(args, ctx).ConfigureAwait(false);
|
||||
|
||||
sessionToken.CreateContainerTokenContext(
|
||||
request.Body.ContainerId,
|
||||
ContainerSessionContext.Types.Verb.Delete,
|
||||
ctx.Key,
|
||||
ctx.GetPublicKeyCache());
|
||||
ctx.GetPublicKeyCache()!);
|
||||
|
||||
request.AddMetaHeader(args.XHeaders, sessionToken);
|
||||
|
||||
|
@ -124,13 +141,17 @@ internal class ContainerServiceProvider(ContainerService.ContainerServiceClient
|
|||
|
||||
Verifier.CheckResponse(response);
|
||||
|
||||
await WaitForContainer(WaitExpects.Removed, request.Body.ContainerId, args.WaitParams, ctx);
|
||||
|
||||
await WaitForContainer(WaitExpects.Removed, request.Body.ContainerId, args.WaitParams, ctx)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
Verifier.CheckResponse(response);
|
||||
}
|
||||
|
||||
private static GetRequest GetContainerRequest(ContainerID id, NameValueCollection? xHeaders, Context ctx)
|
||||
{
|
||||
if (ctx.Key == null)
|
||||
throw new InvalidObjectException(nameof(ctx.Key));
|
||||
|
||||
var request = new GetRequest
|
||||
{
|
||||
Body = new GetRequest.Types.Body
|
||||
|
@ -146,7 +167,7 @@ internal class ContainerServiceProvider(ContainerService.ContainerServiceClient
|
|||
}
|
||||
|
||||
private enum WaitExpects
|
||||
{
|
||||
{
|
||||
Exists,
|
||||
Removed
|
||||
}
|
||||
|
@ -161,7 +182,7 @@ internal class ContainerServiceProvider(ContainerService.ContainerServiceClient
|
|||
Verifier.CheckResponse(response);
|
||||
}
|
||||
|
||||
await WaitFor(action, expect, waitParams);
|
||||
await WaitFor(action, expect, waitParams).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static async Task WaitFor(
|
||||
|
@ -176,7 +197,7 @@ internal class ContainerServiceProvider(ContainerService.ContainerServiceClient
|
|||
{
|
||||
try
|
||||
{
|
||||
await action();
|
||||
await action().ConfigureAwait(false);
|
||||
|
||||
if (expect == WaitExpects.Exists)
|
||||
return;
|
||||
|
@ -184,20 +205,20 @@ internal class ContainerServiceProvider(ContainerService.ContainerServiceClient
|
|||
if (DateTime.UtcNow >= deadLine)
|
||||
throw new TimeoutException();
|
||||
|
||||
await Task.Delay(waitParams.PollInterval);
|
||||
await Task.Delay(waitParams.PollInterval).ConfigureAwait(false);
|
||||
}
|
||||
catch (ResponseException ex)
|
||||
{
|
||||
if (DateTime.UtcNow >= deadLine)
|
||||
throw new TimeoutException();
|
||||
|
||||
if (ex.Status.Code != FrostFsStatusCode.ContainerNotFound)
|
||||
if (ex.Status?.Code != FrostFsStatusCode.ContainerNotFound)
|
||||
throw;
|
||||
|
||||
if (expect == WaitExpects.Removed)
|
||||
return;
|
||||
|
||||
await Task.Delay(waitParams.PollInterval);
|
||||
await Task.Delay(waitParams.PollInterval).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue