-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathv3_graph_client.rs
52 lines (42 loc) · 1.53 KB
/
v3_graph_client.rs
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
/*
cargo run -p nebula-demo-tokio --bin nebula_demo_tokio_v3_graph_client 127.0.0.1 9669 root 'password'
*/
use std::env;
use fbthrift_transport::{AsyncTransport, AsyncTransportConfiguration};
use nebula_client::v3::{GraphClient, GraphQuery as _, GraphTransportResponseHandler};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
run().await
}
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let domain = env::args()
.nth(1)
.unwrap_or_else(|| env::var("DOMAIN").unwrap_or_else(|_| "127.0.0.1".to_owned()));
let port: u16 = env::args()
.nth(2)
.unwrap_or_else(|| env::var("PORT").unwrap_or_else(|_| "9669".to_owned()))
.parse()
.unwrap();
let username = env::args()
.nth(3)
.unwrap_or_else(|| env::var("USERNAME").unwrap_or_else(|_| "root".to_owned()));
let password = env::args()
.nth(4)
.unwrap_or_else(|| env::var("PASSWORD").unwrap_or_else(|_| "password".to_owned()));
println!("v3_graph_client {domain} {port} {username} {password}",);
//
let addr = format!("{domain}:{port}");
//
let transport = AsyncTransport::with_tokio_tcp_connect(
addr,
AsyncTransportConfiguration::new(GraphTransportResponseHandler),
)
.await?;
let client = GraphClient::new(transport);
let mut session = client
.authenticate(&username.as_bytes().to_vec(), &password.as_bytes().to_vec())
.await?;
let res = session.show_hosts().await?;
println!("{res:?}");
Ok(())
}