aboutsummaryrefslogtreecommitdiffstats
path: root/crates/atuin-client/src/settings.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/atuin-client/src/settings.rs')
-rw-r--r--crates/atuin-client/src/settings.rs213
1 files changed, 6 insertions, 207 deletions
diff --git a/crates/atuin-client/src/settings.rs b/crates/atuin-client/src/settings.rs
index 1be6f363..ce84c053 100644
--- a/crates/atuin-client/src/settings.rs
+++ b/crates/atuin-client/src/settings.rs
@@ -11,7 +11,6 @@ use eyre::{Context, Error, Result, bail, eyre};
use fs_err::{File, create_dir_all};
use humantime::parse_duration;
use regex::RegexSet;
-use semver::Version;
use serde::{Deserialize, Serialize};
use serde_with::DeserializeFromStr;
use time::{OffsetDateTime, UtcOffset, format_description::FormatItem, macros::format_description};
@@ -23,32 +22,12 @@ static DATA_DIR: OnceLock<PathBuf> = OnceLock::new();
static META_CONFIG: OnceLock<(String, f64)> = OnceLock::new();
static META_STORE: OnceCell<crate::meta::MetaStore> = OnceCell::const_new();
-mod dotfiles;
-mod kv;
pub(crate) mod meta;
-mod scripts;
pub mod watcher;
-pub struct HubEndpoint(String);
-
/// Default sync address for Atuin's hosted service
pub const DEFAULT_SYNC_ADDRESS: &str = "https://api.atuin.sh";
-/// Default Hub web/API endpoint for Atuin's hosted service
-pub const DEFAULT_HUB_ENDPOINT: &str = "https://hub.atuin.sh";
-
-impl Default for HubEndpoint {
- fn default() -> Self {
- HubEndpoint(DEFAULT_HUB_ENDPOINT.to_string())
- }
-}
-
-impl AsRef<str> for HubEndpoint {
- fn as_ref(&self) -> &str {
- &self.0
- }
-}
-
#[derive(Clone, Debug, Deserialize, Copy, ValueEnum, PartialEq, Serialize)]
pub enum SearchMode {
#[serde(rename = "prefix")]
@@ -374,13 +353,9 @@ pub struct Sync {
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq, Serialize, Default)]
#[serde(rename_all = "lowercase")]
pub enum SyncProtocol {
- /// Use Hub authentication (Bearer token from Hub OAuth flow)
- Hub,
/// Use legacy CLI authentication (Token from CLI register/login)
- Legacy,
- /// Infer from sync_address (default behavior)
#[default]
- Auto,
+ Legacy,
}
/// Resolved authentication state for sync operations.
@@ -394,14 +369,7 @@ pub enum SyncAuth {
/// Self-hosted Rust server. Uses `Authorization: Token <session>` and
/// legacy endpoints.
Legacy { token: String },
- /// Hub with a valid Hub API token (`atapi_*`). Uses
- /// `Authorization: Bearer <token>` and v0 endpoints.
- Hub { token: String },
- /// Targeting Hub but only has a CLI session token. Uses
- /// `Authorization: Token <session>` against compat/record endpoints.
- /// Sync, password change, and account deletion still work, but the user
- /// should be nudged to run `atuin login` for full Hub auth.
- HubViaCli { token: String },
+
/// Not authenticated at all. Contains an actionable user-facing message.
NotLoggedIn { reason: String },
}
@@ -415,8 +383,6 @@ impl SyncAuth {
use crate::api_client::AuthToken;
match self {
SyncAuth::Legacy { token } => Ok(AuthToken::Token(token)),
- SyncAuth::Hub { token } => Ok(AuthToken::Bearer(token)),
- SyncAuth::HubViaCli { token } => Ok(AuthToken::Token(token)),
SyncAuth::NotLoggedIn { reason } => Err(eyre!(reason)),
}
}
@@ -1082,9 +1048,6 @@ pub struct Settings {
/// The sync address for atuin.
pub sync_address: String,
- /// Sync protocol for authentication. When set to "auto" (default), the protocol
- /// is inferred from sync_address. Set to "hub" to force Hub auth with a custom
- /// sync_address (useful for local development).
#[serde(default)]
pub sync_protocol: SyncProtocol,
@@ -1152,9 +1115,6 @@ pub struct Settings {
pub preview: Preview,
#[serde(default)]
- pub dotfiles: dotfiles::Settings,
-
- #[serde(default)]
pub daemon: Daemon,
#[serde(default)]
@@ -1167,12 +1127,6 @@ pub struct Settings {
pub ui: Ui,
#[serde(default)]
- pub scripts: scripts::Settings,
-
- #[serde(default)]
- pub kv: kv::Settings,
-
- #[serde(default)]
pub tmux: Tmux,
#[serde(default)]
@@ -1180,9 +1134,6 @@ pub struct Settings {
#[serde(default)]
pub meta: meta::Settings,
-
- #[serde(default)]
- pub ai: Ai,
}
impl Settings {
@@ -1266,56 +1217,6 @@ impl Settings {
}
}
- pub async fn hub_session_token(&self) -> Result<String> {
- match Self::meta_store().await?.hub_session_token().await? {
- Some(token) => Ok(token),
- None => Err(eyre!("Tried to load hub session; not logged in")),
- }
- }
-
- /// Normalize a URL for comparison by trimming trailing slashes
- fn normalize_url(url: &str) -> &str {
- url.trim_end_matches('/')
- }
-
- /// Check if a URL matches one of Atuin's official hosted addresses
- fn is_official_address(url: &str) -> bool {
- let normalized = Self::normalize_url(url);
- normalized == Self::normalize_url(DEFAULT_SYNC_ADDRESS)
- || normalized == Self::normalize_url(DEFAULT_HUB_ENDPOINT)
- }
-
- /// Returns whether this configuration uses Hub-style sync.
- ///
- /// Hub sync uses Bearer token authentication and is the default for
- /// Atuin's hosted service. This returns true when:
- /// - `sync_protocol` is explicitly set to `Hub`, OR
- /// - `sync_protocol` is `Auto` and `sync_address` is an official Atuin address
- pub fn is_hub_sync(&self) -> bool {
- match self.sync_protocol {
- SyncProtocol::Hub => true,
- SyncProtocol::Legacy => false,
- SyncProtocol::Auto => Self::is_official_address(&self.sync_address),
- }
- }
-
- /// Returns the base URL for the Hub endpoint.
- ///
- /// For Atuin's official hosted service, this always returns `https://hub.atuin.sh`
- /// regardless of whether `sync_address` is `api.atuin.sh` or `hub.atuin.sh`.
- /// For self-hosted instances, returns the configured `sync_address`.
- pub fn active_hub_endpoint(&self) -> Option<HubEndpoint> {
- if self.is_hub_sync() {
- if Self::is_official_address(&self.sync_address) {
- Some(HubEndpoint::default())
- } else {
- Some(HubEndpoint(self.sync_address.clone()))
- }
- } else {
- None
- }
- }
-
/// Examines the configured sync target and available tokens to determine
/// the correct auth strategy. Also performs cleanup of mis-stored tokens
/// (e.g. a CLI token incorrectly saved in the Hub session slot).
@@ -1330,45 +1231,12 @@ impl Settings {
}
};
- if !self.is_hub_sync() {
- // Self-hosted / legacy server
- return match meta.session_token().await {
- Ok(Some(token)) => SyncAuth::Legacy { token },
- _ => SyncAuth::NotLoggedIn {
- reason: "Not logged in. Run 'atuin login' to authenticate \
- with your sync server."
- .into(),
- },
- };
- }
-
- // Targeting Hub — check for a valid Hub API token first
- if let Ok(Some(hub_token)) = meta.hub_session_token().await {
- if hub_token.starts_with("atapi_") {
- return SyncAuth::Hub { token: hub_token };
- }
-
- // A non-atapi_ token in the hub_session slot is a mis-stored CLI
- // token (from the migration-fallback bug). Move it to the CLI
- // session slot if that slot is empty, then clear hub_session
- // only if the move succeeded.
- if let Ok(None) = meta.session_token().await {
- if meta.save_session(&hub_token).await.is_ok() {
- let _ = meta.delete_hub_session().await;
- }
- } else {
- // CLI slot already has a token; just clear the bad hub_session
- let _ = meta.delete_hub_session().await;
- }
- // Fall through to check CLI token below
- }
-
- // No valid Hub token — check for a CLI session token
+ // Self-hosted / legacy server
match meta.session_token().await {
- Ok(Some(token)) => SyncAuth::HubViaCli { token },
+ Ok(Some(token)) => SyncAuth::Legacy { token },
_ => SyncAuth::NotLoggedIn {
- reason: "Not logged in. Run 'atuin login' or 'atuin register' \
- to authenticate."
+ reason: "Not logged in. Run 'atuin login' to authenticate \
+ with your sync server."
.into(),
},
}
@@ -1384,70 +1252,6 @@ impl Settings {
self.resolve_sync_auth().await.into_auth_token()
}
- #[cfg(feature = "check-update")]
- async fn needs_update_check(&self) -> Result<bool> {
- let last_check = Settings::last_version_check().await?;
- let diff = OffsetDateTime::now_utc() - last_check;
-
- // Check a max of once per hour
- Ok(diff.whole_hours() >= 1)
- }
-
- #[cfg(feature = "check-update")]
- async fn latest_version(&self) -> Result<Version> {
- // Default to the current version, and if that doesn't parse, a version so high it's unlikely to ever
- // suggest upgrading.
- let current =
- Version::parse(env!("CARGO_PKG_VERSION")).unwrap_or(Version::new(100000, 0, 0));
-
- if !self.needs_update_check().await? {
- let meta = Self::meta_store().await?;
- let version = match meta.latest_version().await? {
- Some(v) => Version::parse(&v).unwrap_or(current),
- None => current,
- };
-
- return Ok(version);
- }
-
- #[cfg(feature = "sync")]
- let latest = crate::api_client::latest_version().await.unwrap_or(current);
-
- #[cfg(not(feature = "sync"))]
- let latest = current;
-
- let meta = Self::meta_store().await?;
- Settings::save_version_check_time().await?;
- meta.save_latest_version(&latest.to_string()).await?;
-
- Ok(latest)
- }
-
- // Return Some(latest version) if an update is needed. Otherwise, none.
- #[cfg(feature = "check-update")]
- pub async fn needs_update(&self) -> Option<Version> {
- if !self.update_check {
- return None;
- }
-
- let current =
- Version::parse(env!("CARGO_PKG_VERSION")).unwrap_or(Version::new(100000, 0, 0));
-
- let latest = self.latest_version().await;
-
- if latest.is_err() {
- return None;
- }
-
- let latest = latest.unwrap();
-
- if latest > current {
- return Some(latest);
- }
-
- None
- }
-
pub fn default_filter_mode(&self, git_root: bool) -> FilterMode {
self.filter_mode
.filter(|x| self.search.filters.contains(x))
@@ -1465,11 +1269,6 @@ impl Settings {
.unwrap_or(FilterMode::Global)
}
- #[cfg(not(feature = "check-update"))]
- pub async fn needs_update(&self) -> Option<Version> {
- None
- }
-
pub fn builder() -> Result<ConfigBuilder<DefaultState>> {
Self::builder_with_data_dir(&atuin_common::utils::data_dir())
}