Skip to content

Commit

Permalink
Merge branch 'main' into use-current-preview-command-for-preview-height
Browse files Browse the repository at this point in the history
  • Loading branch information
happenslol committed May 29, 2023
2 parents 3fdb715 + 9e3fa8b commit dfa45dd
Show file tree
Hide file tree
Showing 42 changed files with 565 additions and 92 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["atuin", "atuin-client", "atuin-server", "atuin-common"]

[workspace.package]
name = "atuin"
version = "14.0.1"
version = "15.0.0"
authors = ["Ellie Huxtable <[email protected]>"]
rust-version = "1.59"
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build --release --bin atuin

FROM debian:bullseye-20230320-slim AS runtime
FROM debian:bullseye-20230502-slim AS runtime

RUN useradd -c 'atuin user' atuin && mkdir /config && chown atuin:atuin /config
RUN apt update && apt install ca-certificates -y # so that webhooks work
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Read more below for offline-only usage, or for hosting your own server.
```
bash <(curl https://raw.githubusercontent.com/ellie/atuin/main/install.sh)
atuin register -u <USERNAME> -e <EMAIL> -p <PASSWORD>
atuin register -u <USERNAME> -e <EMAIL>
atuin import auto
atuin sync
```
Expand Down Expand Up @@ -130,6 +130,8 @@ bash <(curl https://raw.githubusercontent.com/ellie/atuin/main/install.sh)
atuin import auto
```

By default, Atuin will check for updates. You can [disable update checks by modifying](https://atuin.sh/docs/config/#update_check) `config.toml`.

Then restart your shell!

## Install
Expand Down Expand Up @@ -259,6 +261,10 @@ Then setup Atuin
echo 'eval "$(atuin init bash)"' >> ~/.bashrc
```

**PLEASE NOTE**

bash-preexec currently has an issue where it will stop honoring `ignorespace`. While Atuin will ignore commands prefixed with whitespace, they may still end up in your bash history. Please check your configuration! All other shells do not have this issue.

### fish

Add
Expand Down
2 changes: 1 addition & 1 deletion atuin-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ sync = [
]

[dependencies]
atuin-common = { path = "../atuin-common", version = "14.0.1" }
atuin-common = { path = "../atuin-common", version = "15.0.0" }

log = { workspace = true }
chrono = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions atuin-client/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
## which filter mode to use when atuin is invoked from a shell up-key binding
## the accepted values are identical to those of "filter_mode"
## leave unspecified to use same mode set in "filter_mode"
# filter_mode_shell_up_keybinding = "global"
# filter_mode_shell_up_key_binding = "global"

## which style to use
## possible values: auto, full, compact
Expand Down Expand Up @@ -76,7 +76,7 @@

## prevent commands run with cwd matching any of these regexes from being written
## to history. Note that these regular expressions are unanchored, i.e. if they don't
## start with ^ or end with $, they'll match anyware in CWD.
## start with ^ or end with $, they'll match anywhere in CWD.
## For details on the supported regular expression syntax, see
## https://docs.rs/regex/latest/regex/#syntax
# cwd_filter = [
Expand Down
15 changes: 15 additions & 0 deletions atuin-client/src/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,19 @@ impl<'a> Client<'a> {

Ok(())
}

pub async fn delete(&self) -> Result<()> {
let url = format!("{}/account", self.sync_addr);
let url = Url::parse(url.as_str())?;

let resp = self.client.delete(url).send().await?;

if resp.status() == 403 {
bail!("invalid login details");
} else if resp.status() == 200 {
Ok(())
} else {
bail!("Unknown error");
}
}
}
15 changes: 12 additions & 3 deletions atuin-client/src/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,19 @@ pub fn decode_key(key: String) -> Result<Key> {
let buf = BASE64_STANDARD
.decode(key.trim_end())
.wrap_err("encryption key is not a valid base64 encoding")?;
let buf: &[u8] = rmp_serde::from_slice(&buf)
.wrap_err("encryption key is not a valid message pack encoding")?;

Ok(*Key::from_slice(buf))
let mbuf: Result<[u8; 32]> =
rmp_serde::from_slice(&buf).wrap_err("encryption key is not a valid message pack encoding");

match mbuf {
Ok(b) => Ok(*Key::from_slice(&b)),
Err(_) => {
let buf: &[u8] = rmp_serde::from_slice(&buf)
.wrap_err("encryption key is not a valid message pack encoding")?;

Ok(*Key::from_slice(buf))
}
}
}

