mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-27 09:51:14 +00:00
[AZ-1124] Add PT-10 gRPC stream perf scenario
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using System.Net.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Grpc.Core;
|
||||
using Grpc.Net.Client;
|
||||
using Satellite.V1;
|
||||
@@ -8,15 +10,65 @@ public static class GrpcTestHelpers
|
||||
{
|
||||
public static GrpcChannel CreateChannel(string apiUrl)
|
||||
{
|
||||
var handler = new SocketsHttpHandler
|
||||
{
|
||||
EnableMultipleHttp2Connections = true,
|
||||
};
|
||||
|
||||
var caCertPath = ResolveCaCertPath();
|
||||
if (!string.IsNullOrEmpty(caCertPath))
|
||||
{
|
||||
var caCert = X509Certificate2.CreateFromPemFile(caCertPath);
|
||||
handler.SslOptions = new SslClientAuthenticationOptions
|
||||
{
|
||||
RemoteCertificateValidationCallback = (_, certificate, _, errors) =>
|
||||
{
|
||||
if (errors == SslPolicyErrors.None)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (certificate is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using var chain = new X509Chain();
|
||||
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
|
||||
chain.ChainPolicy.CustomTrustStore.Add(caCert);
|
||||
chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
|
||||
return chain.Build(new X509Certificate2(certificate));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
return GrpcChannel.ForAddress(apiUrl, new GrpcChannelOptions
|
||||
{
|
||||
HttpHandler = new SocketsHttpHandler
|
||||
{
|
||||
EnableMultipleHttp2Connections = true,
|
||||
},
|
||||
HttpHandler = handler,
|
||||
});
|
||||
}
|
||||
|
||||
private static string? ResolveCaCertPath()
|
||||
{
|
||||
var explicitPath = Environment.GetEnvironmentVariable("PERF_CA_CERT");
|
||||
if (!string.IsNullOrWhiteSpace(explicitPath) && File.Exists(explicitPath))
|
||||
{
|
||||
return explicitPath;
|
||||
}
|
||||
|
||||
var projectRoot = Environment.GetEnvironmentVariable("PROJECT_ROOT");
|
||||
if (!string.IsNullOrWhiteSpace(projectRoot))
|
||||
{
|
||||
var defaultPath = Path.Combine(projectRoot, "certs", "api.crt");
|
||||
if (File.Exists(defaultPath))
|
||||
{
|
||||
return defaultPath;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static RouteTileDelivery.RouteTileDeliveryClient CreateClient(string apiUrl, string jwtToken)
|
||||
{
|
||||
var channel = CreateChannel(apiUrl);
|
||||
|
||||
Reference in New Issue
Block a user