chore: update deprecated usage

This commit is contained in:
Conrad Ludgate 2021-11-21 11:26:39 +00:00
parent f1deca0a94
commit 8bf68fab1f
No known key found for this signature in database
GPG Key ID: 3DD1A1DB3CB4BF63
4 changed files with 282 additions and 132 deletions

326
Cargo.lock generated
View File

@ -2,6 +2,12 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "ahash"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e"
[[package]]
name = "ahash"
version = "0.7.2"
@ -75,7 +81,7 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "616896e05fc0e2649463a93a15183c6a16bf03413a7af88ef1285ddedfa9cda5"
dependencies = [
"num-traits 0.2.14",
"num-traits",
]
[[package]]
@ -110,7 +116,7 @@ dependencies = [
"itertools",
"log",
"pretty_env_logger",
"serde 1.0.126",
"serde",
"serde_derive",
"serde_json",
"structopt",
@ -144,7 +150,7 @@ dependencies = [
"reqwest",
"rmp-serde",
"rust-crypto",
"serde 1.0.126",
"serde",
"serde_derive",
"serde_json",
"shellexpand",
@ -165,7 +171,7 @@ dependencies = [
"eyre",
"rmp-serde",
"rust-crypto",
"serde 1.0.126",
"serde",
"serde_derive",
"serde_json",
"sodiumoxide",
@ -193,7 +199,7 @@ dependencies = [
"rand 0.8.4",
"rmp-serde",
"rust-crypto",
"serde 1.0.126",
"serde",
"serde_derive",
"serde_json",
"sodiumoxide",
@ -236,13 +242,34 @@ dependencies = [
"wyz",
]
[[package]]
name = "block-buffer"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b"
dependencies = [
"block-padding",
"byte-tools",
"byteorder",
"generic-array 0.12.4",
]
[[package]]
name = "block-buffer"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
dependencies = [
"generic-array",
"generic-array 0.14.4",
]
[[package]]
name = "block-padding"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5"
dependencies = [
"byte-tools",
]
[[package]]
@ -254,7 +281,7 @@ dependencies = [
"lazy_static",
"memchr",
"regex-automata",
"serde 1.0.126",
"serde",
]
[[package]]
@ -279,6 +306,12 @@ version = "3.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe"
[[package]]
name = "byte-tools"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
[[package]]
name = "byteorder"
version = "1.4.3"
@ -317,8 +350,8 @@ checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"libc",
"num-integer",
"num-traits 0.2.14",
"serde 1.0.126",
"num-traits",
"serde",
"time",
"winapi",
]
@ -386,14 +419,15 @@ dependencies = [
[[package]]
name = "config"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1b9d958c2b1368a663f05538fc1b5975adce1e19f435acceae987aceeeb369"
source = "git+https://github.com/conradludgate/config-rs?branch=absolute-path-current-dir#4e0e155b5f7ef32b5b3f9d02f8f5efedbdfa1782"
dependencies = [
"async-trait",
"json5",
"lazy_static",
"nom 5.1.2",
"nom 7.1.0",
"ron",
"rust-ini",
"serde 1.0.126",
"serde-hjson",
"serde",
"serde_json",
"toml",
"yaml-rust",
@ -464,7 +498,7 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4857fd85a0c34b3c3297875b747c1e02e06b6a0ea32dd892d8192b9ce0813ea6"
dependencies = [
"generic-array",
"generic-array 0.14.4",
"subtle",
]
@ -478,7 +512,7 @@ dependencies = [
"csv-core",
"itoa",
"ryu",
"serde 1.0.126",
"serde",
]
[[package]]
@ -490,13 +524,22 @@ dependencies = [
"memchr",
]
[[package]]
name = "digest"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
dependencies = [
"generic-array 0.12.4",
]
[[package]]
name = "digest"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066"
dependencies = [
"generic-array",
"generic-array 0.14.4",
]
[[package]]
@ -549,6 +592,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "dlv-list"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68df3f2b690c1b86e65ef7830956aededf3cb0a16f898f79b9a6f421a7b6211b"
dependencies = [
"rand 0.8.4",
]
[[package]]
name = "dotenv"
version = "0.15.0"
@ -599,6 +651,12 @@ dependencies = [
"once_cell",
]
[[package]]
name = "fake-simd"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
[[package]]
name = "fern"
version = "0.6.0"
@ -744,6 +802,15 @@ version = "0.3.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2"
[[package]]
name = "generic-array"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd"
dependencies = [
"typenum",
]
[[package]]
name = "generic-array"
version = "0.14.4"
@ -800,6 +867,9 @@ name = "hashbrown"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
dependencies = [
"ahash 0.4.7",
]
[[package]]
name = "hashbrown"
@ -807,7 +877,7 @@ version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
dependencies = [
"ahash",
"ahash 0.7.2",
]
[[package]]
@ -831,7 +901,7 @@ dependencies = [
"headers-core",
"http",
"mime",
"sha-1",
"sha-1 0.9.4",
"time",
]
@ -875,7 +945,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15"
dependencies = [
"crypto-mac",
"digest",
"digest 0.9.0",
]
[[package]]
@ -1053,6 +1123,17 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "json5"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d993b17585f39e5e3bd98ff52bbd9e2a6d6b3f5b09d8abcec9d1873fb04cf3f"
dependencies = [
"pest",
"pest_derive",
"serde",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
@ -1142,9 +1223,9 @@ version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b5a279bb9607f9f53c22d496eade00d138d1bdcccd07d74650387cf94942a15"
dependencies = [
"block-buffer",
"digest",
"opaque-debug",
"block-buffer 0.9.0",
"digest 0.9.0",
"opaque-debug 0.3.0",
]
[[package]]
@ -1169,6 +1250,12 @@ dependencies = [
"unicase",
]
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "minspan"
version = "0.1.1"
@ -1215,17 +1302,6 @@ dependencies = [
"twoway",
]
[[package]]
name = "nom"
version = "5.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
dependencies = [
"lexical-core",
"memchr",
"version_check",
]
[[package]]
name = "nom"
version = "6.1.2"
@ -1239,6 +1315,17 @@ dependencies = [
"version_check",
]
[[package]]
name = "nom"
version = "7.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1d11e1ef389c76fe5b81bcaf2ea32cf88b62bc494e19f493d0b30e7a930109"
dependencies = [
"memchr",
"minimal-lexical",
"version_check",
]
[[package]]
name = "ntapi"
version = "0.3.6"
@ -1259,7 +1346,7 @@ dependencies = [
"num-integer",
"num-iter",
"num-rational",
"num-traits 0.2.14",
"num-traits",
]
[[package]]
@ -1270,7 +1357,7 @@ checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304"
dependencies = [
"autocfg",
"num-integer",
"num-traits 0.2.14",
"num-traits",
]
[[package]]
@ -1280,7 +1367,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6b19411a9719e753aff12e5187b74d60d3dc449ec3f4dc21e3989c3f554bc95"
dependencies = [
"autocfg",
"num-traits 0.2.14",
"num-traits",
]
[[package]]
@ -1290,7 +1377,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
dependencies = [
"autocfg",
"num-traits 0.2.14",
"num-traits",
]
[[package]]
@ -1301,7 +1388,7 @@ checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59"
dependencies = [
"autocfg",
"num-integer",
"num-traits 0.2.14",
"num-traits",
]
[[package]]
@ -1313,16 +1400,7 @@ dependencies = [
"autocfg",
"num-bigint",
"num-integer",
"num-traits 0.2.14",
]
[[package]]
name = "num-traits"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
dependencies = [
"num-traits 0.2.14",
"num-traits",
]
[[package]]
@ -1362,12 +1440,28 @@ version = "1.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3"
[[package]]
name = "opaque-debug"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
[[package]]
name = "opaque-debug"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "ordered-multimap"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c672c7ad9ec066e428c00eb917124a06f08db19e2584de982cc34b1f4c12485"
dependencies = [
"dlv-list",
"hashbrown 0.9.1",
]
[[package]]
name = "parking_lot"
version = "0.11.1"
@ -1410,6 +1504,49 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "pest"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53"
dependencies = [
"ucd-trie",
]
[[package]]
name = "pest_derive"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0"
dependencies = [
"pest",
"pest_generator",
]
[[package]]
name = "pest_generator"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55"
dependencies = [
"pest",
"pest_meta",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "pest_meta"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d"
dependencies = [
"maplit",
"pest",
"sha-1 0.8.2",
]
[[package]]
name = "pin-project"
version = "1.0.7"
@ -1744,7 +1881,7 @@ dependencies = [
"percent-encoding",
"pin-project-lite",
"rustls",
"serde 1.0.126",
"serde",
"serde_json",
"serde_urlencoded",
"tokio",
@ -1779,7 +1916,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f55e5fa1446c4d5dd1f5daeed2a4fe193071771a2636274d0d7a3b082aa7ad6"
dependencies = [
"byteorder",
"num-traits 0.2.14",
"num-traits",
]
[[package]]
@ -1790,7 +1927,18 @@ checksum = "723ecff9ad04f4ad92fe1c8ca6c20d2196d9286e9c60727c4cb5511629260e9d"
dependencies = [
"byteorder",
"rmp",
"serde 1.0.126",
"serde",
]
[[package]]
name = "ron"
version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86018df177b1beef6c7c8ef949969c4f7cb9a9344181b92486b23c79995bdaa4"
dependencies = [
"base64",
"bitflags",
"serde",
]
[[package]]
@ -1808,9 +1956,13 @@ dependencies = [
[[package]]
name = "rust-ini"
version = "0.13.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2"
checksum = "63471c4aa97a1cf8332a5f97709a79a4234698de6a1f5087faf66f2dae810e22"
dependencies = [
"cfg-if",
"ordered-multimap",
]
[[package]]
name = "rustc-serialize"
@ -1871,12 +2023,6 @@ dependencies = [
"untrusted",
]
[[package]]
name = "serde"
version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8"
[[package]]
name = "serde"
version = "1.0.126"
@ -1886,18 +2032,6 @@ dependencies = [
"serde_derive",
]
[[package]]
name = "serde-hjson"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a3a4e0ea8a88553209f6cc6cfe8724ecad22e1acf372793c27d995290fe74f8"
dependencies = [
"lazy_static",
"num-traits 0.1.43",
"regex",
"serde 0.8.23",
]
[[package]]
name = "serde_derive"
version = "1.0.126"
@ -1917,7 +2051,7 @@ checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79"
dependencies = [
"itoa",
"ryu",
"serde 1.0.126",
"serde",
]
[[package]]
@ -1929,7 +2063,19 @@ dependencies = [
"form_urlencoded",
"itoa",
"ryu",
"serde 1.0.126",
"serde",
]
[[package]]
name = "sha-1"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df"
dependencies = [
"block-buffer 0.7.3",
"digest 0.8.1",
"fake-simd",
"opaque-debug 0.2.3",
]
[[package]]
@ -1938,11 +2084,11 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfebf75d25bd900fd1e7d11501efab59bc846dbc76196839663e6637bba9f25f"
dependencies = [
"block-buffer",
"block-buffer 0.9.0",
"cfg-if",
"cpuid-bool",
"digest",
"opaque-debug",
"digest 0.9.0",
"opaque-debug 0.3.0",
]
[[package]]
@ -1951,11 +2097,11 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa827a14b29ab7f44778d14a88d3cb76e949c45083f7dbfa507d0cb699dc12de"
dependencies = [
"block-buffer",
"block-buffer 0.9.0",
"cfg-if",
"cpuid-bool",
"digest",
"opaque-debug",
"digest 0.9.0",
"opaque-debug 0.3.0",
]
[[package]]
@ -2006,7 +2152,7 @@ checksum = "7038b67c941e23501573cb7242ffb08709abe9b11eb74bceff875bbda024a6a8"
dependencies = [
"libc",
"libsodium-sys",
"serde 1.0.126",
"serde",
]
[[package]]
@ -2044,7 +2190,7 @@ version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f23af36748ec8ea8d49ef8499839907be41b0b1178a4e82b8cb45d29f531dc9"
dependencies = [
"ahash",
"ahash 0.7.2",
"atoi",
"base64",
"bitflags",
@ -2074,9 +2220,9 @@ dependencies = [
"percent-encoding",
"rand 0.8.4",
"rustls",
"serde 1.0.126",
"serde",
"serde_json",
"sha-1",
"sha-1 0.9.4",
"sha2",
"smallvec",
"sqlformat",
@ -2398,7 +2544,7 @@ version = "0.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
dependencies = [
"serde 1.0.126",
"serde",
]
[[package]]
@ -2461,7 +2607,7 @@ dependencies = [
"input_buffer",
"log",
"rand 0.8.4",
"sha-1",
"sha-1 0.9.4",
"url",
"utf-8",
]
@ -2481,6 +2627,12 @@ version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06"
[[package]]
name = "ucd-trie"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
[[package]]
name = "unicase"
version = "2.6.0"
@ -2617,7 +2769,7 @@ dependencies = [
"percent-encoding",
"pin-project",
"scoped-tls",
"serde 1.0.126",
"serde",
"serde_json",
"serde_urlencoded",
"tokio",

View File

@ -51,9 +51,11 @@ pub struct Settings {
pub key_path: String,
pub session_path: String,
pub search_mode: SearchMode,
// This is automatically loaded when settings is created. Do not set in
// config! Keep secrets and settings apart.
pub session_token: String,
#[serde(skip)]
pub session_token: Option<String>,
}
impl Settings {
@ -120,24 +122,22 @@ impl Settings {
config_file.push("config.toml");
let mut s = Config::default();
let db_path = data_dir.join("history.db");
let key_path = data_dir.join("key");
let session_path = data_dir.join("session");
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", "1h")?;
s.set_default("sync_address", "https://api.atuin.sh")?;
s.set_default("search_mode", "prefix")?;
let mut s = Config::builder()
.set_default("db_path", db_path.to_str())?
.set_default("key_path", key_path.to_str())?
.set_default("session_path", session_path.to_str())?
.set_default("dialect", "us")?
.set_default("auto_sync", true)?
.set_default("sync_frequency", "1h")?
.set_default("sync_address", "https://api.atuin.sh")?
.set_default("search_mode", "prefix")?;
if config_file.exists() {
s.merge(ConfigFile::with_name(config_file.to_str().unwrap()))
.wrap_err_with(|| format!("could not load config file {:?}", config_file))?;
s = s.add_source(ConfigFile::with_name(config_file.to_str().unwrap()));
} else {
let example_config = include_bytes!("../config.toml");
let mut file = File::create(config_file).wrap_err("could not create config file")?;
@ -145,31 +145,27 @@ impl Settings {
.wrap_err("could not write default config file")?;
}
s.merge(Environment::with_prefix("atuin").separator("_"))
.wrap_err("could not load environment")?;
s = s.add_source(Environment::with_prefix("atuin").separator("_"));
let mut settings: Self = s
.build()
.wrap_err("could not process config builder")?
.try_into()
.map_err(|e| eyre!("failed to deserialize: {}", e))?;
// all paths should be expanded
let db_path = s.get_string("db_path")?;
let db_path = shellexpand::full(db_path.as_str())?;
s.set("db_path", db_path.to_string())?;
let key_path = s.get_string("key_path")?;
let key_path = shellexpand::full(key_path.as_str())?;
s.set("key_path", key_path.to_string())?;
let session_path = s.get_string("session_path")?;
let session_path = shellexpand::full(session_path.as_str())?;
s.set("session_path", session_path.to_string())?;
settings.db_path = shellexpand::full(&settings.db_path)?.into_owned();
settings.key_path = shellexpand::full(&settings.key_path)?.into_owned();
settings.session_path = shellexpand::full(&settings.session_path)?.into_owned();
// 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("session_token", token.trim())?;
if Path::new(&settings.session_path).exists() {
let token = std::fs::read_to_string(&settings.session_path)?;
settings.session_token = Some(token.trim().to_owned());
} else {
s.set("session_token", "not logged in")?;
settings.session_token = None;
}
s.try_into()
.map_err(|e| eyre!("failed to deserialize: {}", e))
Ok(settings)
}
}

View File

@ -1,7 +1,7 @@
use std::convert::TryInto;
use chrono::prelude::*;
use eyre::Result;
use eyre::{eyre, Result};
use atuin_common::{api::AddHistoryRequest, utils::hash_str};
@ -133,7 +133,7 @@ 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.sync_address,
&settings.session_token,
settings.session_token.as_ref().ok_or_else(|| eyre!("not logged in"))?,
load_encoded_key(settings)?,
)?;

View File

@ -3,7 +3,7 @@ use std::io::prelude::*;
use std::path::PathBuf;
use config::{Config, Environment, File as ConfigFile};
use eyre::{eyre, Result};
use eyre::{Context, Result};
pub const HISTORY_PAGE_SIZE: i64 = 100;
@ -34,24 +34,26 @@ impl Settings {
// create the config file if it does not exist
let mut s = Config::default();
let mut s = Config::builder();
if config_file.exists() {
s.merge(ConfigFile::with_name(config_file.to_str().unwrap()))?;
s = s.add_source(ConfigFile::with_name(config_file.to_str().unwrap()));
} else {
let example_config = include_bytes!("../server.toml");
let mut file = File::create(config_file)?;
file.write_all(example_config)?;
}
s.set_default("host", "127.0.0.1")?;
s.set_default("port", 8888)?;
s.set_default("open_registration", false)?;
s.set_default("db_uri", "default_uri")?;
let s = s
.set_default("host", "127.0.0.1")?
.set_default("port", 8888)?
.set_default("open_registration", false)?
.set_default("db_uri", "default_uri")?
.add_source(Environment::with_prefix("atuin").separator("_"));
s.merge(Environment::with_prefix("atuin").separator("_"))?;
s.try_into()
.map_err(|e| eyre!("failed to deserialize: {}", e))
s.build()
.wrap_err("failed to create config parser")?
.try_into()
.wrap_err("failed to deserialize")
}
}