aboutsummaryrefslogtreecommitdiffstats
path: root/crates/turtle/src/atuin_client/api_client.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-06-11 16:10:29 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2026-06-11 16:10:29 +0200
commit97f207b771b94c5285faae4810d6eeda1b78926b (patch)
tree4482544233c30e0e9a62be6afcfe92c8e01b0a50 /crates/turtle/src/atuin_client/api_client.rs
parentchore: Remove all `pub`s (diff)
downloadatuin-97f207b771b94c5285faae4810d6eeda1b78926b.zip
chore(server): Simplify the database support
Diffstat (limited to 'crates/turtle/src/atuin_client/api_client.rs')
-rw-r--r--crates/turtle/src/atuin_client/api_client.rs116
1 files changed, 6 insertions, 110 deletions
diff --git a/crates/turtle/src/atuin_client/api_client.rs b/crates/turtle/src/atuin_client/api_client.rs
index f3f2428a..46995c9a 100644
--- a/crates/turtle/src/atuin_client/api_client.rs
+++ b/crates/turtle/src/atuin_client/api_client.rs
@@ -16,41 +16,26 @@ use crate::atuin_common::{
};
use crate::atuin_common::{
api::{
- AddHistoryRequest, ChangePasswordRequest, CountResponse, DeleteHistoryRequest,
- ErrorResponse, LoginRequest, LoginResponse, MeResponse, RegisterResponse, StatusResponse,
- SyncHistoryResponse,
+ ChangePasswordRequest, ErrorResponse, LoginRequest, LoginResponse, MeResponse,
+ RegisterResponse,
},
record::RecordStatus,
};
use semver::Version;
-use time::OffsetDateTime;
-use time::format_description::well_known::Rfc3339;
-
-use crate::atuin_client::{history::History, sync::hash_str, utils::get_host_user};
static APP_USER_AGENT: &str = concat!("atuin/", env!("CARGO_PKG_VERSION"),);
/// Authentication token for sync API requests.
///
-/// The sync API supports two authentication methods:
-/// - `Bearer`: Hub API tokens (for users authenticated via Atuin Hub)
-/// - `Token`: Legacy CLI session tokens (for users registered via CLI or self-hosted)
-///
-/// When both are available, Hub tokens are preferred as they provide unified
-/// authentication across CLI and Hub features.
+/// Used with `Token <token>` header.
#[derive(Debug, Clone)]
-pub(crate) enum AuthToken {
- /// Legacy CLI session token, used with "Token {token}" header
- Token(String),
-}
+pub(crate) struct AuthToken(pub(crate) String);
impl AuthToken {
/// Format the token as an Authorization header value
fn to_header_value(&self) -> String {
- match self {
- AuthToken::Token(token) => format!("Token {token}"),
- }
+ format!("Token {}", self.0)
}
}
@@ -62,7 +47,7 @@ pub(crate) struct Client<'a> {
fn make_url(address: &str, path: &str) -> Result<String> {
// `join()` expects a trailing `/` in order to join paths
// e.g. it treats `http://host:port/subdir` as a file called `subdir`
- let address = if address.ends_with("/") {
+ let address = if address.ends_with('/') {
address
} else {
&format!("{address}/")
@@ -223,42 +208,6 @@ impl<'a> Client<'a> {
})
}
- pub(crate) async fn count(&self) -> Result<i64> {
- let url = make_url(self.sync_addr, "/sync/count")?;
- let url = Url::parse(url.as_str())?;
-
- let resp = self.client.get(url).send().await?;
- let resp = handle_resp_error(resp).await?;
-
- if !ensure_version(&resp)? {
- bail!("could not sync due to version mismatch");
- }
-
- if resp.status() != StatusCode::OK {
- bail!("failed to get count (are you logged in?)");
- }
-
- let count = resp.json::<CountResponse>().await?;
-
- Ok(count.count)
- }
-
- pub(crate) async fn status(&self) -> Result<StatusResponse> {
- let url = make_url(self.sync_addr, "/sync/status")?;
- let url = Url::parse(url.as_str())?;
-
- let resp = self.client.get(url).send().await?;
- let resp = handle_resp_error(resp).await?;
-
- if !ensure_version(&resp)? {
- bail!("could not sync due to version mismatch");
- }
-
- let status = resp.json::<StatusResponse>().await?;
-
- Ok(status)
- }
-
pub(crate) async fn me(&self) -> Result<MeResponse> {
let url = make_url(self.sync_addr, "/api/v0/me")?;
let url = Url::parse(url.as_str())?;
@@ -271,59 +220,6 @@ impl<'a> Client<'a> {
Ok(status)
}
- pub(crate) async fn get_history(
- &self,
- sync_ts: OffsetDateTime,
- history_ts: OffsetDateTime,
- host: Option<String>,
- ) -> Result<SyncHistoryResponse> {
- let host = host.unwrap_or_else(|| hash_str(&get_host_user()));
-
- let url = make_url(
- self.sync_addr,
- &format!(
- "/sync/history?sync_ts={}&history_ts={}&host={}",
- urlencoding::encode(sync_ts.format(&Rfc3339)?.as_str()),
- urlencoding::encode(history_ts.format(&Rfc3339)?.as_str()),
- host,
- ),
- )?;
-
- let resp = self.client.get(url).send().await?;
- let resp = handle_resp_error(resp).await?;
-
- let history = resp.json::<SyncHistoryResponse>().await?;
- Ok(history)
- }
-
- pub(crate) async fn post_history(&self, history: &[AddHistoryRequest]) -> Result<()> {
- let url = make_url(self.sync_addr, "/history")?;
- let url = Url::parse(url.as_str())?;
-
- let resp = self.client.post(url).json(history).send().await?;
- handle_resp_error(resp).await?;
-
- Ok(())
- }
-
- pub(crate) async fn delete_history(&self, h: History) -> Result<()> {
- let url = make_url(self.sync_addr, "/history")?;
- let url = Url::parse(url.as_str())?;
-
- let resp = self
- .client
- .delete(url)
- .json(&DeleteHistoryRequest {
- client_id: h.id.to_string(),
- })
- .send()
- .await?;
-
- handle_resp_error(resp).await?;
-
- Ok(())
- }
-
pub(crate) async fn delete_store(&self) -> Result<()> {
let url = make_url(self.sync_addr, "/api/v0/store")?;
let url = Url::parse(url.as_str())?;