Skip to content

Commit

Permalink
Made possible to Populate GoogleAuth Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
amigin committed Jul 11, 2024
1 parent 01eb5da commit 3bf5c2a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
] }
Expand All @@ -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" }

Expand All @@ -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 = "*"
Expand Down
6 changes: 4 additions & 2 deletions src/settings/end_point_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl EndpointSettings {
&self,
endpoint_template: Option<&EndpointTemplateSettings>,
g_auth_settings: &Option<HashMap<String, GoogleAuthSettings>>,
var: VariablesReader,
) -> Result<Option<GoogleAuthSettings>, String> {
let mut g_auth_id = self.google_auth.as_ref();

Expand All @@ -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)));
}
}

Expand Down Expand Up @@ -201,7 +202,8 @@ impl EndpointSettings {
global_settings: &Option<GlobalSettings>,
app: &AppContext,
) -> Result<EndpointType, String> {
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 => {
Expand Down
29 changes: 22 additions & 7 deletions src/settings/google_auth_settings.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down

0 comments on commit 3bf5c2a

Please sign in to comment.