// Creates a client to Juzusvr with SSL credentials // from a string containing PEM encoded root certificates, // that can validate the certificate presented by the server. public Client(string url, string rootCert) { this.serverURL = url; this.creds = new Grpc.Core.SslCredentials(rootCert); this.channel = new Grpc.Core.Channel(url, this.creds, this.defaultChannelOptions()); this.client = client = new CobaltSpeech.Juzu.Juzu.JuzuClient(channel); }
// Creates a client to Juzusvr with mutually authenticated TLS. // The PEM encoded root certificates, PEM encoded client certificate // and the client's PEM private key must be provided as strings. public Client(string url, string rootCert, string clientCert, string clientKey) { this.serverURL = url; var keyCertPair = new Grpc.Core.KeyCertificatePair(clientCert, clientKey); this.creds = new Grpc.Core.SslCredentials(rootCert, keyCertPair); this.channel = new Grpc.Core.Channel(url, this.creds, this.defaultChannelOptions()); this.client = client = new CobaltSpeech.Juzu.Juzu.JuzuClient(channel); }
public GrpcConnectionProvider( GrpcCore.ChannelCredentials credentials, IRpcClientOptions?options = null, IEnumerable <GrpcCore.ChannelOption>?channelOptions = null) { this.credentials = credentials ?? throw new ArgumentNullException(nameof(credentials)); this.options = options?.AsImmutable(); this.channelOptions = channelOptions?.ToImmutableArrayList(); }
internal GrpcConnection( RpcConnectionInfo connectionInfo, GrpcCore.ChannelCredentials credentials, IRpcClientOptions?options, GrpcProxyGenerator proxyGenerator, IEnumerable <GrpcCore.ChannelOption>?channelOptions) : base(connectionInfo, options, proxyGenerator) { if (connectionInfo?.HostUrl?.Scheme == GrpcConnectionProvider.GrpcScheme) { GrpcCore.ChannelCredentials actualCredentials = credentials; if (options != null) { var callInterceptors = options.Interceptors; if (callInterceptors != null) { int nInterceptors = callInterceptors.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 = callInterceptors[index]; allCallCredentials[index] = GrpcCore.CallCredentials.FromInterceptor((context, metadata) => callInterceptor(new GrpcCallMetadata(metadata))); } callCredentials = GrpcCore.CallCredentials.Compose(allCallCredentials); } else { var callInterceptor = callInterceptors[0]; callCredentials = GrpcCore.CallCredentials.FromInterceptor((context, metadata) => callInterceptor(new GrpcCallMetadata(metadata))); } actualCredentials = GrpcCore.ChannelCredentials.Create(actualCredentials, callCredentials); } } } var allOptions = ExtractOptions(options, channelOptions); this.Channel = new GrpcCore.Channel(connectionInfo.HostUrl.Host, connectionInfo.HostUrl.Port, actualCredentials, allOptions); this.CallInvoker = new GrpcCore.DefaultCallInvoker(this.Channel); this.isSecure = credentials != null && credentials != GrpcCore.ChannelCredentials.Insecure; } else { throw new NotImplementedException($"GrpcConnection is only implemented for the '{nameof(GrpcConnectionProvider.GrpcScheme)}' scheme."); } }
public GrpcConnection( RpcConnectionInfo connectionInfo, GrpcCore.ChannelCredentials credentials, IRpcClientOptions?options = null, IEnumerable <GrpcCore.ChannelOption>?channelOptions = null) : this( connectionInfo, credentials, options, GrpcProxyGenerator.Default, channelOptions) { }
/// <summary> /// Creates a channel that connects to a specific host. /// Port will default to 80 for an unsecure channel and to 443 for a secure channel. /// </summary> /// <param name="target">Target of the channel.</param> /// <param name="credentials">Credentials to secure the channel.</param> /// <param name="options">Channel options.</param> public Channel(string target, ChannelCredentials credentials, IEnumerable<ChannelOption> options = null) { this.target = Preconditions.CheckNotNull(target, "target"); this.environment = GrpcEnvironment.AddRef(); this.options = options != null ? new List<ChannelOption>(options) : new List<ChannelOption>(); EnsureUserAgentChannelOption(this.options); using (CredentialsSafeHandle nativeCredentials = credentials.ToNativeCredentials()) using (ChannelArgsSafeHandle nativeChannelArgs = ChannelOptions.CreateChannelArgs(this.options)) { if (nativeCredentials != null) { this.handle = ChannelSafeHandle.CreateSecure(nativeCredentials, target, nativeChannelArgs); } else { this.handle = ChannelSafeHandle.CreateInsecure(target, nativeChannelArgs); } } }
/// <summary> /// Creates a channel that connects to a specific host. /// Port will default to 80 for an unsecure channel and to 443 for a secure channel. /// </summary> /// <param name="target">Target of the channel.</param> /// <param name="credentials">Credentials to secure the channel.</param> /// <param name="options">Channel options.</param> public Channel(string target, ChannelCredentials credentials, IEnumerable <ChannelOption> options = null) { this.target = GrpcPreconditions.CheckNotNull(target, "target"); this.options = CreateOptionsDictionary(options); EnsureUserAgentChannelOption(this.options); this.environment = GrpcEnvironment.AddRef(); using (var nativeCredentials = credentials.ToNativeCredentials()) using (var nativeChannelArgs = ChannelOptions.CreateChannelArgs(this.options.Values)) { if (nativeCredentials != null) { this.handle = ChannelSafeHandle.CreateSecure(nativeCredentials, target, nativeChannelArgs); } else { this.handle = ChannelSafeHandle.CreateInsecure(target, nativeChannelArgs); } } }
// Creates a client to Juzusvr. If insecure is set // to True, TLS will be disabled. public Client(string url, bool insecure) { this.serverURL = url; if (insecure) { // no TLS this.creds = Grpc.Core.ChannelCredentials.Insecure; } else { // SSL credentials loaded from disk file pointed to by the // GRPC_DEFAULT_SSL_ROOTS_FILE_PATH environment variable. // If that fails, gets the roots certificates from a well // known place on disk. this.creds = new Grpc.Core.SslCredentials(); } this.channel = new Grpc.Core.Channel(url, this.creds, this.defaultChannelOptions()); this.client = client = new CobaltSpeech.Juzu.Juzu.JuzuClient(channel); }
/// <summary> /// Creates a channel that connects to a specific host. /// Port will default to 80 for an unsecure channel or to 443 for a secure channel. /// </summary> /// <param name="target">Target of the channel.</param> /// <param name="credentials">Credentials to secure the channel.</param> /// <param name="options">Channel options.</param> public Channel(string target, ChannelCredentials credentials, IEnumerable <ChannelOption> options) : base(target) { this.options = CreateOptionsDictionary(options); EnsureUserAgentChannelOption(this.options); this.environment = GrpcEnvironment.AddRef(); this.completionQueue = this.environment.PickCompletionQueue(); using (var nativeChannelArgs = ChannelOptions.CreateChannelArgs(this.options.Values)) { var nativeCredentials = credentials.ToNativeCredentials(); if (nativeCredentials != null) { this.handle = ChannelSafeHandle.CreateSecure(nativeCredentials, target, nativeChannelArgs); } else { this.handle = ChannelSafeHandle.CreateInsecure(target, nativeChannelArgs); } } GrpcEnvironment.RegisterChannel(this); }
/// <summary> /// Creates a channel that connects to a specific host. /// Port will default to 80 for an unsecure channel and to 443 for a secure channel. /// </summary> /// <param name="target">Target of the channel.</param> /// <param name="credentials">Credentials to secure the channel.</param> /// <param name="options">Channel options.</param> public Channel(string target, ChannelCredentials credentials, IEnumerable<ChannelOption> options) { this.target = GrpcPreconditions.CheckNotNull(target, "target"); this.options = CreateOptionsDictionary(options); EnsureUserAgentChannelOption(this.options); this.environment = GrpcEnvironment.AddRef(); this.completionQueue = this.environment.PickCompletionQueue(); using (var nativeCredentials = credentials.ToNativeCredentials()) using (var nativeChannelArgs = ChannelOptions.CreateChannelArgs(this.options.Values)) { if (nativeCredentials != null) { this.handle = ChannelSafeHandle.CreateSecure(nativeCredentials, target, nativeChannelArgs); } else { this.handle = ChannelSafeHandle.CreateInsecure(target, nativeChannelArgs); } } GrpcEnvironment.RegisterChannel(this); }
/// <summary> /// Creates a channel that connects to a specific host. /// Port will default to 80 for an unsecure channel and to 443 for a secure channel. /// </summary> /// <param name="target">Target of the channel.</param> /// <param name="credentials">Credentials to secure the channel.</param> public Channel(string target, ChannelCredentials credentials) : this(target, credentials, null) { }
/// <summary> /// Creates a channel that connects to a specific host and port. /// </summary> /// <param name="host">The name or IP address of the host.</param> /// <param name="port">The port.</param> /// <param name="credentials">Credentials to secure the channel.</param> public Channel(string host, int port, ChannelCredentials credentials) : this(host, port, credentials, null) { }
/// <summary> /// Creates a channel that connects to a specific host and port. /// </summary> /// <param name="host">The name or IP address of the host.</param> /// <param name="port">The port.</param> /// <param name="credentials">Credentials to secure the channel.</param> /// <param name="options">Channel options.</param> public Channel(string host, int port, ChannelCredentials credentials, IEnumerable <ChannelOption> options) : this(string.Format("{0}:{1}", host, port), credentials, options) { }
/// <summary> /// Creates a new instance of <c>ChannelCredentials</c> class by composing /// given channel credentials with call credentials. /// </summary> /// <param name="channelCredentials">Channel credentials.</param> /// <param name="callCredentials">Call credentials.</param> /// <returns>The new composite <c>ChannelCredentials</c></returns> public static ChannelCredentials Create(ChannelCredentials channelCredentials, CallCredentials callCredentials) { return new CompositeChannelCredentials(channelCredentials, callCredentials); }
private Channel GetChannel(ServiceEndpoint endpoint, ChannelCredentials credentials) { lock (_lock) { Channel channel; if (!_channels.TryGetValue(endpoint, out channel)) { channel = new Channel(endpoint.Host, endpoint.Port, credentials); _channels[endpoint] = channel; } return channel; } }
/// <summary> /// Initializes a new instance of <c>CompositeChannelCredentials</c> class. /// The resulting credentials object will be composite of all the credentials specified as parameters. /// </summary> /// <param name="channelCredentials">channelCredentials to compose</param> /// <param name="callCredentials">channelCredentials to compose</param> public CompositeChannelCredentials(ChannelCredentials channelCredentials, CallCredentials callCredentials) { this.channelCredentials = GrpcPreconditions.CheckNotNull(channelCredentials); this.callCredentials = GrpcPreconditions.CheckNotNull(callCredentials); GrpcPreconditions.CheckArgument(channelCredentials.IsComposable, "Supplied channel credentials do not allow composition."); }
/// <summary> /// Creates a channel that connects to a specific host and port. /// </summary> /// <param name="host">The name or IP address of the host.</param> /// <param name="port">The port.</param> /// <param name="credentials">Credentials to secure the channel.</param> /// <param name="options">Channel options.</param> public Channel(string host, int port, ChannelCredentials credentials, IEnumerable<ChannelOption> options = null) : this(string.Format("{0}:{1}", host, port), credentials, options) { }
/// <summary> /// Creates a new instance of <c>ChannelCredentials</c> class by composing /// given channel credentials with call credentials. /// </summary> /// <param name="channelCredentials">Channel credentials.</param> /// <param name="callCredentials">Call credentials.</param> /// <returns>The new composite <c>ChannelCredentials</c></returns> public static ChannelCredentials Create(ChannelCredentials channelCredentials, CallCredentials callCredentials) { return(new CompositeChannelCredentials(channelCredentials, callCredentials)); }
/// <summary> /// Configures the credentials to use composite channel credentials (a composite of channel credentials and call credentials). /// </summary> public abstract void SetCompositeCredentials(object state, ChannelCredentials channelCredentials, CallCredentials callCredentials);