-
Notifications
You must be signed in to change notification settings - Fork 0
Flow JSON Export #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flow JSON Export #247
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,24 +1,27 @@ | ||||||||||||||||
| use futures::{StreamExt, TryStreamExt}; | ||||||||||||||||
| use prost::Message; | ||||||||||||||||
| use std::sync::Arc; | ||||||||||||||||
| use tokio::fs; | ||||||||||||||||
| use std::{path::Path, sync::Arc}; | ||||||||||||||||
| use tonic::{Extensions, Request, transport::Channel}; | ||||||||||||||||
| use tucana::sagittarius::{ | ||||||||||||||||
| use tucana::{sagittarius::{ | ||||||||||||||||
| FlowLogonRequest, FlowResponse, flow_response::Data, flow_service_client::FlowServiceClient, | ||||||||||||||||
| }; | ||||||||||||||||
| }, shared::{Flows, ValidationFlow}}; | ||||||||||||||||
|
|
||||||||||||||||
| use crate::{authorization::authorization::get_authorization_metadata, flow::get_flow_identifier}; | ||||||||||||||||
|
|
||||||||||||||||
| #[derive(Clone)] | ||||||||||||||||
| pub struct SagittariusFlowClient { | ||||||||||||||||
| store: Arc<async_nats::jetstream::kv::Store>, | ||||||||||||||||
| client: FlowServiceClient<Channel>, | ||||||||||||||||
| env: String, | ||||||||||||||||
| token: String, | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| impl SagittariusFlowClient { | ||||||||||||||||
| pub async fn new( | ||||||||||||||||
| sagittarius_url: String, | ||||||||||||||||
| store: Arc<async_nats::jetstream::kv::Store>, | ||||||||||||||||
| env: String, | ||||||||||||||||
| token: String, | ||||||||||||||||
| ) -> SagittariusFlowClient { | ||||||||||||||||
| let client = match FlowServiceClient::connect(sagittarius_url).await { | ||||||||||||||||
|
|
@@ -35,10 +38,50 @@ impl SagittariusFlowClient { | |||||||||||||||
| SagittariusFlowClient { | ||||||||||||||||
| store, | ||||||||||||||||
| client, | ||||||||||||||||
| env, | ||||||||||||||||
| token, | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| fn is_development(&self) -> bool { | ||||||||||||||||
| self.env == String::from("DEVELOPMENT") | ||||||||||||||||
raphael-goetz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| async fn export_flows_json_overwrite(&self, flows: Flows) { | ||||||||||||||||
| if !self.is_development() { | ||||||||||||||||
| return; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| log::info!("Will export flows into file because env is set to `DEVELOPMENT`"); | ||||||||||||||||
|
|
||||||||||||||||
| let json = match serde_json::to_vec_pretty(&flows) { | ||||||||||||||||
| Ok(b) => b, | ||||||||||||||||
| Err(e) => { | ||||||||||||||||
| log::error!("Failed to serialize flows to JSON: {:?}", e); | ||||||||||||||||
| return; | ||||||||||||||||
| } | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| let final_path = Path::new("flowExport.json"); | ||||||||||||||||
|
||||||||||||||||
| let tmp_path = Path::new("flowExport.json.tmp"); | ||||||||||||||||
|
Comment on lines
+65
to
+66
|
||||||||||||||||
| let final_path = Path::new("flowExport.json"); | |
| let tmp_path = Path::new("flowExport.json.tmp"); | |
| let export_path = std::env::var("FLOW_EXPORT_PATH") | |
| .unwrap_or_else(|_| "flowExport.json".to_string()); | |
| let final_path = Path::new(&export_path); | |
| let tmp_path_string = format!("{}.tmp", export_path); | |
| let tmp_path = Path::new(&tmp_path_string); |
Uh oh!
There was an error while loading. Please reload this page.