From a6fd0f1dd7e34575e17dbc665f09a2aa1d497256 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Mon, 24 Mar 2025 21:57:05 +0000 Subject: [PATCH 1/5] Add clap --- backend/Cargo.lock | 109 +++++++++++++++++++++++++++++++++ backend/sync_server/Cargo.toml | 1 + 2 files changed, 110 insertions(+) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 6292ef06..4ea73d94 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -96,6 +96,56 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" +dependencies = [ + "anstyle", + "once_cell", + "windows-sys 0.59.0", +] + [[package]] name = "anyhow" version = "1.0.94" @@ -399,6 +449,52 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "clap" +version = "4.5.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6088f3ae8c3608d19260cd7445411865a485688711b78b5be70d78cd96136f83" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22a7ef7f676155edfb82daa97f99441f3ebf4a58d5e32f295a56259f1b6facc8" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09176aae279615badda0765c0c0b3f6ed53f4709118af73cf4655d85d1530cd7" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.90", +] + +[[package]] +name = "clap_lex" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" + +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -1196,6 +1292,12 @@ dependencies = [ "similar", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "iso8601" version = "0.6.1" @@ -2403,6 +2505,7 @@ dependencies = [ "axum-jsonschema", "axum_typed_multipart", "chrono", + "clap", "log", "rand", "reconcile", @@ -2826,6 +2929,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "uuid" version = "1.11.0" diff --git a/backend/sync_server/Cargo.toml b/backend/sync_server/Cargo.toml index 8b14c450..4b31cc1c 100644 --- a/backend/sync_server/Cargo.toml +++ b/backend/sync_server/Cargo.toml @@ -33,6 +33,7 @@ rand = "0.8.5" sanitize-filename = "0.6.0" axum-jsonschema = { version = "0.8.0", features = ["aide"] } regex = "1.11.1" +clap = { version = "4.5.32", features = ["derive"] } [lints] workspace = true -- 2.47.2 From 958af89116e617e8f7d31a4e360ee1b397ab49fc Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Mon, 24 Mar 2025 21:57:26 +0000 Subject: [PATCH 2/5] Rename config.yml --- .github/workflows/e2e.yml | 2 +- backend/.dockerignore | 2 +- backend/{config.yml => config-e2e.yml} | 6 ++++++ frontend/test-client/src/cli.ts | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) rename backend/{config.yml => config-e2e.yml} (76%) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 2352e5b2..1481234d 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -38,7 +38,7 @@ jobs: - name: E2E tests run: | cd backend - RUST_BACKTRACE=1 cargo run -p sync_server & + RUST_BACKTRACE=1 cargo run -p sync_server config-e2e.yml & cd .. scripts/update-api-types.sh diff --git a/backend/.dockerignore b/backend/.dockerignore index dd62faf4..985e2cd4 100644 --- a/backend/.dockerignore +++ b/backend/.dockerignore @@ -3,4 +3,4 @@ Dockerfile .dockerignore databases sync_lib/pkg -config.yml +*.yml diff --git a/backend/config.yml b/backend/config-e2e.yml similarity index 76% rename from backend/config.yml rename to backend/config-e2e.yml index d8ccf20d..2345c8b3 100644 --- a/backend/config.yml +++ b/backend/config-e2e.yml @@ -9,5 +9,11 @@ users: user_tokens: - name: admin token: test-token-change-me + vaults: + all: true + - name: test token: other-test-token + vaults: + allowed: + - default diff --git a/frontend/test-client/src/cli.ts b/frontend/test-client/src/cli.ts index 4747f2af..799ee790 100644 --- a/frontend/test-client/src/cli.ts +++ b/frontend/test-client/src/cli.ts @@ -27,7 +27,7 @@ async function runTest({ const initialSettings: Partial = { isSyncEnabled: true, - token: "test-token-change-me", // same as in backend/config.yml + token: "test-token-change-me", // same as in backend/config-e2e.yml vaultName: uuidv4(), syncConcurrency: concurrency, remoteUri: "http://localhost:3000" -- 2.47.2 From baba8f82bfab079a1e8f1e36322cecbbb35e78c9 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Mon, 24 Mar 2025 21:57:56 +0000 Subject: [PATCH 3/5] Take config path as input --- backend/sync_server/src/cli.rs | 1 + backend/sync_server/src/cli/args.rs | 38 +++++++++++++++++++++ backend/sync_server/src/consts.rs | 2 +- backend/sync_server/src/main.rs | 7 +++- backend/sync_server/src/server.rs | 6 ++-- backend/sync_server/src/server/app_state.rs | 11 +++--- 6 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 backend/sync_server/src/cli.rs create mode 100644 backend/sync_server/src/cli/args.rs diff --git a/backend/sync_server/src/cli.rs b/backend/sync_server/src/cli.rs new file mode 100644 index 00000000..6e10f4ad --- /dev/null +++ b/backend/sync_server/src/cli.rs @@ -0,0 +1 @@ +pub mod args; diff --git a/backend/sync_server/src/cli/args.rs b/backend/sync_server/src/cli/args.rs new file mode 100644 index 00000000..ec5739f9 --- /dev/null +++ b/backend/sync_server/src/cli/args.rs @@ -0,0 +1,38 @@ +use std::ffi::OsString; + +use clap::{Parser, ValueEnum}; + +/// Simple program to greet a person +#[derive(Parser, Debug)] +#[command(version, about, long_about = None)] +pub struct Args { + #[arg( + long, + require_equals = true, + value_name = "WHEN", + num_args = 0..=1, + default_value_t = ColorWhen::Auto, + default_missing_value = "always", + value_enum + )] + pub color: ColorWhen, + + #[arg(last = true)] + pub config_path: Option, +} + +#[derive(ValueEnum, Copy, Clone, Debug, PartialEq, Eq)] +pub enum ColorWhen { + Always, + Auto, + Never, +} + +impl std::fmt::Display for ColorWhen { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.to_possible_value() + .expect("no values are skipped") + .get_name() + .fmt(f) + } +} diff --git a/backend/sync_server/src/consts.rs b/backend/sync_server/src/consts.rs index f38012de..bec936b4 100644 --- a/backend/sync_server/src/consts.rs +++ b/backend/sync_server/src/consts.rs @@ -1,4 +1,4 @@ -pub const CONFIG_PATH: &str = "config.yml"; +pub const DEFAULT_CONFIG_PATH: &str = "config.yml"; pub const DEFAULT_DATABASES_DIRECTORY_PATH: &str = "databases"; pub const DEFAULT_HOST: &str = "127.0.0.1"; pub const DEFAULT_PORT: u16 = 3000; diff --git a/backend/sync_server/src/main.rs b/backend/sync_server/src/main.rs index 61f6f2af..2b8abccd 100644 --- a/backend/sync_server/src/main.rs +++ b/backend/sync_server/src/main.rs @@ -1,3 +1,4 @@ +mod cli; mod config; mod consts; mod database; @@ -6,6 +7,8 @@ mod server; mod utils; use anyhow::{Context as _, Result}; +use clap::Parser; +use cli::args::Args; use errors::{SyncServerError, init_error}; use log::info; use server::create_server; @@ -13,6 +16,8 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; #[tokio::main] async fn main() -> Result<(), SyncServerError> { + let args = Args::parse(); + tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { @@ -33,7 +38,7 @@ async fn main() -> Result<(), SyncServerError> { env!("CARGO_PKG_VERSION") ); - create_server() + create_server(args.config_path) .await .context("Failed to start server") .map_err(init_error) diff --git a/backend/sync_server/src/server.rs b/backend/sync_server/src/server.rs index 511187e0..083be5ba 100644 --- a/backend/sync_server/src/server.rs +++ b/backend/sync_server/src/server.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{ffi::OsString, sync::Arc}; use aide::{ axum::{ @@ -48,11 +48,11 @@ mod requests; mod responses; mod update_document; -pub async fn create_server() -> Result<()> { +pub async fn create_server(config_path: Option) -> Result<()> { aide::r#gen::on_error(|err| error!("{err}")); aide::r#gen::extract_schemas(true); - let app_state = AppState::try_new() + let app_state = AppState::try_new(config_path) .await .context("Failed to initialise app state")?; diff --git a/backend/sync_server/src/server/app_state.rs b/backend/sync_server/src/server/app_state.rs index 0b02abcb..2a8a96eb 100644 --- a/backend/sync_server/src/server/app_state.rs +++ b/backend/sync_server/src/server/app_state.rs @@ -1,6 +1,8 @@ +use std::ffi::OsString; + use anyhow::Result; -use crate::{config::Config, consts::CONFIG_PATH, database::Database}; +use crate::{config::Config, consts::DEFAULT_CONFIG_PATH, database::Database}; #[derive(Clone, Debug)] pub struct AppState { @@ -9,10 +11,11 @@ pub struct AppState { } impl AppState { - pub async fn try_new() -> Result { - let path = std::path::Path::new(CONFIG_PATH); + pub async fn try_new(config_path: Option) -> Result { + let config_path = config_path.unwrap_or_else(|| OsString::from(DEFAULT_CONFIG_PATH)); + let path = std::path::PathBuf::from(config_path); - let config = Config::read_or_create(path).await?; + let config = Config::read_or_create(&path).await?; let database = Database::try_new(&config.database).await?; Ok(Self { config, database }) -- 2.47.2 From ccff1cfc7a1b7edb65c4c4b351c5fe7685729017 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Mon, 24 Mar 2025 22:03:43 +0000 Subject: [PATCH 4/5] Fix parsing --- backend/sync_server/src/cli/args.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/sync_server/src/cli/args.rs b/backend/sync_server/src/cli/args.rs index ec5739f9..88ff1718 100644 --- a/backend/sync_server/src/cli/args.rs +++ b/backend/sync_server/src/cli/args.rs @@ -2,10 +2,13 @@ use std::ffi::OsString; use clap::{Parser, ValueEnum}; -/// Simple program to greet a person +/// Server for backing the VaultLink plugin #[derive(Parser, Debug)] #[command(version, about, long_about = None)] pub struct Args { + #[arg(index = 1)] + pub config_path: Option, + #[arg( long, require_equals = true, @@ -16,9 +19,6 @@ pub struct Args { value_enum )] pub color: ColorWhen, - - #[arg(last = true)] - pub config_path: Option, } #[derive(ValueEnum, Copy, Clone, Debug, PartialEq, Eq)] -- 2.47.2 From 025288ceb07a22435aaf7301b09a111a133b3ece Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Mar 2025 22:54:42 +0000 Subject: [PATCH 5/5] Bump uuid from 1.11.0 to 1.16.0 in /backend Bumps [uuid](https://github.com/uuid-rs/uuid) from 1.11.0 to 1.16.0. - [Release notes](https://github.com/uuid-rs/uuid/releases) - [Commits](https://github.com/uuid-rs/uuid/compare/1.11.0...v1.16.0) --- updated-dependencies: - dependency-name: uuid dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- backend/Cargo.lock | 52 ++++++++++++++++++++++++++++------ backend/sync_server/Cargo.toml | 2 +- 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 6292ef06..0bb43c37 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -24,7 +24,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", - "getrandom", + "getrandom 0.2.15", "once_cell", "serde", "version_check", @@ -826,10 +826,22 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "wasm-bindgen", ] +[[package]] +name = "getrandom" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasi 0.14.2+wasi-0.2.4", +] + [[package]] name = "gimli" version = "0.31.1" @@ -1242,7 +1254,7 @@ dependencies = [ "bytecount", "fancy-regex", "fraction", - "getrandom", + "getrandom 0.2.15", "iso8601", "itoa", "memchr", @@ -1393,7 +1405,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" dependencies = [ "libc", - "wasi", + "wasi 0.11.0+wasi-snapshot-preview1", "windows-sys 0.52.0", ] @@ -1714,6 +1726,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5" + [[package]] name = "rand" version = "0.8.5" @@ -1741,7 +1759,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.15", ] [[package]] @@ -2828,11 +2846,11 @@ checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] name = "uuid" -version = "1.11.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" +checksum = "458f7a779bf54acc9f347480ac654f68407d3aab21269a6e3c9f922acd9e2da9" dependencies = [ - "getrandom", + "getrandom 0.3.2", "serde", ] @@ -2870,6 +2888,15 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasi" +version = "0.14.2+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +dependencies = [ + "wit-bindgen-rt", +] + [[package]] name = "wasite" version = "0.1.0" @@ -3176,6 +3203,15 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "wit-bindgen-rt" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" +dependencies = [ + "bitflags", +] + [[package]] name = "write16" version = "1.0.0" diff --git a/backend/sync_server/Cargo.toml b/backend/sync_server/Cargo.toml index 8b14c450..0b741037 100644 --- a/backend/sync_server/Cargo.toml +++ b/backend/sync_server/Cargo.toml @@ -14,7 +14,7 @@ serde = { workspace = true } thiserror = { workspace = true } tokio = { version = "1.42.0", features = ["full"]} -uuid = { version = "1.11.0", features = ["v4", "serde"] } +uuid = { version = "1.16.0", features = ["v4", "serde"] } log = { version = "0.4.22" } anyhow = { version = "1.0.94", features = ["backtrace"] } axum = { version = "0.7.4", features = ["ws", "macros", "tracing", "multipart"]} -- 2.47.2