From 3bf5c2a2f75069cefbd4e1a596df0717d0afc64d Mon Sep 17 00:00:00 2001 From: amigin Date: Thu, 11 Jul 2024 13:13:50 +0300 Subject: [PATCH] Made possible to Populate GoogleAuth Configuration --- Cargo.toml | 6 +++--- src/settings/end_point_settings.rs | 6 ++++-- src/settings/google_auth_settings.rs | 29 +++++++++++++++++++++------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f80b607..ff599c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -my-http-server = { tag = "0.7.0", git = "https://github.com/MyJetTools/my-http-server.git", features = [ +my-http-server = { tag = "0.7.1", git = "https://github.com/MyJetTools/my-http-server.git", features = [ "static-files", "macros", ] } @@ -19,7 +19,7 @@ rust-extensions = { tag = "0.1.4", git = "https://github.com/MyJetTools/rust-ext my-settings-reader = { tag = "0.3.1", git = "https://github.com/MyJetTools/my-settings-reader.git" } -my-logger = { tag = "1.0.3", git = "https://github.com/MyJetTools/my-logger.git" } +my-logger = { tag = "1.1.0", git = "https://github.com/MyJetTools/my-logger.git" } my-ssh = { git = "https://github.com/MyJetTools/my-ssh.git", tag = "0.1.0" } @@ -31,7 +31,7 @@ hyper = { version = "*", features = ["full"] } tokio = { version = "*", features = ["full"] } hyper-util = { version = "*", features = ["tokio", "server", "http1", "http2"] } http-body-util = "*" -tokio-rustls = { version = "0.26.*", features = ["tls12"] } +tokio-rustls = { version = "0.26", features = ["tls12"] } bytes = "*" lazy_static = "*" pem = "*" diff --git a/src/settings/end_point_settings.rs b/src/settings/end_point_settings.rs index d9d3067..381afe2 100644 --- a/src/settings/end_point_settings.rs +++ b/src/settings/end_point_settings.rs @@ -100,6 +100,7 @@ impl EndpointSettings { &self, endpoint_template: Option<&EndpointTemplateSettings>, g_auth_settings: &Option>, + var: VariablesReader, ) -> Result, String> { let mut g_auth_id = self.google_auth.as_ref(); @@ -117,7 +118,7 @@ impl EndpointSettings { if let Some(g_auth_settings) = g_auth_settings { if let Some(result) = g_auth_settings.get(g_auth_id) { - return Ok(Some(result.clone())); + return Ok(Some(result.clone_an_populate(var))); } } @@ -201,7 +202,8 @@ impl EndpointSettings { global_settings: &Option, app: &AppContext, ) -> Result { - let g_auth = self.get_google_auth_settings(endpoint_template_settings, g_auth_settings)?; + let g_auth = + self.get_google_auth_settings(endpoint_template_settings, g_auth_settings, variables)?; match self.endpoint_type.as_str() { HTTP1_ENDPOINT_TYPE => { diff --git a/src/settings/google_auth_settings.rs b/src/settings/google_auth_settings.rs index 50827d9..f9b0165 100644 --- a/src/settings/google_auth_settings.rs +++ b/src/settings/google_auth_settings.rs @@ -1,7 +1,5 @@ +use crate::{types::Email, variables_reader::VariablesReader}; use serde::*; - -use crate::types::Email; - #[derive(Serialize, Deserialize, Debug, Clone)] pub struct GoogleAuthSettings { pub client_id: String, @@ -10,8 +8,25 @@ pub struct GoogleAuthSettings { } impl GoogleAuthSettings { + pub fn clone_an_populate(&self, vars: VariablesReader) -> Self { + let client_id = + crate::populate_variable::populate_variable(self.client_id.trim(), vars).to_string(); + let client_secret = + crate::populate_variable::populate_variable(self.client_secret.trim(), vars) + .to_string(); + + let whitelisted_domains = + crate::populate_variable::populate_variable(self.whitelisted_domains.trim(), vars) + .to_string(); + + Self { + client_id, + client_secret, + whitelisted_domains, + } + } pub fn domain_is_allowed(&self, email: &Email) -> bool { - if self.whitelisted_domains.trim() == "*" { + if self.whitelisted_domains == "*" { return true; } @@ -23,15 +38,15 @@ impl GoogleAuthSettings { let email_domain = email_domain.unwrap(); - let separator = if self.whitelisted_domains.contains(',') { + let separator = if self.whitelisted_domains.as_str().contains(',') { ',' } else { ';' }; - for whitelisted_domain in self.whitelisted_domains.split(separator) { + for whitelisted_domain in self.whitelisted_domains.as_str().split(separator) { if rust_extensions::str_utils::compare_strings_case_insensitive( - whitelisted_domain, + whitelisted_domain.trim(), email_domain, ) { return true;