From bbdf38018b47328b5faa2cef635c37095045be72 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Fri, 12 Jun 2026 01:54:21 +0200 Subject: feat(server): Really make users stateless (with tests) This commit also remove another load of unneeded features. --- crates/turtle/src/command/client/sync.rs | 40 ++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'crates/turtle/src/command/client/sync.rs') diff --git a/crates/turtle/src/command/client/sync.rs b/crates/turtle/src/command/client/sync.rs index 7adf90ed..84b74cc1 100644 --- a/crates/turtle/src/command/client/sync.rs +++ b/crates/turtle/src/command/client/sync.rs @@ -1,12 +1,12 @@ use clap::Subcommand; use eyre::{Result, WrapErr}; +use serde_json::json; -use crate::atuin_client::{ - database::Database, - encryption, - history::store::HistoryStore, - record::{sqlite_store::SqliteStore, store::Store, sync}, - settings::Settings, +use crate::{ + atuin_client::{ + database::ClientSqlite, encryption, history::store::HistoryStore, record::{sqlite_store::SqliteStore, store::Store, sync}, settings::Settings + }, + atuin_common::utils, }; mod status; @@ -15,14 +15,14 @@ mod status; #[command(infer_subcommands = true)] pub(crate) enum Cmd { /// Sync with the configured server - Sync { + Perform { /// Force re-download everything #[arg(long, short)] force: bool, }, - /// Print the encryption key for transfer to another machine - Key {}, + /// Print (or generate) the encryption key and user id for transfer to another machine + KeyAndId {}, /// Display the sync status Status, @@ -32,18 +32,28 @@ impl Cmd { pub(crate) async fn run( self, settings: Settings, - db: &impl Database, + db: &ClientSqlite, store: SqliteStore, ) -> Result<()> { match self { - Self::Sync { force } => run(&settings, force, db, store).await, + Self::Perform { force } => run(&settings, force, db, store).await, Self::Status => status::run(&settings).await, - Self::Key {} => { + Self::KeyAndId {} => { use crate::atuin_client::encryption::{encode_key, load_key}; + let key = load_key(&settings).wrap_err("could not load encryption key")?; + let user_id = settings + .sync + .user_id() + .wrap_err("Failed to load user-id")? + .unwrap_or_else(utils::uuid_v7); + + let key = encode_key(&key).wrap_err("could not encode encryption key")?; + + let json = serde_json::to_string_pretty(&json!({ "key": key, "user_id": user_id })) + .expect("Will always be formattable"); - let encode = encode_key(&key).wrap_err("could not encode encryption key")?; - println!("{encode}"); + println!("{json}"); Ok(()) } @@ -54,7 +64,7 @@ impl Cmd { async fn run( settings: &Settings, force: bool, - db: &impl Database, + db: &ClientSqlite, store: SqliteStore, ) -> Result<()> { let encryption_key: [u8; 32] = encryption::load_key(settings) -- cgit v1.3.1