Restructure account commands to account subcommand (#984)
* Stop running triggers on history delete * Move to account management dir * Alter trigger function to only run for inserts * wip * Add atuin account subcommands, and re-org delete * Clarify docs * Delete silly dupe migration * Um where did this come from * Oops, insert only plz
This commit is contained in:
parent
7d5a82df14
commit
ca263834e9
11 changed files with 91 additions and 13 deletions
|
@ -219,7 +219,7 @@ impl<'a> Client<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete(&self) -> Result<()> {
|
pub async fn delete(&self) -> Result<()> {
|
||||||
let url = format!("{}/register", self.sync_addr);
|
let url = format!("{}/account", self.sync_addr);
|
||||||
let url = Url::parse(url.as_str())?;
|
let url = Url::parse(url.as_str())?;
|
||||||
|
|
||||||
let resp = self.client.delete(url).send().await?;
|
let resp = self.client.delete(url).send().await?;
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
-- We do not need to run the trigger on deletes, as the only time we are deleting history is when the user
|
||||||
|
-- has already been deleted
|
||||||
|
-- This actually slows down deleting all the history a good bit!
|
||||||
|
|
||||||
|
create or replace function user_history_count()
|
||||||
|
returns trigger as
|
||||||
|
$func$
|
||||||
|
begin
|
||||||
|
if (TG_OP='INSERT') then
|
||||||
|
update total_history_count_user set total = total + 1 where user_id = new.user_id;
|
||||||
|
|
||||||
|
if not found then
|
||||||
|
insert into total_history_count_user(user_id, total)
|
||||||
|
values (
|
||||||
|
new.user_id,
|
||||||
|
(select count(1) from history where user_id = new.user_id)
|
||||||
|
);
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
return NEW; -- this is actually ignored for an after trigger, but oh well
|
||||||
|
end;
|
||||||
|
$func$
|
||||||
|
language plpgsql volatile -- pldfplplpflh
|
||||||
|
cost 100; -- default value
|
||||||
|
|
||||||
|
create or replace trigger tg_user_history_count
|
||||||
|
after insert on history
|
||||||
|
for each row
|
||||||
|
execute procedure user_history_count();
|
|
@ -9,6 +9,9 @@ use env_logger::Builder;
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
mod sync;
|
mod sync;
|
||||||
|
|
||||||
|
#[cfg(feature = "sync")]
|
||||||
|
mod account;
|
||||||
|
|
||||||
mod history;
|
mod history;
|
||||||
mod import;
|
mod import;
|
||||||
mod search;
|
mod search;
|
||||||
|
@ -34,6 +37,9 @@ pub enum Cmd {
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
#[command(flatten)]
|
#[command(flatten)]
|
||||||
Sync(sync::Cmd),
|
Sync(sync::Cmd),
|
||||||
|
|
||||||
|
#[cfg(feature = "sync")]
|
||||||
|
Account(account::Cmd),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Cmd {
|
impl Cmd {
|
||||||
|
@ -54,8 +60,12 @@ impl Cmd {
|
||||||
Self::Import(import) => import.run(&mut db).await,
|
Self::Import(import) => import.run(&mut db).await,
|
||||||
Self::Stats(stats) => stats.run(&mut db, &settings).await,
|
Self::Stats(stats) => stats.run(&mut db, &settings).await,
|
||||||
Self::Search(search) => search.run(db, &mut settings).await,
|
Self::Search(search) => search.run(db, &mut settings).await,
|
||||||
|
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
Self::Sync(sync) => sync.run(settings, &mut db).await,
|
Self::Sync(sync) => sync.run(settings, &mut db).await,
|
||||||
|
|
||||||
|
#[cfg(feature = "sync")]
|
||||||
|
Self::Account(account) => account.run(settings).await,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
41
atuin/src/command/client/account.rs
Normal file
41
atuin/src/command/client/account.rs
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
use clap::{Args, Subcommand};
|
||||||
|
use eyre::Result;
|
||||||
|
|
||||||
|
use atuin_client::settings::Settings;
|
||||||
|
|
||||||
|
pub mod delete;
|
||||||
|
pub mod login;
|
||||||
|
pub mod logout;
|
||||||
|
pub mod register;
|
||||||
|
|
||||||
|
#[derive(Args)]
|
||||||
|
pub struct Cmd {
|
||||||
|
#[command(subcommand)]
|
||||||
|
command: Commands,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand)]
|
||||||
|
pub enum Commands {
|
||||||
|
/// Login to the configured server
|
||||||
|
Login(login::Cmd),
|
||||||
|
|
||||||
|
// Register a new account
|
||||||
|
Register(register::Cmd),
|
||||||
|
|
||||||
|
/// Log out
|
||||||
|
Logout,
|
||||||
|
|
||||||
|
// Delete your account, and all synced data
|
||||||
|
Delete,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Cmd {
|
||||||
|
pub async fn run(self, settings: Settings) -> Result<()> {
|
||||||
|
match self.command {
|
||||||
|
Commands::Login(l) => l.run(&settings).await,
|
||||||
|
Commands::Register(r) => r.run(&settings).await,
|
||||||
|
Commands::Logout => logout::run(&settings),
|
||||||
|
Commands::Delete => delete::run(&settings).await,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,12 +3,10 @@ use eyre::{Result, WrapErr};
|
||||||
|
|
||||||
use atuin_client::{database::Database, settings::Settings};
|
use atuin_client::{database::Database, settings::Settings};
|
||||||
|
|
||||||
mod delete;
|
|
||||||
mod login;
|
|
||||||
mod logout;
|
|
||||||
mod register;
|
|
||||||
mod status;
|
mod status;
|
||||||
|
|
||||||
|
use crate::command::client::account;
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
#[command(infer_subcommands = true)]
|
#[command(infer_subcommands = true)]
|
||||||
pub enum Cmd {
|
pub enum Cmd {
|
||||||
|
@ -20,16 +18,13 @@ pub enum Cmd {
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Login to the configured server
|
/// Login to the configured server
|
||||||
Login(login::Cmd),
|
Login(account::login::Cmd),
|
||||||
|
|
||||||
/// Log out
|
/// Log out
|
||||||
Logout,
|
Logout,
|
||||||
|
|
||||||
/// Register with the configured server
|
/// Register with the configured server
|
||||||
Register(register::Cmd),
|
Register(account::register::Cmd),
|
||||||
|
|
||||||
/// Unregister with the configured server
|
|
||||||
Unregister,
|
|
||||||
|
|
||||||
/// Print the encryption key for transfer to another machine
|
/// Print the encryption key for transfer to another machine
|
||||||
Key {
|
Key {
|
||||||
|
@ -46,9 +41,8 @@ impl Cmd {
|
||||||
match self {
|
match self {
|
||||||
Self::Sync { force } => run(&settings, force, db).await,
|
Self::Sync { force } => run(&settings, force, db).await,
|
||||||
Self::Login(l) => l.run(&settings).await,
|
Self::Login(l) => l.run(&settings).await,
|
||||||
Self::Logout => logout::run(&settings),
|
Self::Logout => account::logout::run(&settings),
|
||||||
Self::Register(r) => r.run(&settings).await,
|
Self::Register(r) => r.run(&settings).await,
|
||||||
Self::Unregister => delete::run(&settings).await,
|
|
||||||
Self::Status => status::run(&settings, db).await,
|
Self::Status => status::run(&settings, db).await,
|
||||||
Self::Key { base64 } => {
|
Self::Key { base64 } => {
|
||||||
use atuin_client::encryption::{encode_key, load_key};
|
use atuin_client::encryption::{encode_key, load_key};
|
||||||
|
|
|
@ -49,6 +49,7 @@ impl AtuinCmd {
|
||||||
match self {
|
match self {
|
||||||
#[cfg(feature = "client")]
|
#[cfg(feature = "client")]
|
||||||
Self::Client(client) => client.run(),
|
Self::Client(client) => client.run(),
|
||||||
|
|
||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
Self::Server(server) => server.run(),
|
Self::Server(server) => server.run(),
|
||||||
Self::Contributors => {
|
Self::Contributors => {
|
||||||
|
|
|
@ -40,9 +40,11 @@ here!
|
||||||
You can delete your sync account with
|
You can delete your sync account with
|
||||||
|
|
||||||
```
|
```
|
||||||
atuin unregister
|
atuin account delete
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This will remove your account and all synchronized history from the server. Local data will not be touched!
|
||||||
|
|
||||||
## Key
|
## Key
|
||||||
|
|
||||||
As all your data is encrypted, Atuin generates a key for you. It's stored in the
|
As all your data is encrypted, Atuin generates a key for you. It's stored in the
|
||||||
|
|
Loading…
Reference in a new issue