Skip to content

Commit 5209e6c

Browse files
committed
feat: push command will use module service instead of old service structure
1 parent 854ebac commit 5209e6c

2 files changed

Lines changed: 98 additions & 2 deletions

File tree

crates/cli/src/command/push/mod.rs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
1-
use crate::analyser::core::Analyser;
1+
use tucana::shared::Module;
2+
3+
use crate::{
4+
analyser::core::Analyser, command::parse_errors::fail_on_parser_errors,
5+
command::push::module_service_client_impl::SagittariusModuleServiceClient, parser::Parser,
6+
};
27

38
mod auth;
9+
mod module_service_client_impl;
10+
11+
fn apply_version_to_module(mut module: Module, version: String) -> Module {
12+
module.version = version.clone();
13+
14+
for data_type in &mut module.definition_data_types {
15+
data_type.version = version.clone();
16+
}
17+
for flow_type in &mut module.flow_types {
18+
flow_type.version = version.clone();
19+
}
20+
for runtime_flow_type in &mut module.runtime_flow_types {
21+
runtime_flow_type.version = version.clone();
22+
}
23+
for function in &mut module.function_definitions {
24+
function.version = version.clone();
25+
}
26+
for runtime_function in &mut module.runtime_function_definitions {
27+
runtime_function.version = version.clone();
28+
}
29+
30+
module
31+
}
432

533
pub async fn push(
634
token: String,
@@ -17,5 +45,24 @@ pub async fn push(
1745

1846
let mut analyzer = Analyser::new(dir_path.as_str());
1947
analyzer.report(false, true);
20-
todo!("Implement Sagittarius Module Service Client Endpoint!")
48+
49+
let parser = match Parser::from_path(dir_path.as_str()) {
50+
Some(parser) => parser,
51+
None => {
52+
panic!("Error reading definitions");
53+
}
54+
};
55+
fail_on_parser_errors(&parser);
56+
57+
let mods = parser
58+
.modules
59+
.into_iter()
60+
.map(|definition_module| {
61+
let module = definition_module.into_module();
62+
apply_version_to_module(module, version.clone())
63+
})
64+
.collect::<Vec<_>>();
65+
66+
let mut client = SagittariusModuleServiceClient::new(url, token).await;
67+
client.update(mods).await;
2168
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use crate::command::push::auth::get_authorization_metadata;
2+
use crate::formatter::{error_without_trace, info};
3+
use tonic::{Extensions, Request, transport::Channel};
4+
use tucana::sagittarius::ModuleUpdateRequest;
5+
use tucana::sagittarius::module_service_client::ModuleServiceClient;
6+
use tucana::shared::Module;
7+
8+
pub struct SagittariusModuleServiceClient {
9+
client: ModuleServiceClient<Channel>,
10+
token: String,
11+
}
12+
13+
impl SagittariusModuleServiceClient {
14+
pub async fn new(sagittarius_url: String, token: String) -> Self {
15+
let client = match ModuleServiceClient::connect(sagittarius_url).await {
16+
Ok(client) => {
17+
info(String::from(
18+
"Successfully connected to Sagittarius Module Service Endpoint!",
19+
));
20+
client
21+
}
22+
Err(err) => panic!(
23+
"Failed to connect to Sagittarius (Module Service Endpoint): {:?}",
24+
err
25+
),
26+
};
27+
Self { client, token }
28+
}
29+
30+
pub async fn update(&mut self, modules: Vec<Module>) {
31+
let request = Request::from_parts(
32+
get_authorization_metadata(&self.token),
33+
Extensions::new(),
34+
ModuleUpdateRequest { modules },
35+
);
36+
37+
match self.client.update(request).await {
38+
Ok(response) => {
39+
info(format!(
40+
"Successfully transferred data types. Did Sagittarius updated them? {:?}",
41+
&response.into_inner().success
42+
));
43+
}
44+
Err(err) => {
45+
error_without_trace(format!("Failed to update DataTypes: {:?}", err));
46+
}
47+
};
48+
}
49+
}

0 commit comments

Comments
 (0)