1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

#![deny(missing_docs,
        missing_debug_implementations,
        trivial_casts,
        trivial_numeric_casts,
        unsafe_code,
        unstable_features,
        unused_import_braces,
        unused_qualifications,
        unused_results)]
#![cfg_attr(test, deny(warnings))]
#![cfg_attr(feature = "clippy", allow(unstable_features))]
#![cfg_attr(feature = "clippy", feature(plugin))]
#![cfg_attr(feature = "clippy", plugin(clippy))]
#![cfg_attr(feature = "clippy", deny(clippy))]

//! Client API for interacting with [Vault](https://www.vaultproject.io/docs/http/index.html)

#[macro_use]
extern crate hyper;
#[macro_use]
extern crate log;
extern crate rustc_serialize;
#[macro_use]
extern crate quick_error;
extern crate chrono;

/// vault client
pub mod client;
pub use client::VaultClient as Client;
pub use client::error::Error;

#[cfg(test)]
mod tests {
    use client::VaultClient as Client;

    #[test]
    fn it_can_create_a_client() {
        let host = "http://127.0.0.1:8200";
        let token = "test12345";
        let _ = Client::new(host, token).unwrap();
    }

    #[test]
    fn it_can_query_secrets() {
        let host = "http://127.0.0.1:8200";
        let token = "test12345";
        let client = Client::new(host, token).unwrap();
        println!("Created client!");
        let res = client.set_secret("hello_query", "world");
        assert!(res.is_ok());
        let res = client.get_secret("hello_query").unwrap();
        assert_eq!(res, "world");
    }

    #[test]
    fn it_can_write_secrets_with_newline() {
        let host = "http://127.0.0.1:8200";
        let token = "test12345";
        let client = Client::new(host, token).unwrap();

        let res = client.set_secret("hello_set", "world\n");
        assert!(res.is_ok());
        let res = client.get_secret("hello_set").unwrap();
        assert_eq!(res, "world\n");
    }
    #[test]
    fn it_returns_err_on_forbidden() {
        let host = "http://127.0.0.1:8200";
        let token = "test123456";
        let client = Client::new(host, token);
        // assert_eq!(Err("Forbidden".to_string()), client);
        assert!(client.is_err());
    }

    #[test]
    fn it_can_delete_a_secret() {
        let host = "http://127.0.0.1:8200";
        let token = "test12345";
        let client = Client::new(host, token).unwrap();

        let res = client.set_secret("hello_delete", "world");
        assert!(res.is_ok());
        let res = client.get_secret("hello_delete").unwrap();
        assert_eq!(res, "world");
        let res = client.delete_secret("hello_delete");
        assert!(res.is_ok());
        let res = client.get_secret("hello_delete");
        assert!(res.is_err());
    }
}