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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#![allow(missing_docs, unused_variables, trivial_casts)]
extern crate vault_api;
#[allow(unused_extern_crates)]
extern crate futures;
#[allow(unused_extern_crates)]
extern crate swagger;
#[allow(unused_extern_crates)]
extern crate uuid;
extern crate clap;
#[allow(unused_imports)]
use futures::{Future, future, Stream, stream};
#[allow(unused_imports)]
use vault_api::{ApiNoContext, ContextWrapperExt,
ApiError,
SysLeasesRevokePutResponse,
GenerateCertResponse,
ReadCertResponse,
CreateOrphanTokenResponse,
CreateTokenResponse,
LogInWithTLSCertificateResponse,
RenewOwnTokenResponse
};
use clap::{App, Arg};
fn main() {
let matches = App::new("client")
.arg(Arg::with_name("operation")
.help("Sets the operation to run")
.possible_values(&[
"ReadCert",
"LogInWithTLSCertificate",
])
.required(true)
.index(1))
.arg(Arg::with_name("https")
.long("https")
.help("Whether to use HTTPS or not"))
.arg(Arg::with_name("host")
.long("host")
.takes_value(true)
.default_value("localhost")
.help("Hostname to contact"))
.arg(Arg::with_name("port")
.long("port")
.takes_value(true)
.default_value("8080")
.help("Port to contact"))
.get_matches();
let is_https = matches.is_present("https");
let base_url = format!("{}://{}:{}",
if is_https { "https" } else { "http" },
matches.value_of("host").unwrap(),
matches.value_of("port").unwrap());
let client = if is_https {
// Using Simple HTTPS
vault_api::Client::try_new_https(&base_url, "examples/ca.pem")
.expect("Failed to create HTTPS client")
} else {
// Using HTTP
vault_api::Client::try_new_http(&base_url)
.expect("Failed to create HTTP client")
};
// Using a non-default `Context` is not required; this is just an example!
let client = client.with_context(vault_api::Context::new_with_span_id(self::uuid::Uuid::new_v4().to_string()));
match matches.value_of("operation") {
// Disabled because there's no example.
// Some("SysLeasesRevokePut") => {
// let result = client.sys_leases_revoke_put("x_vault_token_example".to_string(), ???).wait();
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
// },
// Disabled because there's no example.
// Some("GenerateCert") => {
// let result = client.generate_cert("x_vault_token_example".to_string(), "mount_example".to_string(), "name_example".to_string(), ???).wait();
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
// },
Some("ReadCert") => {
let result = client.read_cert("mount_example".to_string(), "serial_example".to_string()).wait();
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
},
// Disabled because there's no example.
// Some("CreateOrphanToken") => {
// let result = client.create_orphan_token("x_vault_token_example".to_string(), ???).wait();
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
// },
// Disabled because there's no example.
// Some("CreateToken") => {
// let result = client.create_token("x_vault_token_example".to_string(), ???).wait();
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
// },
Some("LogInWithTLSCertificate") => {
let result = client.log_in_with_tls_certificate(None).wait();
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
},
// Disabled because there's no example.
// Some("RenewOwnToken") => {
// let result = client.renew_own_token("x_vault_token_example".to_string(), ???).wait();
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
// },
_ => {
panic!("Invalid operation provided")
}
}
}