/// <summary> /// Checks if an connection exists for the host and the connection can be reused /// </summary> /// <returns><c>true</c>, if an old connection can be reused, <c>false</c> otherwise</returns> private bool UsingOldConnection() { try { if (!_hostConnectionMap.ContainsKey(_host)) { return(false); } _channel = _hostConnectionMap[_host].Channel; _kvClient = _hostConnectionMap[_host].KvClient; if (HealthCheck()) { return(true); } _hostConnectionMap.TryRemove(_host, out _); } catch { // ignored } return(false); }
public EtcdClient(params Uri[] etcdUrls) { this.channel = new Channel(etcdUrls[0].Host, etcdUrls[0].Port, ChannelCredentials.Insecure); this.kvClient = new KV.KVClient(channel); this.watchClient = new WatchClient(this.channel); this.leaseClient = new LeaseClient(this.channel); var asyncDuplexStreamingCall = leaseClient.LeaseKeepAlive(); this.leaseTTLRefresher = new EtcdLeaseTTLRefresher(asyncDuplexStreamingCall); }
/// <summary> /// Initializes etcd client with no auth over an insecure channel /// </summary> /// <param name="host">etcd server hostname</param> /// <param name="port">etcd server port</param> public EtcdClient(string host, int port) { _host = host; if (UsingOldConnection()) { return; } _channel = new Channel(_host, port, ChannelCredentials.Insecure); _kvClient = new KV.KVClient(_channel); _hostConnectionMap.TryAdd(_host, new Client { Channel = _channel, KvClient = _kvClient }); }
private void Init() { try { if (_publicRootCa) { _channel = new Channel(_host, _port, new SslCredentials()); } else if (_clientSSL) { _channel = new Channel( _host, _port, new SslCredentials( _caCert, new KeyCertificatePair(_clientCert, _clientKey) ) ); } else if (_ssl) { _channel = new Channel(_host, _port, new SslCredentials(_caCert)); } else { _channel = new Channel(_host, _port, ChannelCredentials.Insecure); } if (_basicAuth) { Authenticate(); } _kvClient = new KV.KVClient(_channel); _watchClient = new Watch.WatchClient(_channel); _leaseClient = new Lease.LeaseClient(_channel); _lockClient = new Lock.LockClient(_channel); _clusterClient = new Cluster.ClusterClient(_channel); _maintenanceClient = new Maintenance.MaintenanceClient(_channel); } catch { throw; } _disposed = false; }
/// <summary> /// Initializes etcd client with no auth over an secure channel /// </summary> /// <param name="host">etcd server hostname</param> /// <param name="port">etcd server port</param> /// <param name="cert">Certificate contents to connect to etcd server</param> public EtcdClient(string host, int port, string cert) { _host = host; if (UsingOldConnection()) { return; } var credentials = new SslCredentials(cert); _channel = new Channel(_host, port, credentials); _kvClient = new KV.KVClient(_channel); _hostConnectionMap.TryAdd(_host, new Client { Channel = _channel, KvClient = _kvClient }); }
private void Init() { try { if (_publicRootCa) { _channel = new Channel(_host, _port, new SslCredentials()); } else if (_clientSSL) { _channel = new Channel( _host, _port, new SslCredentials( _caCert, new KeyCertificatePair(_clientCert, _clientKey) ) ); } else if (_ssl) { _channel = new Channel(_host, _port, new SslCredentials(_caCert)); } else { _channel = new Channel(_host, _port, ChannelCredentials.Insecure); } if (_basicAuth) { Authenticate(); } _kvClient = new KV.KVClient(_channel); } catch { throw; } _disposed = false; }
/// <summary> /// Initializes etcd client with basic auth over an insecure channel /// </summary> /// <param name="host">etcd server hostname</param> /// <param name="port">etcd server port</param> /// <param name="username">Username for basic auth on etcd</param> /// <param name="password">Password for basic auth on etcd</param> public EtcdClient(string host, int port, string username, string password) { _host = host; _username = username; _password = password; if (UsingOldConnection()) { return; } Authenticate(); _channel = new Channel(_host, port, ChannelCredentials.Insecure); _kvClient = new KV.KVClient(_channel); _hostConnectionMap.TryAdd(_host, new Client { Channel = _channel, KvClient = _kvClient }); }