Skip to content

Commit cce7934

Browse files
committed
Switch config from TOML to JSON
1 parent 979cf17 commit cce7934

4 files changed

Lines changed: 41 additions & 33 deletions

File tree

crates/devolutions-pedm/Cargo.toml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@ publish = false
1111

1212
[dependencies]
1313
anyhow = "1.0"
14-
axum = { version = "0.8", default-features = false, features = ["http1", "json", "tokio", "query", "tracing", "tower-log", "form", "original-uri", "matched-path"] }
14+
axum = { version = "0.8", default-features = false, features = [
15+
"http1",
16+
"json",
17+
"tokio",
18+
"query",
19+
"tracing",
20+
"tower-log",
21+
"form",
22+
"original-uri",
23+
"matched-path",
24+
] }
1525
base16ct = { version = "0.2", features = ["std", "alloc"] }
1626
base64 = "0.22"
1727
digest = "0.10"
@@ -25,27 +35,32 @@ sha2 = "0.10"
2535
tokio = { version = "1.44", features = ["net", "rt-multi-thread"] }
2636
tower-service = "0.3"
2737
win-api-wrappers = { path = "../win-api-wrappers" }
28-
devolutions-pedm-shared = { path = "../devolutions-pedm-shared", features = ["policy"]}
38+
devolutions-pedm-shared = { path = "../devolutions-pedm-shared", features = [
39+
"policy",
40+
] }
2941
devolutions-gateway-task = { path = "../devolutions-gateway-task" }
3042
devolutions-agent-shared = { path = "../devolutions-agent-shared" }
3143
camino = { version = "1", features = ["serde1"] }
3244
async-trait = "0.1"
3345
tracing = "0.1"
34-
aide = { version = "0.14", features = ["axum", "axum-extra", "axum-json", "axum-tokio"] }
46+
aide = { version = "0.14", features = [
47+
"axum",
48+
"axum-extra",
49+
"axum-json",
50+
"axum-tokio",
51+
] }
3552
tower-http = { version = "0.5", features = ["timeout"] }
3653
parking_lot = "0.12"
3754
cfg-if = "1.0"
3855
uuid = "1"
3956
dunce = "1.0"
4057
tower = "0.5"
4158
futures-util = "0.3"
42-
toml = "0.8"
43-
libsql = { version = "0.9", optional = true, features = [ "core", "stream"] }
59+
libsql = { version = "0.9", optional = true, features = ["core", "stream"] }
4460
tokio-postgres = { version = "0.7", optional = true }
4561
bb8 = { version = "0.9.0", optional = true }
4662
bb8-postgres = { version = "0.9.0", optional = true }
4763

48-
4964
[features]
5065
default = ["libsql"]
5166
libsql = ["dep:libsql"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"db": "libsql",
3+
"libsql": {
4+
"path": "C:/ProgramData/Devolutions/Agent/pedm/pedm.sqlite"
5+
},
6+
"postgres": {
7+
"host": "192.168.0.100",
8+
"dbname": "pedm",
9+
"user": "pedm",
10+
"password": "pedm"
11+
}
12+
}

crates/devolutions-pedm/config.example.toml

Lines changed: 0 additions & 10 deletions
This file was deleted.

crates/devolutions-pedm/src/config.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::data_dir;
99

1010
/// The application config.
1111
#[derive(Serialize, Deserialize)]
12-
#[serde(rename_all = "lowercase")]
1312
pub(crate) struct Config {
1413
/// The selected database backend.
1514
///
@@ -36,14 +35,14 @@ impl Config {
3635
match fs::read_to_string(path) {
3736
Ok(s) => {
3837
info!("Loading config from {path}");
39-
let c: Self = toml::from_str(&s)?;
38+
let c: Self = serde_json::from_str(&s)?;
4039
c.validate()?;
4140
Ok(c)
4241
}
4342
Err(e) if e.kind() == io::ErrorKind::NotFound => {
4443
info!("Config not found at {path}. Initializing default config");
4544
let c = Config::standard();
46-
fs::write(path, toml::to_string(&c)?).map_err(|e| ConfigError::Io(e, path.into()))?;
45+
fs::write(path, serde_json::to_string(&c)?).map_err(|e| ConfigError::Io(e, path.into()))?;
4746
Ok(c)
4847
}
4948
Err(e) => Err(ConfigError::Io(e, path.into())),
@@ -108,17 +107,15 @@ pub(crate) struct PgConfig {
108107
#[derive(Debug)]
109108
pub enum ConfigError {
110109
Io(io::Error, Utf8PathBuf),
111-
TomlDe(toml::de::Error),
112-
TomlSer(toml::ser::Error),
110+
Json(serde_json::Error),
113111
MissingSection(DbBackend),
114112
}
115113

116114
impl error::Error for ConfigError {
117115
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
118116
match self {
119117
Self::Io(e, _) => Some(e),
120-
Self::TomlDe(e) => Some(e),
121-
Self::TomlSer(e) => Some(e),
118+
Self::Json(e) => Some(e),
122119
Self::MissingSection(_) => None,
123120
}
124121
}
@@ -128,20 +125,14 @@ impl fmt::Display for ConfigError {
128125
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
129126
match self {
130127
Self::Io(e, path) => write!(f, "IO error while loading config at {path}: {e}"),
131-
Self::TomlDe(e) => e.fmt(f),
132-
Self::TomlSer(e) => e.fmt(f),
128+
Self::Json(e) => e.fmt(f),
133129
Self::MissingSection(s) => write!(f, "{s} config section is missing"),
134130
}
135131
}
136132
}
137133

138-
impl From<toml::de::Error> for ConfigError {
139-
fn from(e: toml::de::Error) -> Self {
140-
Self::TomlDe(e)
141-
}
142-
}
143-
impl From<toml::ser::Error> for ConfigError {
144-
fn from(e: toml::ser::Error) -> Self {
145-
Self::TomlSer(e)
134+
impl From<serde_json::Error> for ConfigError {
135+
fn from(e: serde_json::Error) -> Self {
136+
Self::Json(e)
146137
}
147138
}

0 commit comments

Comments
 (0)