Struct etcd::Client [] [src]

pub struct Client<C> where
    C: Clone + Connect
{ /* fields omitted */ }

API client for etcd.

All API calls require a client.

Methods

impl Client<HttpConnector>
[src]

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.

impl Client<HttpsConnector<HttpConnector>>
[src]

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.

impl<C> Client<C> where
    C: Clone + Connect
[src]

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:

extern crate etcd;
extern crate futures;
extern crate hyper;
extern crate hyper_tls;
extern crate native_tls;
extern crate tokio_core;

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

use futures::Future;
use hyper::client::HttpConnector;
use hyper_tls::HttpsConnector;
use native_tls::{Certificate, Pkcs12, TlsConnector};
use tokio_core::reactor::Core;

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().unwrap();
    builder.add_root_certificate(Certificate::from_der(&ca_cert_buffer).unwrap()).unwrap();
    builder.identity(Pkcs12::from_der(&pkcs12_buffer, "secret").unwrap()).unwrap();

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

    let mut core = Core::new().unwrap();
    let handle = core.handle();

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

    let hyper = hyper::Client::configure().connector(https_connector).build(&handle);

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

    let work = kv::set(&client, "/foo", "bar", None).and_then(|_| {
        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(())
        })
    });

    core.run(work).unwrap();
}

Runs a basic health check against each etcd member.

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

Trait Implementations

impl<C: Clone> Clone for Client<C> where
    C: Clone + Connect
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<C: Debug> Debug for Client<C> where
    C: Clone + Connect
[src]

Formats the value using the given formatter.