Skip to content

Commit

Permalink
exclude docker desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacob Halsey committed Jun 7, 2022
1 parent 9831791 commit 9964d22
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wsl2-dns-agent"
version = "0.1.1"
version = "0.2.0"
edition = "2021"
license = "GPL-3.0"
description = "An agent that automatically patches your WSL2 DNS configuration for users of Cisco AnyConnect (or similar VPNs)"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ shutdown = false
[distributions.Ubuntu]
apply_dns = false
```

Note: the default configuration will ignore Docker Desktop, since the changes are unnecessary.
19 changes: 18 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::collections::HashMap;
use std::fs;
use std::path::PathBuf;

const EXCLUDE_BY_DEFAULT: &[&str] = &["docker-desktop", "docker-desktop-data"];

#[derive(Debug, Deserialize, Serialize)]
pub struct Config {
/// Show toast notifications when DNS update is applied
Expand All @@ -13,10 +15,25 @@ pub struct Config {
#[serde(default)]
defaults: DistributionSetting,
/// Per distribution settings
#[serde(default)]
#[serde(default = "default_distributions")]
distributions: HashMap<String, DistributionSetting>,
}

fn default_distributions() -> HashMap<String, DistributionSetting> {
let mut map = HashMap::new();
for d in EXCLUDE_BY_DEFAULT {
map.insert(
d.to_string(),
DistributionSetting {
apply_dns: false,
shutdown: false,
patch_wsl_conf: false,
},
);
}
map
}

#[derive(Debug, Deserialize, Serialize)]
pub struct DistributionSetting {
/// Whether to update the wsl.conf and resolv.conf files for this distribution
Expand Down
2 changes: 2 additions & 0 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ fn update_dns(config: &Config) -> Result<(), Error> {
if let Err(e) = update_distribution(&d, dist_config, &resolv) {
log::error!("Failed to update DNS for {}, due to: {}", d.name, e);
}
} else {
log::info!("Ignoring: {}", d.name);
}
}
Ok(())
Expand Down

0 comments on commit 9964d22

Please sign in to comment.