Struct etcd::Client

source ·
pub struct Client<C>where
    C: Clone + Connect + Sync + 'static,
{ /* private fields */ }
Expand description

API client for etcd.

All API calls require a client.

Implementations§

Constructs a new client using the HTTP protocol.

Parameters
  • handle: A handle to the event loop.
  • endpoints: URLs for one or more cluster members. When making an API call, the client will make the call to each member in order until it receives a successful respponse.
  • basic_auth: Credentials for HTTP basic authentication.
Errors

Fails if no endpoints are provided or if any of the endpoints is an invalid URL.

Constructs a new client using the HTTPS protocol.

Parameters
  • handle: A handle to the event loop.
  • endpoints: URLs for one or more cluster members. When making an API call, the client will make the call to each member in order until it receives a successful respponse.
  • basic_auth: Credentials for HTTP basic authentication.
Errors

Fails if no endpoints are provided or if any of the endpoints is an invalid URL.

Constructs a new client using the provided hyper::Client.

This method allows the user to configure the details of the underlying HTTP client to their liking. It is also necessary when using X.509 client certificate authentication.

Parameters
  • hyper: A fully configured hyper::Client.
  • endpoints: URLs for one or more cluster members. When making an API call, the client will make the call to each member in order until it receives a successful respponse.
  • basic_auth: Credentials for HTTP basic authentication.
Errors

Fails if no endpoints are provided or if any of the endpoints is an invalid URL.

Examples

Configuring the client to authenticate with both HTTP basic auth and an X.509 client certificate:

use std::fs::File;
use std::io::Read;

use futures::Future;
use hyper::client::HttpConnector;
use hyper_tls::HttpsConnector;
use native_tls::{Certificate, TlsConnector, Identity};
use tokio::runtime::Runtime;

use etcd::{Client, kv};

fn main() {
    let mut ca_cert_file = File::open("ca.der").unwrap();
    let mut ca_cert_buffer = Vec::new();
    ca_cert_file.read_to_end(&mut ca_cert_buffer).unwrap();

    let mut pkcs12_file = File::open("/source/tests/ssl/client.p12").unwrap();
    let mut pkcs12_buffer = Vec::new();
    pkcs12_file.read_to_end(&mut pkcs12_buffer).unwrap();

    let mut builder = TlsConnector::builder();
    builder.add_root_certificate(Certificate::from_der(&ca_cert_buffer).unwrap());
    builder.identity(Identity::from_pkcs12(&pkcs12_buffer, "secret").unwrap());

    let tls_connector = builder.build().unwrap();

    let mut http_connector = HttpConnector::new(4);
    http_connector.enforce_http(false);
    let https_connector = HttpsConnector::from((http_connector, tls_connector));

    let hyper = hyper::Client::builder().build(https_connector);

    let client = Client::custom(hyper, &["https://etcd.example.com:2379"], None).unwrap();

    let work = kv::set(&client, "/foo", "bar", None).and_then(move |_| {
        let get_request = kv::get(&client, "/foo", kv::GetOptions::default());

        get_request.and_then(|response| {
            let value = response.data.node.value.unwrap();

            assert_eq!(value, "bar".to_string());

            Ok(())
        })
    });

    assert!(Runtime::new().unwrap().block_on(work).is_ok());
}

Runs a basic health check against each etcd member.

Returns version information from each etcd cluster member the client was initialized with.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.