From 972466c760437a09ed3ca3ca9abc1c9f3b392b01 Mon Sep 17 00:00:00 2001 From: Teo Stocco Date: Fri, 8 Mar 2024 19:12:20 +0100 Subject: [PATCH] feat: newline and 1p file support (#67) * feat: newline and 1p file support * chore: bump 0.10.0 --- Cargo.toml | 34 ++++++++++++++++---------------- lade.yml | 9 +++++++-- scripts/on.bash | 11 +++++------ scripts/on.fish | 4 ++-- scripts/on.zsh | 13 ++++++------ sdk/Cargo.toml | 18 ++++++++--------- sdk/src/providers/onepassword.rs | 3 ++- src/main.rs | 4 ++-- 8 files changed, 50 insertions(+), 46 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9bee34b..61b3e87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,13 +6,13 @@ resolver = "2" [package] name = "lade" -version = "0.9.2-beta.1" +version = "0.10.0" edition = "2021" description = "Automatically load secrets from your preferred vault as environment variables, and clear them once your shell command is over." license = "MPL-2.0" [dependencies] -anyhow = "1.0.79" +anyhow = "1.0.80" self_update = { version = "0.39.0", features = [ "archive-tar", "archive-zip", @@ -20,25 +20,25 @@ self_update = { version = "0.39.0", features = [ "compression-zip-deflate", "compression-zip-bzip2", ] } -serde = { version = "1.0.196", features = ["derive"] } -serde_yaml = "0.9.31" -clap = { version = "4.4.18", features = ["derive"] } +serde = { version = "1.0.197", features = ["derive"] } +serde_yaml = "0.9.32" +clap = { version = "4.5.2", features = ["derive"] } regex = "1.10.3" -lade-sdk = { path = "./sdk", version = "0.9.2-beta.1" } +lade-sdk = { path = "./sdk", version = "0.10.0" } tokio = { version = "1", features = ["full"] } -indexmap = { version = "2.2.2", features = ["serde"] } -clap-verbosity-flag = "2.1.2" -env_logger = "0.11.1" -openssl = { version = "0.10.63", features = ["vendored"] } -serde_json = "1.0.113" +indexmap = { version = "2.2.5", features = ["serde"] } +clap-verbosity-flag = "2.2.0" +env_logger = "0.11.3" +openssl = { version = "0.10.64", features = ["vendored"] } +serde_json = "1.0.114" futures = "0.3.30" path-clean = "1.0.1" directories = "5.0.1" -chrono = { version = "0.4.33", features = ["serde"] } -log = "0.4.20" -semver = "1.0.21" -sysinfo = "0.30.5" -textwrap = "0.16.0" +chrono = { version = "0.4.35", features = ["serde"] } +log = "0.4.21" +semver = "1.0.22" +sysinfo = "0.30.7" +textwrap = "0.16.1" [dev-dependencies] -assert_cmd = "2.0.13" +assert_cmd = "2.0.14" diff --git a/lade.yml b/lade.yml index 45de40d..9d68c17 100644 --- a/lade.yml +++ b/lade.yml @@ -8,23 +8,28 @@ B1: doppler://api.doppler.com/lade/dev/DOPPLER_A B2: doppler://api.doppler.com/lade/dev/DOPPLER_B B3: doppler://api.doppler.com/lade/prd/DOPPLER_B + B4: doppler://api.doppler.com/lade/dev/MULTILINE ^echo c: - C1: infisical://infisical.exponent.ch/63fd114968d64dec0823ac52/test/STORE_FILE + C1: infisical://app.infisical.com/63a2290a0edf8bf1f65e3784/dev/INFISICAL_A C2: infisical://app.infisical.com/63a2290a0edf8bf1f65e3784/dev/INFISICAL_B C3: infisical://app.infisical.com/63a2290a0edf8bf1f65e3784/prod/INFISICAL_B + C4: infisical://app.infisical.com/63a2290a0edf8bf1f65e3784/dev/MULTILINE ^echo d: D1: op://my.1password.eu/Personal/Lade/username D2: op://my.1password.eu/Personal/Lade/password D3: op://my.1password.eu/Personal/Lade/with space + D4: op://my.1password.eu/Personal/Lade/file ^echo e: - # vault kv put -address=http://127.0.0.1:8200 -mount=secret password value1=itsasecret value2=itsanotsecret + # export VAULT_TOKEN=token + # vault kv put -address=http://127.0.0.1:8200 -mount=secret password value1=itsasecret value2=itsanotsecret multiline="a\nb" # vault kv put -address=http://127.0.0.1:8200 -mount=secret org/team value=secret E1: vault://127.0.0.1:8200/secret/password/value1 E2: vault://127.0.0.1:8200/secret/password/value2 E3: vault://127.0.0.1:8200/secret/org%2Fteam/value + E4: vault://127.0.0.1:8200/secret/password/multiline ^echo f: F1: file://../lade/examples/sources/config.ini?query=.format diff --git a/scripts/on.bash b/scripts/on.bash index 674ef9c..bc69094 100644 --- a/scripts/on.bash +++ b/scripts/on.bash @@ -1,21 +1,20 @@ - -preexec_lade() { +preexec_lade() { if [ "$1" = "source off.bash" ]; then return fi LADE="$1" - eval $(lade set $@) + eval "$(lade set $@)" } preexec_functions+=(preexec_lade) precmd_lade() { if [ -z ${LADE+x} ]; then - return # ensure only runs at postexec + return # ensure only runs at postexec elif [ "$LADE" = "source on.bash" ]; then return - fi - eval $(lade unset $@) + fi + eval "$(lade unset $@)" unset -v LADE } diff --git a/scripts/on.fish b/scripts/on.fish index c8883da..f2a5a06 100644 --- a/scripts/on.fish +++ b/scripts/on.fish @@ -4,7 +4,7 @@ function preexec_lade --on-event fish_preexec return end set --global LADE "$argv" - eval $(lade set $argv) + eval "$(lade set $argv)" end function postexec_lade --on-event fish_postexec @@ -12,6 +12,6 @@ function postexec_lade --on-event fish_postexec if [ "$LADE" = "source on.fish" ] return end - eval $(lade unset $argv) + eval "$(lade unset $argv)" set --global --erase LADE end diff --git a/scripts/on.zsh b/scripts/on.zsh index 0e83f15..171c5ae 100644 --- a/scripts/on.zsh +++ b/scripts/on.zsh @@ -1,29 +1,28 @@ - -preexec_lade() { +preexec_lade() { if [ "$1" = "source off.zsh" ]; then return fi LADE=$1 if [ "$(uname)" = "Darwin" ]; then # bugfix: macOs seems to triple argv - argv=${argv:1:$(( ${#argv[@]} / 3 ))} + argv=${argv:1:$((${#argv[@]} / 3))} fi - eval $(lade set $argv) + eval "$(lade set $argv)" } preexec_functions+=(preexec_lade) precmd_lade() { if [ -z ${LADE+x} ]; then - return # ensure only runs at postexec + return # ensure only runs at postexec elif [ "$LADE" = "source on.zsh" ]; then return fi if [ "$(uname)" = "Darwin" ]; then # bugfix: macOs seems to triple argv - argv=${argv:1:$(( ${#argv[@]} / 3 ))} + argv=${argv:1:$((${#argv[@]} / 3))} fi - eval $(lade unset $argv) + eval "$(lade unset $argv)" unset -v LADE } diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index be9b592..aaf1e2f 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -1,27 +1,27 @@ [package] name = "lade-sdk" -version = "0.9.2-beta.1" +version = "0.10.0" edition = "2021" description = "Lade SDK" license = "MPL-2.0" [dependencies] access-json = "0.1.0" -anyhow = "1.0.79" -async-process = "2.0.1" +anyhow = "1.0.80" +async-process = "2.1.0" async-trait = "0.1.77" directories = "5.0.1" futures = "0.3.30" itertools = "0.12.1" -log = "0.4.20" +log = "0.4.21" once_cell = "1.19.0" regex = "1.10.3" rust-ini = "0.20.0" -serde = { version = "1.0.196", features = ["derive"] } -serde_json = "1.0.113" -serde_yaml = "0.9.31" -tempfile = "3.9.0" +serde = { version = "1.0.197", features = ["derive"] } +serde_json = "1.0.114" +serde_yaml = "0.9.32" +tempfile = "3.10.1" tokio = { version = "1.36.0", features = ["fs"] } -toml = "0.8.9" +toml = "0.8.10" url = "2.5.0" urlencoding = "2.1.3" diff --git a/sdk/src/providers/onepassword.rs b/sdk/src/providers/onepassword.rs index 4f15fc2..140a12a 100644 --- a/sdk/src/providers/onepassword.rs +++ b/sdk/src/providers/onepassword.rs @@ -87,8 +87,9 @@ impl Provider for OnePassword { Ok(child) => child, }; + let output = String::from_utf8_lossy(&child.stdout).trim().replace('\n', "\\n"); let loaded = - serde_json::from_slice::(&child.stdout).map_err(|err| { + serde_json::from_str::(&output).map_err(|err| { let stderr = String::from_utf8_lossy(&child.stderr); if stderr.contains("could not resolve item UUID") { anyhow!( diff --git a/src/main.rs b/src/main.rs index 4f7ecbc..83b9d85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use anyhow::{bail, Ok, Result}; -use chrono::{Duration, Utc}; +use chrono::{TimeDelta, Utc}; use log::{debug, warn}; use self_update::{backends::github::Update, cargo_crate_version, update::UpdateStatus}; use semver::Version; @@ -31,7 +31,7 @@ async fn upgrade_check() -> Result<()> { debug!("config_path: {:?}", config_path); let mut local_config = GlobalConfig::load(config_path.clone()).await?; - if local_config.update_check + Duration::days(1) < Utc::now() { + if local_config.update_check + TimeDelta::try_days(1).unwrap() < Utc::now() { debug!("checking for update"); let current_version = cargo_crate_version!(); let latest = tokio::task::spawn_blocking(move || {