-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule_service_client_impl.rs
More file actions
56 lines (52 loc) · 1.88 KB
/
Copy pathmodule_service_client_impl.rs
File metadata and controls
56 lines (52 loc) · 1.88 KB
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
use crate::command::push::auth::get_authorization_metadata;
use crate::formatter::{error_without_trace, info};
use tonic::{Extensions, Request, transport::Channel};
use tucana::sagittarius::ModuleUpdateRequest;
use tucana::sagittarius::module_service_client::ModuleServiceClient;
use tucana::shared::Module;
pub struct SagittariusModuleServiceClient {
client: ModuleServiceClient<Channel>,
token: String,
}
impl SagittariusModuleServiceClient {
pub async fn new(sagittarius_url: String, token: String) -> Self {
let client = match ModuleServiceClient::connect(sagittarius_url).await {
Ok(client) => {
info(String::from(
"Successfully connected to Sagittarius Module Service Endpoint!",
));
client
}
Err(err) => panic!(
"Failed to connect to Sagittarius (Module Service Endpoint): {:?}",
err
),
};
Self { client, token }
}
pub async fn update(&mut self, modules: Vec<Module>) {
let available_defintition_soruces: Vec<String> = modules
.iter()
.map(|x| x.definition_source.clone())
.collect();
let request = Request::from_parts(
get_authorization_metadata(&self.token),
Extensions::new(),
ModuleUpdateRequest {
modules,
available_defintition_soruces,
},
);
match self.client.update(request).await {
Ok(response) => {
info(format!(
"Successfully transferred data types. Did Sagittarius updated them? {:?}",
&response.into_inner().success
));
}
Err(err) => {
error_without_trace(format!("Failed to update DataTypes: {:?}", err));
}
};
}
}