diff options
author | Ellie Huxtable <e@elm.sh> | 2021-04-20 21:53:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-20 20:53:07 +0000 |
commit | a21737e2b7f8d1e426726bdd7536033f299d476a (patch) | |
tree | e940afdff9c145d25d9a2895fd44a77d70719a2e | |
parent | 34888827f8a06de835cbe5833a06914f28cce514 (diff) |
Use cargo workspaces (#37)
* Switch to Cargo workspaces
Breaking things into "client", "server" and "common" makes managing the
codebase much easier!
client - anything running on a user's machine for adding history
server - handles storing/syncing history and running a HTTP server
common - request/response API definitions, common utils, etc
* Update dockerfile
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Cargo.lock | 166 | ||||
-rw-r--r-- | Cargo.toml | 31 | ||||
-rw-r--r-- | Dockerfile | 53 | ||||
-rw-r--r-- | atuin-client/Cargo.toml | 40 | ||||
-rw-r--r-- | atuin-client/config.toml (renamed from config.toml) | 19 | ||||
-rw-r--r-- | atuin-client/src/api_client.rs (renamed from src/local/api_client.rs) | 9 | ||||
-rw-r--r-- | atuin-client/src/database.rs (renamed from src/local/database.rs) | 0 | ||||
-rw-r--r-- | atuin-client/src/encryption.rs (renamed from src/local/encryption.rs) | 4 | ||||
-rw-r--r-- | atuin-client/src/history.rs (renamed from src/local/history.rs) | 2 | ||||
-rw-r--r-- | atuin-client/src/import.rs (renamed from src/local/import.rs) | 0 | ||||
-rw-r--r-- | atuin-client/src/lib.rs (renamed from src/local/mod.rs) | 7 | ||||
-rw-r--r-- | atuin-client/src/settings.rs (renamed from src/settings.rs) | 59 | ||||
-rw-r--r-- | atuin-client/src/sync.rs (renamed from src/local/sync.rs) | 19 | ||||
-rw-r--r-- | atuin-common/Cargo.toml | 21 | ||||
-rw-r--r-- | atuin-common/src/api.rs (renamed from src/api.rs) | 0 | ||||
-rw-r--r-- | atuin-common/src/lib.rs | 5 | ||||
-rw-r--r-- | atuin-common/src/utils.rs (renamed from src/utils.rs) | 5 | ||||
-rw-r--r-- | atuin-server/Cargo.toml | 38 | ||||
-rw-r--r-- | atuin-server/server.toml | 11 | ||||
-rw-r--r-- | atuin-server/src/auth.rs (renamed from src/server/auth.rs) | 0 | ||||
-rw-r--r-- | atuin-server/src/database.rs (renamed from src/server/database.rs) | 0 | ||||
-rw-r--r-- | atuin-server/src/handlers/history.rs (renamed from src/server/handlers/history.rs) | 6 | ||||
-rw-r--r-- | atuin-server/src/handlers/mod.rs (renamed from src/server/handlers/mod.rs) | 0 | ||||
-rw-r--r-- | atuin-server/src/handlers/user.rs (renamed from src/server/handlers/user.rs) | 11 | ||||
-rw-r--r-- | atuin-server/src/lib.rs (renamed from src/server/mod.rs) | 7 | ||||
-rw-r--r-- | atuin-server/src/models.rs (renamed from src/server/models.rs) | 0 | ||||
-rw-r--r-- | atuin-server/src/router.rs (renamed from src/server/router.rs) | 8 | ||||
-rw-r--r-- | atuin-server/src/settings.rs | 57 | ||||
-rw-r--r-- | src/command/history.rs | 10 | ||||
-rw-r--r-- | src/command/import.rs | 6 | ||||
-rw-r--r-- | src/command/login.rs | 8 | ||||
-rw-r--r-- | src/command/mod.rs | 40 | ||||
-rw-r--r-- | src/command/register.rs | 8 | ||||
-rw-r--r-- | src/command/search.rs | 5 | ||||
-rw-r--r-- | src/command/server.rs | 15 | ||||
-rw-r--r-- | src/command/stats.rs | 8 | ||||
-rw-r--r-- | src/command/sync.rs | 6 | ||||
-rw-r--r-- | src/main.rs | 39 |
39 files changed, 415 insertions, 309 deletions
@@ -1,2 +1,3 @@ /target +*/target .env @@ -3,21 +3,6 @@ version = 3 [[package]] -name = "addr2line" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a55f82cfe485775d02112886f4169bde0c5894d75e79ead7eafe7e40a25e45f7" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] name = "ahash" version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -100,17 +85,46 @@ name = "atuin" version = "0.5.0" dependencies = [ "async-trait", + "atuin-client", + "atuin-common", + "atuin-server", "base64", "chrono", "chrono-english", "cli-table", - "config", "directories", - "dotenv", "eyre", "fern", "fork", - "human-panic", + "humantime", + "indicatif", + "itertools", + "log", + "reqwest", + "rusqlite", + "serde 1.0.125", + "serde_derive", + "serde_json", + "structopt", + "termion", + "tokio", + "tui", + "unicode-width", +] + +[[package]] +name = "atuin-client" +version = "0.1.0" +dependencies = [ + "async-trait", + "atuin-common", + "base64", + "chrono", + "chrono-english", + "config", + "directories", + "eyre", + "fern", "humantime", "indicatif", "itertools", @@ -126,11 +140,55 @@ dependencies = [ "serde_json", "shellexpand", "sodiumoxide", + "tokio", + "urlencoding", + "uuid", + "whoami", +] + +[[package]] +name = "atuin-common" +version = "0.1.0" +dependencies = [ + "chrono", + "eyre", + "rmp-serde", + "rust-crypto", + "serde 1.0.125", + "serde_derive", + "serde_json", + "sodiumoxide", + "uuid", + "warp", +] + +[[package]] +name = "atuin-server" +version = "0.1.0" +dependencies = [ + "async-trait", + "atuin-common", + "base64", + "chrono", + "chrono-english", + "config", + "directories", + "eyre", + "fern", + "fork", + "indicatif", + "log", + "parse_duration", + "rand 0.8.3", + "reqwest", + "rmp-serde", + "rust-crypto", + "serde 1.0.125", + "serde_derive", + "serde_json", + "sodiumoxide", "sqlx", - "structopt", - "termion", "tokio", - "tui", "unicode-width", "urlencoding", "uuid", @@ -145,20 +203,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] -name = "backtrace" -version = "0.3.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d117600f438b1707d4e4ae15d3595657288f8235a0eb593e80ecc98ab34e1bc" -dependencies = [ - "addr2line", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] name = "base64" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -772,12 +816,6 @@ dependencies = [ ] [[package]] -name = "gimli" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce" - -[[package]] name = "h2" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -908,21 +946,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" [[package]] -name = "human-panic" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39f357a500abcbd7c5f967c1d45c8838585b36743823b9d43488f24850534e36" -dependencies = [ - "backtrace", - "os_type", - "serde 1.0.125", - "serde_derive", - "termcolor", - "toml", - "uuid", -] - -[[package]] name = "humantime" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1169,16 +1192,6 @@ dependencies = [ ] [[package]] -name = "miniz_oxide" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" -dependencies = [ - "adler", - "autocfg", -] - -[[package]] name = "mio" version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1378,12 +1391,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" [[package]] -name = "object" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" - -[[package]] name = "once_cell" version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1429,15 +1436,6 @@ dependencies = [ ] [[package]] -name = "os_type" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7edc011af0ae98b7f88cf7e4a83b70a54a75d2b8cb013d6efd02e5956207e9eb" -dependencies = [ - "regex", -] - -[[package]] name = "parking_lot" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1901,12 +1899,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2" [[package]] -name = "rustc-demangle" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e3bad0ee36814ca07d7968269dd4b7ec89ec2da10c4bb613928d3077083c232" - -[[package]] name = "rustc-serialize" version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1,47 +1,40 @@ [package] name = "atuin" version = "0.5.0" -authors = ["Ellie Huxtable <e@elm.sh>"] +authors = ["Ellie Huxtable <ellie@elliehuxtable.com>"] edition = "2018" license = "MIT" description = "atuin - magical shell history" +[workspace] +members = ["./atuin-client", "./atuin-server", "./atuin-common"] + [dependencies] +atuin-server = { path = "atuin-server", version = "0.1.0" } +atuin-client = { path = "atuin-client", version = "0.1.0" } +atuin-common = { path = "atuin-common", version = "0.1.0" } + log = "0.4" fern = {version = "0.6.0", features = ["colored"] } chrono = { version = "0.4", features = ["serde"] } eyre = "0.6" -shellexpand = "2" structopt = "0.3" directories = "3" -uuid = { version = "0.8", features = ["v4"] } indicatif = "0.15.0" -whoami = "1.1.2" -chrono-english = "0.1.4" -cli-table = "0.4" -config = "0.11" serde_derive = "1.0.125" serde = "1.0.125" serde_json = "1.0.64" -rmp-serde = "0.15.4" tui = "0.14" termion = "1.5" unicode-width = "0.1" itertools = "0.10.0" -dotenv = "0.15.0" -sodiumoxide = "0.2.6" -reqwest = { version = "0.11", features = ["blocking", "json"] } -base64 = "0.13.0" fork = "0.1.18" -parse_duration = "2.1.1" -rand = "0.8.3" -rust-crypto = "^0.2" -human-panic = "1.0.3" tokio = { version = "1", features = ["full"] } -warp = "0.3" -sqlx = { version = "0.5", features = [ "runtime-tokio-native-tls", "uuid", "chrono", "postgres" ] } async-trait = "0.1.49" -urlencoding = "1.1.1" +chrono-english = "0.1.4" +cli-table = "0.4" +reqwest = { version = "0.11", features = ["blocking", "json"] } +base64 = "0.13.0" humantime = "2.1.0" [dependencies.rusqlite] @@ -1,31 +1,22 @@ -FROM rust:1.51-buster as builder - -RUN cargo new --bin atuin -WORKDIR /atuin -COPY ./Cargo.toml ./Cargo.toml -COPY ./Cargo.lock ./Cargo.lock - -RUN cargo build --release - -RUN rm src/*.rs - -ADD . ./ - -RUN rm ./target/release/deps/atuin* -RUN cargo build --release - -FROM debian:buster-slim - -RUN apt-get update \ - && apt-get install -y ca-certificates tzdata libpq-dev \ - && rm -rf /var/lib/apt/lists/* - -EXPOSE 8888 - -ENV TZ=Etc/UTC -ENV RUST_LOG=info -ENV ATUIN_CONFIG=/config/config.toml - -COPY --from=builder /atuin/target/release/atuin ./atuin - -ENTRYPOINT ["./atuin"] +FROM lukemathwalker/cargo-chef as planner +WORKDIR app +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM lukemathwalker/cargo-chef as cacher +WORKDIR app +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json + +FROM rust as builder +WORKDIR app +COPY . . +# Copy over the cached dependencies +COPY --from=cacher /app/target target +COPY --from=cacher $CARGO_HOME $CARGO_HOME +RUN cargo build --release --bin atuin + +FROM debian:buster-slim as runtime +WORKDIR app +COPY --from=builder /app/target/release/atuin /usr/local/bin +ENTRYPOINT ["/usr/local/bin/atuin"] diff --git a/atuin-client/Cargo.toml b/atuin-client/Cargo.toml new file mode 100644 index 00000000..06c96a9a --- /dev/null +++ b/atuin-client/Cargo.toml @@ -0,0 +1,40 @@ +[package] +name = "atuin-client" +version = "0.1.0" +authors = ["Ellie Huxtable <ellie@elliehuxtable.com>"] +edition = "2018" +license = "MIT" +description = "client library for atuin" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +atuin-common = { path = "../atuin-common", version = "0.1.0" } + +log = "0.4" +fern = {version = "0.6.0", features = ["colored"] } +chrono = { version = "0.4", features = ["serde"] } +eyre = "0.6" +directories = "3" +uuid = { version = "0.8", features = ["v4"] } +indicatif = "0.15.0" +whoami = "1.1.2" +chrono-english = "0.1.4" +config = "0.11" +serde_derive = "1.0.125" +serde = "1.0.125" +serde_json = "1.0.64" +rmp-serde = "0.15.4" +sodiumoxide = "0.2.6" +reqwest = { version = "0.11", features = ["blocking", "json"] } +base64 = "0.13.0" +parse_duration = "2.1.1" +rand = "0.8.3" +rust-crypto = "^0.2" +tokio = { version = "1", features = ["full"] } +async-trait = "0.1.49" +urlencoding = "1.1.1" +humantime = "2.1.0" +rusqlite= { version = "0.25", features = ["bundled"] } +itertools = "0.10.0" +shellexpand = "2" diff --git a/config.toml b/atuin-client/config.toml index fe776d6e..33e5b545 100644 --- a/config.toml +++ b/atuin-client/config.toml @@ -1,8 +1,3 @@ -# A'tuin example config - -# This section specifies the config for a local client, -# ie where your shell history is on your local machine -[local] ## where to store your database, default is your system data directory ## mac: ~/Library/Application Support/com.elliehuxtable.atuin/history.db ## linux: ~/.local/share/atuin/history.db @@ -27,17 +22,3 @@ ## address of the sync server # sync_address = "https://api.atuin.sh" - -# This section configures the sync server, if you decide to host your own -[server] -## host to bind, can also be passed via CLI args -# host = "127.0.0.1" - -## port to bind, can also be passed via CLI args -# port = 8888 - -## whether to allow anyone to register an account -# open_registration = false - -## URI for postgres (using development creds here) -# db_uri="postgres://username:password@localhost/atuin" diff --git a/src/local/api_client.rs b/atuin-client/src/api_client.rs index 1b64a295..db2802c3 100644 --- a/src/local/api_client.rs +++ b/atuin-client/src/api_client.rs @@ -4,10 +4,11 @@ use reqwest::header::{HeaderMap, AUTHORIZATION}; use reqwest::Url; use sodiumoxide::crypto::secretbox; -use crate::api::{AddHistoryRequest, CountResponse, SyncHistoryResponse}; -use crate::local::encryption::decrypt; -use crate::local::history::History; -use crate::utils::hash_str; +use atuin_common::api::{AddHistoryRequest, CountResponse, SyncHistoryResponse}; +use atuin_common::utils::hash_str; + +use crate::encryption::decrypt; +use crate::history::History; pub struct Client<'a> { sync_addr: &'a str, diff --git a/src/local/database.rs b/atuin-client/src/database.rs index abc22bb8..abc22bb8 100644 --- a/src/local/database.rs +++ b/atuin-client/src/database.rs diff --git a/src/local/encryption.rs b/atuin-client/src/encryption.rs index 3c1699e3..37153f94 100644 --- a/src/local/encryption.rs +++ b/atuin-client/src/encryption.rs @@ -15,7 +15,7 @@ use std::path::PathBuf; use eyre::{eyre, Result}; use sodiumoxide::crypto::secretbox; -use crate::local::history::History; +use crate::history::History; use crate::settings::Settings; #[derive(Debug, Serialize, Deserialize)] @@ -26,7 +26,7 @@ pub struct EncryptedHistory { // Loads the secret key, will create + save if it doesn't exist pub fn load_key(settings: &Settings) -> Result<secretbox::Key> { - let path = settings.local.key_path.as_str(); + let path = settings.key_path.as_str(); if PathBuf::from(path).exists() { let bytes = std::fs::read(path)?; diff --git a/src/local/history.rs b/atuin-client/src/history.rs index 1712f8b9..7f607784 100644 --- a/src/local/history.rs +++ b/atuin-client/src/history.rs @@ -3,7 +3,7 @@ use std::hash::{Hash, Hasher}; use chrono::Utc; -use crate::command::uuid_v4; +use atuin_common::utils::uuid_v4; // Any new fields MUST be Optional<>! #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/src/local/import.rs b/atuin-client/src/import.rs index 3b0b2a69..3b0b2a69 100644 --- a/src/local/import.rs +++ b/atuin-client/src/import.rs diff --git a/src/local/mod.rs b/atuin-client/src/lib.rs index 9fe31292..1207bfdb 100644 --- a/src/local/mod.rs +++ b/atuin-client/src/lib.rs @@ -1,6 +1,13 @@ +#[macro_use] +extern crate log; + +#[macro_use] +extern crate serde_derive; + pub mod api_client; pub mod database; pub mod encryption; pub mod history; pub mod import; +pub mod settings; pub mod sync; diff --git a/src/settings.rs b/atuin-client/src/settings.rs index 5325610e..e28963c0 100644 --- a/src/settings.rs +++ b/atuin-client/src/settings.rs @@ -12,7 +12,7 @@ use parse_duration::parse; pub const HISTORY_PAGE_SIZE: i64 = 100; #[derive(Clone, Debug, Deserialize)] -pub struct Local { +pub struct Settings { pub dialect: String, pub auto_sync: bool, pub sync_address: String, @@ -26,7 +26,7 @@ pub struct Local { pub session_token: String, } -impl Local { +impl Settings { pub fn save_sync_time() -> Result<()> { let sync_time_path = ProjectDirs::from("com", "elliehuxtable", "atuin") .ok_or_else(|| eyre!("could not determine key file location"))?; @@ -66,28 +66,12 @@ impl Local { match parse(self.sync_frequency.as_str()) { Ok(d) => { let d = chrono::Duration::from_std(d).unwrap(); - Ok(Utc::now() - Local::last_sync()? >= d) + Ok(Utc::now() - Settings::last_sync()? >= d) } Err(e) => Err(eyre!("failed to check sync: {}", e)), } } -} -#[derive(Clone, Debug, Deserialize)] -pub struct Server { - pub host: String, - pub port: u16, - pub db_uri: String, - pub open_registration: bool, -} - -#[derive(Clone, Debug, Deserialize)] -pub struct Settings { - pub local: Local, - pub server: Server, -} - -impl Settings { pub fn new() -> Result<Self> { let config_dir = ProjectDirs::from("com", "elliehuxtable", "atuin").unwrap(); let config_dir = config_dir.config_dir(); @@ -103,8 +87,6 @@ impl Settings { config_file }; - // create the config file if it does not exist - let mut s = Config::new(); let db_path = ProjectDirs::from("com", "elliehuxtable", "atuin") @@ -122,18 +104,13 @@ impl Settings { .data_dir() .join("session"); - s.set_default("local.db_path", db_path.to_str())?; - s.set_default("local.key_path", key_path.to_str())?; - s.set_default("local.session_path", session_path.to_str())?; - s.set_default("local.dialect", "us")?; - s.set_default("local.auto_sync", true)?; - s.set_default("local.sync_frequency", "5m")?; - s.set_default("local.sync_address", "https://api.atuin.sh")?; - - s.set_default("server.host", "127.0.0.1")?; - s.set_default("server.port", 8888)?; - s.set_default("server.open_registration", false)?; - s.set_default("server.db_uri", "default_uri")?; + s.set_default("db_path", db_path.to_str())?; + s.set_default("key_path", key_path.to_str())?; + s.set_default("session_path", session_path.to_str())?; + s.set_default("dialect", "us")?; + s.set_default("auto_sync", true)?; + s.set_default("sync_frequency", "5m")?; + s.set_default("sync_address", "https://api.atuin.sh")?; if config_file.exists() { s.merge(ConfigFile::with_name(config_file.to_str().unwrap()))?; @@ -146,24 +123,24 @@ impl Settings { s.merge(Environment::with_prefix("atuin").separator("_"))?; // all paths should be expanded - let db_path = s.get_str("local.db_path")?; + let db_path = s.get_str("db_path")?; let db_path = shellexpand::full(db_path.as_str())?; - s.set("local.db_path", db_path.to_string())?; + s.set("db_path", db_path.to_string())?; - let key_path = s.get_str("local.key_path")?; + let key_path = s.get_str("key_path")?; let key_path = shellexpand::full(key_path.as_str())?; - s.set("local.key_path", key_path.to_string())?; + s.set("key_path", key_path.to_string())?; - let session_path = s.get_str("local.session_path")?; + let session_path = s.get_str("session_path")?; let session_path = shellexpand::full(session_path.as_str())?; - s.set("local.session_path", session_path.to_string())?; + s.set("session_path", session_path.to_string())?; // Finally, set the auth token if Path::new(session_path.to_string().as_str()).exists() { let token = std::fs::read_to_string(session_path.to_string())?; - s.set("local.session_token", token.trim())?; + s.set("session_token", token.trim())?; } else { - s.set("local.session_token", "not logged in")?; + s.set("session_token", "not logged in")?; } s.try_into() diff --git a/src/local/sync.rs b/atuin-client/src/sync.rs index e0feb759..0ca8d3a6 100644 --- a/src/local/sync.rs +++ b/atuin-client/src/sync.rs @@ -3,11 +3,12 @@ use std::convert::TryInto; use chrono::prelude::*; use eyre::Result; -use crate::local::api_client; -use crate::local::database::Database; -use crate::local::encryption::{encrypt, load_key}; -use crate::settings::{Local, Settings, HISTORY_PAGE_SIZE}; -use crate::{api::AddHistoryRequest, utils::hash_str}; +use atuin_common::{api::AddHistoryRequest, utils::hash_str}; + +use crate::api_client; +use crate::database::Database; +use crate::encryption::{encrypt, load_key}; +use crate::settings::{Settings, HISTORY_PAGE_SIZE}; // Currently sync is kinda naive, and basically just pages backwards through // history. This means newly added stuff shows up properly! We also just use @@ -33,7 +34,7 @@ async fn sync_download( let mut last_sync = if force { Utc.timestamp_millis(0) } else { - Local::last_sync()? + Settings::last_sync()? }; let mut last_timestamp = Utc.timestamp_millis(0); @@ -124,8 +125,8 @@ async fn sync_upload( pub async fn sync(settings: &Settings, force: bool, db: &mut (impl Database + Send)) -> Result<()> { let client = api_client::Client::new( - settings.local.sync_address.as_str(), - settings.local.session_token.as_str(), + settings.sync_address.as_str(), + settings.session_token.as_str(), load_key(settings)?, ); @@ -135,7 +136,7 @@ pub async fn sync(settings: &Settings, force: bool, db: &mut (impl Database + Se debug!("sync downloaded {}", download.0); - Local::save_sync_time()?; + Settings::save_sync_time()?; Ok(()) } diff --git a/atuin-common/Cargo.toml b/atuin-common/Cargo.toml new file mode 100644 index 00000000..efe7da63 --- /dev/null +++ b/atuin-common/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "atuin-common" +version = "0.1.0" +authors = ["Ellie Huxtable <ellie@elliehuxtable.com>"] +edition = "2018" +license = "MIT" +description = "common library for atuin" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rust-crypto = "^0.2" +sodiumoxide = "0.2.6" +chrono = { version = "0.4", features = ["serde"] } +eyre = "0.6" +serde_derive = "1.0.125" +serde = "1.0.125" +serde_json = "1.0.64" +rmp-serde = "0.15.4" +warp = "0.3" +uuid = { version = "0.8", features = ["v4"] } diff --git a/src/api.rs b/atuin-common/src/api.rs index 82ee6604..82ee6604 100644 --- a/src/api.rs +++ b/ |