diff options
author | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-02-02 15:05:07 +0000 |
---|---|---|
committer | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-02-02 18:01:09 +0000 |
commit | c9a453289e2fea97b5ac17e265f99332edcdcd4c (patch) | |
tree | e51eb1f7d2fd3b44fabf2c1260802232fa0367b2 /atuin-server | |
parent | 3c420f85f69771db269c015ead8e1678a4ad6899 (diff) |
feat: add `store push --force`
This will
1. Wipe the remote store
2. Upload all of the local store to remote
Imagine the scenario where you end up with some mixed keys locally :(
You confirm this with
```
atuin store verify
```
You then fix it locally with
```
atuin store purge
```
Ensure that your local changes are reflected remotely with
```
atuin store push --force
```
and then (another PR, coming soon), update all other hosts with
```
atuin store pull --force
```
Diffstat (limited to 'atuin-server')
-rw-r--r-- | atuin-server/src/handlers/v0/mod.rs | 1 | ||||
-rw-r--r-- | atuin-server/src/handlers/v0/store.rs | 37 | ||||
-rw-r--r-- | atuin-server/src/router.rs | 3 |
3 files changed, 40 insertions, 1 deletions
diff --git a/atuin-server/src/handlers/v0/mod.rs b/atuin-server/src/handlers/v0/mod.rs index 78fb47b8a..2d6745cff 100644 --- a/atuin-server/src/handlers/v0/mod.rs +++ b/atuin-server/src/handlers/v0/mod.rs @@ -1 +1,2 @@ pub(crate) mod record; +pub(crate) mod store; diff --git a/atuin-server/src/handlers/v0/store.rs b/atuin-server/src/handlers/v0/store.rs new file mode 100644 index 000000000..941f24872 --- /dev/null +++ b/atuin-server/src/handlers/v0/store.rs @@ -0,0 +1,37 @@ +use axum::{extract::Query, extract::State, http::StatusCode}; +use metrics::counter; +use serde::Deserialize; +use tracing::{error, instrument}; + +use crate::{ + handlers::{ErrorResponse, ErrorResponseStatus, RespExt}, + router::{AppState, UserAuth}, +}; +use atuin_server_database::Database; + +#[derive(Deserialize)] +pub struct DeleteParams {} + +#[instrument(skip_all, fields(user.id = user.id))] +pub async fn delete<DB: Database>( + _params: Query<DeleteParams>, + UserAuth(user): UserAuth, + state: State<AppState<DB>>, +) -> Result<(), ErrorResponseStatus<'static>> { + let State(AppState { + database, + settings: _, + }) = state; + + if let Err(e) = database.delete_store(&user).await { + counter!("atuin_store_delete_failed", 1); + error!("failed to delete store {e:?}"); + + return Err(ErrorResponse::reply("failed to delete store") + .with_status(StatusCode::INTERNAL_SERVER_ERROR)); + } + + counter!("atuin_store_deleted", 1); + + Ok(()) +} diff --git a/atuin-server/src/router.rs b/atuin-server/src/router.rs index 74df229a7..52fc14842 100644 --- a/atuin-server/src/router.rs +++ b/atuin-server/src/router.rs @@ -127,7 +127,8 @@ pub fn router<DB: Database>(database: DB, settings: Settings<DB::Settings>) -> R .route("/record/next", get(handlers::record::next)) .route("/api/v0/record", post(handlers::v0::record::post)) .route("/api/v0/record", get(handlers::v0::record::index)) - .route("/api/v0/record/next", get(handlers::v0::record::next)); + .route("/api/v0/record/next", get(handlers::v0::record::next)) + .route("/api/v0/store", delete(handlers::v0::store::delete)); let path = settings.path.as_str(); if path.is_empty() { |