···14141515#[ntex::main]
1616async fn main() -> std::io::Result<()> {
1717- let _ = config::loadenv();
1717+1818+ match config::loadenv() {
1919+ Ok(_) => (),
2020+ Err(err) => {
2121+ println!("there was a problem reading .env: {err}");
2222+ }
2323+ }
18241925 tracing_subscriber::fmt::fmt()
2626+ // uses RUST_LOG env for filtering log levels and namespaces
2027 .with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
2128 .init();
2229
+13-1
src/proxy.rs
···35353636 if res.status() == 200 {
37373838+ // if route is to list containers we want to return a filtered list
3839 if new_url.path().contains("containers/json") {
39404041 let containers = &res.json::<Vec<ContainerSummary>>().await.unwrap();
41424343+ // filter all containers to only those that have values from CONTAINER_NAMES includes in their names
4244 let filtered_containers = containers.into_iter()
4345 .filter(|&con| docker::is_container_named(con, &container_names.get_ref()))
4446 .collect::<Vec<&ContainerSummary>>();
···4850 Ok(fresp)
4951 } else {
50525353+ // only deal with routes that are for containers like /containers/1234/{some_resource}
5154 match docker::match_container_get(new_url.path()) {
5555+ // the regex pulls the container id from the route with a named capture group, avaiable as m.id
5256 Some (m) => {
5757+ // we keep a stateful hashmap of all requested container ids and their names
5858+ // see AppStateWithContainerMap
5359 let mut cm = data.container_map.lock().unwrap();
6060+6161+ // if the map does not already include the container id-name then we try to get it with our own request to docker api
5462 if !cm.contains_key(&m.id) {
5563 debug!("Requested container Id not in map, trying to inspect: {}", &m.id);
5664 let name_res = docker::get_container_name(&forward_url.to_string(), &m.id).await;
···6674 }
6775 }
68767777+ // then we try to get the name from the stateful hashmap
6978 let name_val = cm.get(&m.id).unwrap();
70797180 match name_val {
7281 Some(n) => {
8282+ // only return if a response if requested container has a name that includes values from CONTAINER_NAMES
7383 if container_names.get_ref().iter().any(|x| n.contains(x)) {
7474- //if n.contains(container_name.get_ref()) { //n.iter().any(|x| x.contains(container_name.get_ref())) {
75848585+ // if the route resource is specifically the Container Inspect API
8686+ // then we may need to scrub Envs if SCRUB_ENVS=true
7687 if m.resource == "json" {
77887889 client_resp.content_type("application/json");
···102113 }
103114 }
104115 }
116116+ // if we don't match container route then proxy response through, unmodified
105117 None => {
106118 let stream = res.into_stream();
107119 Ok(client_resp.streaming(stream))