From 55b7a07585c63e5fac5504169c3734183778013e Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 12 Apr 2026 01:22:19 +0200 Subject: [PATCH 1/3] feat: added auth metadata function --- src/flow_service/auth.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/flow_service/auth.rs diff --git a/src/flow_service/auth.rs b/src/flow_service/auth.rs new file mode 100644 index 0000000..cc60dfd --- /dev/null +++ b/src/flow_service/auth.rs @@ -0,0 +1,29 @@ +use std::str::FromStr; +use tonic::metadata::{MetadataMap, MetadataValue}; + +/// get_authorization_metadata +/// +/// Creates a `MetadataMap` that contains the defined token as a value of the `authorization` key +/// Used for setting the runtime_token to authorize Sagittarius request +/// +/// # Examples +/// +/// ``` +/// use aquila_grpc::get_authorization_metadata; +/// let token = String::from("token"); +/// let metadata = get_authorization_metadata(&token); +/// assert!(metadata.get("authorization").is_some()); +/// assert_eq!(metadata.get("authorization").unwrap(), "token"); +/// ``` +pub fn get_authorization_metadata(token: &str) -> MetadataMap { + let metadata_value = MetadataValue::from_str(token).unwrap_or_else(|error| { + panic!( + "An error occurred trying to convert runtime_token into metadata: {}", + error + ); + }); + + let mut map = MetadataMap::new(); + map.insert("authorization", metadata_value); + map +} From 960de32f143d16f88455c389610a550d3ad1ae3a Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 12 Apr 2026 01:22:51 +0200 Subject: [PATCH 2/3] feat: require aquila token for definitions --- src/flow_service/mod.rs | 42 +++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/src/flow_service/mod.rs b/src/flow_service/mod.rs index e58916f..ee4a603 100644 --- a/src/flow_service/mod.rs +++ b/src/flow_service/mod.rs @@ -1,5 +1,8 @@ -use crate::{flow_definition::Reader, flow_service::retry::create_channel_with_retry}; -use tonic::transport::Channel; +use crate::{ + flow_definition::Reader, + flow_service::{auth::get_authorization_metadata, retry::create_channel_with_retry}, +}; +use tonic::{Extensions, Request, transport::Channel}; use tucana::{ aquila::{ DataTypeUpdateRequest, FlowTypeUpdateRequest, RuntimeFunctionDefinitionUpdateRequest, @@ -10,6 +13,7 @@ use tucana::{ shared::{DefinitionDataType as DataType, FlowType, RuntimeFunctionDefinition}, }; +pub mod auth; pub mod retry; pub struct FlowUpdateService { @@ -17,13 +21,14 @@ pub struct FlowUpdateService { runtime_definitions: Vec, flow_types: Vec, channel: Channel, + aquila_token: String, } impl FlowUpdateService { /// Create a new FlowUpdateService instance from an Aquila URL and a definition path. /// /// This will read the definition files from the given path and initialize the service with the data types, runtime definitions, and flow types. - pub async fn from_url(aquila_url: String, definition_path: &str) -> Self { + pub async fn from_url(aquila_url: String, definition_path: &str, aquila_token: String) -> Self { let mut data_types = Vec::new(); let mut runtime_definitions = Vec::new(); let mut flow_types = Vec::new(); @@ -51,6 +56,7 @@ impl FlowUpdateService { runtime_definitions, flow_types, channel, + aquila_token, } } @@ -86,9 +92,13 @@ impl FlowUpdateService { log::info!("Updating the current DataTypes!"); let mut client = DataTypeServiceClient::new(self.channel.clone()); - let request = DataTypeUpdateRequest { - data_types: self.data_types.clone(), - }; + let request = Request::from_parts( + get_authorization_metadata(&self.aquila_token), + Extensions::new(), + DataTypeUpdateRequest { + data_types: self.data_types.clone(), + }, + ); match client.update(request).await { Ok(response) => { @@ -111,9 +121,13 @@ impl FlowUpdateService { log::info!("Updating the current RuntimeDefinitions!"); let mut client = RuntimeFunctionDefinitionServiceClient::new(self.channel.clone()); - let request = RuntimeFunctionDefinitionUpdateRequest { - runtime_functions: self.runtime_definitions.clone(), - }; + let request = Request::from_parts( + get_authorization_metadata(&self.aquila_token), + Extensions::new(), + RuntimeFunctionDefinitionUpdateRequest { + runtime_functions: self.runtime_definitions.clone(), + }, + ); match client.update(request).await { Ok(response) => { @@ -136,9 +150,13 @@ impl FlowUpdateService { log::info!("Updating the current FlowTypes!"); let mut client = FlowTypeServiceClient::new(self.channel.clone()); - let request = FlowTypeUpdateRequest { - flow_types: self.flow_types.clone(), - }; + let request = Request::from_parts( + get_authorization_metadata(&self.aquila_token), + Extensions::new(), + FlowTypeUpdateRequest { + flow_types: self.flow_types.clone(), + }, + ); match client.update(request).await { Ok(response) => { From 4c37f65b86bcbdcc875040c2db8ff4932c7cd7fe Mon Sep 17 00:00:00 2001 From: Raphael Date: Sun, 12 Apr 2026 01:26:46 +0200 Subject: [PATCH 3/3] fix: correct import for tests --- src/flow_service/auth.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flow_service/auth.rs b/src/flow_service/auth.rs index cc60dfd..8e11f19 100644 --- a/src/flow_service/auth.rs +++ b/src/flow_service/auth.rs @@ -9,7 +9,7 @@ use tonic::metadata::{MetadataMap, MetadataValue}; /// # Examples /// /// ``` -/// use aquila_grpc::get_authorization_metadata; +/// use code0_flow::flow_service::auth::get_authorization_metadata; /// let token = String::from("token"); /// let metadata = get_authorization_metadata(&token); /// assert!(metadata.get("authorization").is_some());