pub fn encrypt(history: &History, key: &Key) -> Result<EncryptedHistory> {
Expand Down
2 changes: 1 addition & 1 deletion atuin-client/src/import/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Importer for Bash {
// this increment is deliberately very small to prevent particularly fast fingers
// causing ordering issues; it also helps in handling the "here document" syntax,
// where several lines are recorded in succession without individual timestamps
let timestamp_increment = Duration::nanoseconds(1);
let timestamp_increment = Duration::milliseconds(1);

// make sure there is a minimum amount of time before the first known timestamp
// to fit all commands, given the default increment
Expand Down
4 changes: 4 additions & 0 deletions atuin-client/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,9 @@ pub struct Settings {
pub filter_mode_shell_up_key_binding: Option<FilterMode>,
pub shell_up_key_binding: bool,
pub inline_height: u16,
pub invert: bool,
pub show_preview: bool,
pub show_help: bool,
pub exit_mode: ExitMode,
pub word_jump_mode: WordJumpMode,
pub word_chars: String,
Expand Down Expand Up @@ -336,6 +338,8 @@ impl Settings {
.set_default("style", "auto")?
.set_default("inline_height", 0)?
.set_default("show_preview", false)?
.set_default("show_help", true)?
.set_default("invert", false)?
.set_default("exit_mode", "return-original")?
.set_default("word_jump_mode", "emacs")?
.set_default(
Expand Down
6 changes: 3 additions & 3 deletions atuin-client/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
api_client,
database::Database,
encryption::{encrypt, load_encoded_key, load_key},
settings::{Settings, HISTORY_PAGE_SIZE},
settings::Settings,
};

pub fn hash_str(string: &str) -> String {
Expand Down Expand Up @@ -72,7 +72,7 @@ async fn sync_download(

local_count = db.history_count().await?;

if page.len() < HISTORY_PAGE_SIZE.try_into().unwrap() {
if page.len() < remote_status.page_size.try_into().unwrap() {
break;
}

Expand Down Expand Up @@ -134,7 +134,7 @@ async fn sync_upload(
let mut cursor = Utc::now();

while local_count > remote_count {
let last = db.before(cursor, HISTORY_PAGE_SIZE).await?;
let last = db.before(cursor, remote_status.page_size).await?;
let mut buffer = Vec::new();

if last.is_empty() {
Expand Down
9 changes: 9 additions & 0 deletions atuin-common/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub struct RegisterResponse {
pub session: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct DeleteUserResponse {}

#[derive(Debug, Serialize, Deserialize)]
pub struct LoginRequest {
pub username: String,
Expand Down Expand Up @@ -71,6 +74,12 @@ pub struct StatusResponse {
pub count: i64,
pub username: String,
pub deleted: Vec<String>,

// These could/should also go on the index of the server
// However, we do not request the server index as a part of normal sync
// I'd rather slightly increase the size of this response, than add an extra HTTP request
pub page_size: i64, // max page size supported by the server
pub version: String,
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down
3 changes: 2 additions & 1 deletion atuin-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ homepage = { workspace = true }
repository = { workspace = true }

[dependencies]
atuin-common = { path = "../atuin-common", version = "14.0.1" }
atuin-common = { path = "../atuin-common", version = "15.0.0" }

tracing = "0.1"
chrono = { workspace = true }
Expand All @@ -34,3 +34,4 @@ tower = "0.4"
tower-http = { version = "0.3", features = ["trace"] }
reqwest = { workspace = true }
argon2 = "0.5.0"
semver = { workspace = true }
30 changes: 30 additions & 0 deletions atuin-server/migrations/20230515221038_trigger-delete-only.sql
Original file line number Diff line number Diff line change
@@ -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();
26 changes: 24 additions & 2 deletions atuin-server/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use super::{
models::{History, NewHistory, NewSession, NewUser, Session, User},
};
use crate::settings::Settings;
use crate::settings::HISTORY_PAGE_SIZE;

use atuin_common::utils::get_days_from_month;

Expand All @@ -27,6 +26,7 @@ pub trait Database {
async fn get_user(&self, username: &str) -> Result<User>;
async fn get_user_session(&self, u: &User) -> Result<Session>;
async fn add_user(&self, user: &NewUser) -> Result<i64>;
async fn delete_user(&self, u: &User) -> Result<()>;

async fn count_history(&self, user: &User) -> Result<i64>;
async fn count_history_cached(&self, user: &User) -> Result<i64>;
Expand All @@ -50,6 +50,7 @@ pub trait Database {
created_after: chrono::NaiveDateTime,
since: chrono::NaiveDateTime,
host: &str,
page_size: i64,
) -> Result<Vec<History>>;

async fn add_history(&self, history: &[NewHistory]) -> Result<()>;
Expand Down Expand Up @@ -270,6 +271,7 @@ impl Database for Postgres {
created_after: chrono::NaiveDateTime,
since: chrono::NaiveDateTime,
host: &str,
page_size: i64,
) -> Result<Vec<History>> {
let res = sqlx::query_as::<_, History>(
"select id, client_id, user_id, hostname, timestamp, data, created_at from history
Expand All @@ -284,7 +286,7 @@ impl Database for Postgres {
.bind(host)
.bind(created_after)
.bind(since)
.bind(HISTORY_PAGE_SIZE)
.bind(page_size)
.fetch_all(&self.pool)
.await?;

Expand Down Expand Up @@ -336,6 +338,26 @@ impl Database for Postgres {
Ok(())
}

#[instrument(skip_all)]
async fn delete_user(&self, u: &User) -> Result<()> {
sqlx::query("delete from sessions where user_id = $1")
.bind(u.id)
.execute(&self.pool)
.await?;

sqlx::query("delete from users where id = $1")
.bind(u.id)
.execute(&self.pool)
.await?;

sqlx::query("delete from history where user_id = $1")
.bind(u.id)
.execute(&self.pool)
.await?;

Ok(())
}

#[instrument(skip_all)]
async fn add_user(&self, user: &NewUser) -> Result<i64> {
let email: &str = &user.email;
Expand Down

0 comments on commit dfa45dd

Please sign in to comment.