public void Init() { var rootCert = File.ReadAllText(TestCredentials.ClientCertAuthorityPath); var keyCertPair = new KeyCertificatePair( File.ReadAllText(TestCredentials.ServerCertChainPath), File.ReadAllText(TestCredentials.ServerPrivateKeyPath)); var serverCredentials = new SslServerCredentials(new[] { keyCertPair }, rootCert, true); var clientCredentials = new SslCredentials(rootCert, keyCertPair); server = new Server { Services = { TestService.BindService(new TestServiceImpl()) }, Ports = { { Host, ServerPort.PickUnused, serverCredentials } } }; server.Start(); var options = new List<ChannelOption> { new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride) }; channel = new Channel(Host, server.Ports.Single().BoundPort, clientCredentials, options); client = TestService.NewClient(channel); }
public ImageClassifier(Uri address, string folderId, string IamToken, ILoggerFactory loggerFactory) { this.endpointAddress = address; this.IamToken = IamToken; SslCredentials sslCred = new Grpc.Core.SslCredentials(); var chn = GrpcChannel.ForAddress(endpointAddress, new GrpcChannelOptions { LoggerFactory = loggerFactory }); visionClassifierClient = new ImageClassifierService.ImageClassifierServiceClient(chn); }
/// <summary> /// /// </summary> /// <param name="apiKey">API key</param> /// <param name="host">default - api.prefab.cloud:8443</param> /// <param name="timeout">default - 1s</param> public PrefabCloudClient(ApiKey apiKey, string host = @"api.prefab.cloud:8443", TimeSpan?timeout = null) { m_apiKey = apiKey; m_timeout = timeout ?? TimeSpan.FromSeconds(2); var channelCredentials = new Grpc.Core.SslCredentials(); m_channel = new Channel(host, ChannelCredentials.Create( channelCredentials, CallCredentials.FromInterceptor(new AsyncAuthInterceptor((a, b) => Task.Run(() => b.Add("auth", m_apiKey)))))); RateLimitInit(); ConfigInit(); }
public VisionClassifier(Configuration config, ILoggerFactory loggerFactory) { this.config = config; this.log = loggerFactory.CreateLogger <VisionClassifier>(); SslCredentials sslCred = new Grpc.Core.SslCredentials(); var chn = GrpcChannel.ForAddress(endpointAddress, new GrpcChannelOptions { LoggerFactory = loggerFactory }); visionClassifierClient = new VisionService.VisionServiceClient(chn); String outDirectoryPath = Path.Combine(AppContext.BaseDirectory, ClassifyTaskHelper.GetTimestamp(DateTime.Now)); this.outDirectory = Directory.CreateDirectory(outDirectoryPath); this.log.LogInformation($"output directory created: {outDirectoryPath}"); }
public SkRecognitionClient(Uri address, string folderId, string IamToken, RecognitionSpec rSpec, ILoggerFactory loggerFactory, ISkTaskDb taskDb) { this.log = loggerFactory.CreateLogger <SkRecognitionClient>(); this.taskDb = taskDb; this.endpointAddress = address; this.IamToken = IamToken; this.rConf = new RecognitionConfig() { FolderId = folderId, Specification = rSpec }; SslCredentials sslCred = new Grpc.Core.SslCredentials(); var chn = GrpcChannel.ForAddress(endpointAddress, new GrpcChannelOptions { LoggerFactory = loggerFactory }); speechKitRpctClient = new SttService.SttServiceClient(chn); }
public void Init() { var rootCert = File.ReadAllText(TestCredentials.ClientCertAuthorityPath); var keyCertPair = new KeyCertificatePair( File.ReadAllText(TestCredentials.ServerCertChainPath), File.ReadAllText(TestCredentials.ServerPrivateKeyPath)); var serverCredentials = new SslServerCredentials(new[] { keyCertPair }, rootCert); var clientCredentials = new SslCredentials(rootCert, keyCertPair); server = new Server(); server.AddServiceDefinition(TestService.BindService(new TestServiceImpl())); int port = server.AddPort(host, Server.PickUnusedPort, serverCredentials); server.Start(); var options = new List<ChannelOption> { new ChannelOption(ChannelOptions.SslTargetNameOverride, TestCredentials.DefaultHostOverride) }; channel = new Channel(host, port, clientCredentials, options); client = TestService.NewClient(channel); }
/// <summary> /// Convenience method to create a <see cref="ChannelCredentials"/> instance from /// <c>ITokenAccess</c> credential and <c>SslCredentials</c> instance. /// </summary> /// <param name="credential">The credential to use to obtain access tokens.</param> /// <param name="sslCredentials">The <c>SslCredentials</c> instance.</param> /// <returns>The channel credentials for access token based auth over a secure channel.</returns> public static ChannelCredentials Create(ITokenAccess credential, SslCredentials sslCredentials) { return ChannelCredentials.Create(sslCredentials, Create(credential)); }
public static ChannelCredentials CreateChannelCredentials(string userName, string password, string domain, SslCredentials sslCredentials) { AsyncAuthInterceptor asyncAuthInterceptor = CreateAsyncAuthInterceptor(userName, password, domain); return ChannelCredentials.Create(sslCredentials, CallCredentials.FromInterceptor(asyncAuthInterceptor)); }
internal NetGrpcConnection( RpcConnectionInfo connectionInfo, IRpcClientOptions?options, GrpcProxyGenerator proxyGenerator, GrpcNet.Client.GrpcChannelOptions?channelOptions) : base(connectionInfo, options, proxyGenerator) { if (connectionInfo is null) { throw new ArgumentNullException(nameof(connectionInfo)); } var scheme = connectionInfo.HostUrl?.Scheme; if (connectionInfo.HostUrl != null && (scheme == WellKnownRpcSchemes.Grpc || scheme == "https" || scheme == "http")) { GrpcNet.Client.GrpcChannelOptions actualChannelOptions = ExtractOptions(options, channelOptions); this.isSecure = scheme == "https" || scheme == WellKnownRpcSchemes.Grpc; var interceptors = options?.Interceptors ?? ImmutableList <RpcClientCallInterceptor> .Empty; int nInterceptors = interceptors.Count; if (nInterceptors > 0) { GrpcCore.CallCredentials callCredentials; if (nInterceptors > 1) { GrpcCore.CallCredentials[] allCallCredentials = new GrpcCore.CallCredentials[nInterceptors]; for (int index = 0; index < nInterceptors; index++) { var callInterceptor = interceptors[index]; allCallCredentials[index] = GrpcCore.CallCredentials.FromInterceptor((context, metadata) => callInterceptor(new GrpcCallMetadata(metadata))); } callCredentials = GrpcCore.CallCredentials.Compose(allCallCredentials); } else { var callInterceptor = interceptors[0]; callCredentials = GrpcCore.CallCredentials.FromInterceptor((context, metadata) => callInterceptor(new GrpcCallMetadata(metadata))); } var channelCredentials = actualChannelOptions.Credentials; if (channelCredentials == null) { if (this.isSecure) { channelCredentials = new GrpcCore.SslCredentials(); } else { channelCredentials = GrpcCore.ChannelCredentials.Insecure; } } actualChannelOptions.Credentials = GrpcCore.ChannelCredentials.Create(channelCredentials, callCredentials); } var channelUri = scheme == WellKnownRpcSchemes.Grpc ? new Uri($"https://{connectionInfo.HostUrl.Authority}/") : connectionInfo.HostUrl; this.Channel = GrpcNet.Client.GrpcChannel.ForAddress(channelUri, actualChannelOptions); this.CallInvoker = this.Channel.CreateCallInvoker(); } else { throw new NotImplementedException($"NetGrpcConnection is only implemented for the '{WellKnownRpcSchemes.Grpc}' scheme."); } }