Skip to content

Commit

Permalink
feat: Try to adopt basic_auth data when available
Browse files Browse the repository at this point in the history
  • Loading branch information
stmh committed Dec 13, 2024
1 parent a658ff5 commit 8aff443
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/apps/app_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ pub struct ContainerState {
pub port: Option<u32>,
pub started_at: Option<chrono::DateTime<chrono::Local>>,
pub used_registry: Option<String>,
pub basic_auth: Option<(String, String)>,
}

impl Default for ContainerState {
Expand All @@ -299,6 +300,7 @@ impl Default for ContainerState {
port: None,
started_at: None,
used_registry: None,
basic_auth: None,
}
}
}
Expand Down Expand Up @@ -468,6 +470,7 @@ impl AppData {
..AppSettings::default()
};

let mut basic_auth = None;
// Iterate over services and add them to the new settings
for service in &self.services {
if !service.domains.is_empty() {
Expand All @@ -477,8 +480,13 @@ impl AppData {
domains: service.domains.clone(),
});
}
if service.basic_auth.is_some() {
basic_auth = service.basic_auth.clone();
}
}

new_settings.basic_auth = basic_auth;

let app_data = AppData {
settings: Some(new_settings),
..self.clone()
Expand Down
8 changes: 8 additions & 0 deletions src/docker/find_apps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ async fn get_running_services(
port: None,
started_at: None,
used_registry: None,
basic_auth: None,
}
}
})
Expand Down Expand Up @@ -285,6 +286,13 @@ async fn inspect_docker_container(
port: loadbalancer_info.port,
started_at: Some(local_date),
used_registry,
basic_auth: match (
loadbalancer_info.basic_auth_user,
loadbalancer_info.basic_auth_pass,
) {
(Some(user), Some(pass)) => Some((user, pass)),
_ => None,
},
};

Ok(container_state)
Expand Down
12 changes: 6 additions & 6 deletions src/docker/loadbalancer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub struct LoadBalancerInfo {
pub domains: Vec<String>,
pub port: Option<u32>,
pub tls_enabled: bool,
pub http_auth_user: Option<String>,
pub http_auth_pass: Option<String>,
pub basic_auth_user: Option<String>,
pub basic_auth_pass: Option<String>,
}

impl Default for LoadBalancerInfo {
Expand All @@ -23,8 +23,8 @@ impl Default for LoadBalancerInfo {
domains: vec![],
port: Some(80),
tls_enabled: false,
http_auth_user: None,
http_auth_pass: None,
basic_auth_user: None,
basic_auth_pass: None,
}
}
}
Expand Down Expand Up @@ -93,10 +93,10 @@ impl LoadBalancerImpl for HaproxyLoadBalancer {
}
}
"HTTTP_AUTH_USER" => {
result.http_auth_user = Some(value.to_string());
result.basic_auth_user = Some(value.to_string());
}
"HTTP_AUTH_PASS" => {
result.http_auth_pass = Some(value.to_string());
result.basic_auth_pass = Some(value.to_string());
}
_ => {}
}
Expand Down

0 comments on commit 8aff443

Please sign in to comment.