diff options
| author | David Lönnhager <david.l@mullvad.net> | 2025-02-25 14:38:26 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2025-03-06 00:09:15 +0100 |
| commit | 541079d02c4b3d09cb2f89831ec20a3aa6761e19 (patch) | |
| tree | ce5151bd5756cf4860b8aa3de72916f8cb909eb4 | |
| parent | 7f6d6c9df3676829d8d45e78df557934de537b3b (diff) | |
| download | mullvadvpn-541079d02c4b3d09cb2f89831ec20a3aa6761e19.tar.xz mullvadvpn-541079d02c4b3d09cb2f89831ec20a3aa6761e19.zip | |
Add config.toml for meta tool
| -rw-r--r-- | Cargo.lock | 2 | ||||
| -rw-r--r-- | mullvad-update/meta/Cargo.toml | 2 | ||||
| -rw-r--r-- | mullvad-update/meta/src/config.rs | 30 | ||||
| -rw-r--r-- | mullvad-update/meta/src/main.rs | 3 |
4 files changed, 37 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock index 7bb0305295..4058c2c7fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2461,9 +2461,11 @@ dependencies = [ "mullvad-version", "rand 0.8.5", "reqwest", + "serde", "serde_json", "sha2", "tokio", + "toml 0.8.19", ] [[package]] diff --git a/mullvad-update/meta/Cargo.toml b/mullvad-update/meta/Cargo.toml index 37dd6beb24..18dfd2bdd0 100644 --- a/mullvad-update/meta/Cargo.toml +++ b/mullvad-update/meta/Cargo.toml @@ -18,8 +18,10 @@ hex = { version = "0.4" } rand = { version = "0.8.5" } reqwest = { version = "0.12.9", features = ["rustls-tls"] } serde_json = { workspace = true } +serde = { workspace = true } sha2 = "0.10" tokio = { version = "1", features = ["full"] } +toml = "0.8" mullvad-version = { path = "../../mullvad-version", features = ["serde"] } mullvad-update = { path = "../", features = ["client", "sign"] } diff --git a/mullvad-update/meta/src/config.rs b/mullvad-update/meta/src/config.rs new file mode 100644 index 0000000000..bbfa923cc6 --- /dev/null +++ b/mullvad-update/meta/src/config.rs @@ -0,0 +1,30 @@ +//! TOML configuration file + +use anyhow::Context; +use serde::{Deserialize, Serialize}; +use tokio::{fs, io}; + +/// Path to the configuration file. Currently a file in the working directory. +const CONFIG_FILENAME: &str = "config.toml"; + +#[derive(Default, Deserialize, Serialize)] +pub struct Config { + /// URLs to use as bases for installers. + /// Files are expected at (example): `<base>/MullvadVPN-2025.1.exe`. + pub base_urls: Vec<String>, +} + +impl Config { + pub async fn load_or_create() -> anyhow::Result<Self> { + println!("Reading {CONFIG_FILENAME}"); + + match fs::read_to_string(CONFIG_FILENAME).await { + Ok(toml_str) => toml::from_str(&toml_str).context("Failed to parse TOML file"), + Err(err) if err.kind() == io::ErrorKind::NotFound => { + println!("Creating default {CONFIG_FILENAME}"); + Ok(Self::default()) + } + Err(err) => Err(err).context(format!("Failed to read {CONFIG_FILENAME}")), + } + } +} diff --git a/mullvad-update/meta/src/main.rs b/mullvad-update/meta/src/main.rs index f0f600db53..8c3cd478a9 100644 --- a/mullvad-update/meta/src/main.rs +++ b/mullvad-update/meta/src/main.rs @@ -2,6 +2,7 @@ use anyhow::{bail, Context}; use clap::Parser; +use config::Config; use io_util::create_dir_and_write; use mullvad_update::format::{self, key, SignedResponse}; @@ -9,6 +10,7 @@ use mullvad_update::format::{self, key, SignedResponse}; use platform::Platform; mod artifacts; +mod config; mod github; mod io_util; mod platform; @@ -110,6 +112,7 @@ pub enum Opt { #[tokio::main] async fn main() -> anyhow::Result<()> { let opt = Opt::parse(); + let config = Config::load_or_create().await?; match opt { Opt::GenerateKey => { |
