diff options
| author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-06-12 01:54:21 +0200 |
|---|---|---|
| committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2026-06-12 01:54:21 +0200 |
| commit | bbdf38018b47328b5faa2cef635c37095045be72 (patch) | |
| tree | 8983817d547551ae12508a8ae8731b622d990af4 /crates/turtle/src/command/client/sync.rs | |
| parent | feat(server): Make user stuff stateless (diff) | |
| download | atuin-bbdf38018b47328b5faa2cef635c37095045be72.zip | |
feat(server): Really make users stateless (with tests)
This commit also remove another load of unneeded features.
Diffstat (limited to 'crates/turtle/src/command/client/sync.rs')
| -rw-r--r-- | crates/turtle/src/command/client/sync.rs | 40 |
1 files changed, 25 insertions, 15 deletions
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) |
