From 2a417fce37a929017f5f479e65d9064693ee9ad6 Mon Sep 17 00:00:00 2001 From: Teo Stocco Date: Thu, 10 Aug 2023 21:55:39 +0200 Subject: [PATCH] feat: fix lade on for bash (#44) * fix: bash compat improved * feat: upgrade deps * chore: release 0.8.1 * chore: fix --- .github/dependabot.yml | 8 ++++++++ .github/release.yml | 18 ++++++++++++++++++ Cargo.toml | 12 ++++++------ README.md | 15 +++------------ installer.sh | 17 ++++++++++------- scripts/bash-preexec.sh | 32 +++++++++++++++++++++----------- sdk/Cargo.toml | 10 +++++----- sdk/src/providers/onepassword.rs | 9 ++++++++- src/shell.rs | 6 +++++- 9 files changed, 84 insertions(+), 43 deletions(-) create mode 100644 .github/release.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 25306e1..9ffff71 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,7 +4,15 @@ updates: directory: / schedule: interval: monthly + groups: + deps: + patterns: + - "*" - package-ecosystem: cargo directory: / schedule: interval: monthly + groups: + deps: + patterns: + - "*" diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..13367f1 --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,18 @@ +changelog: + exclude: + authors: + - octocat + - dependabot + categories: + - title: Breaking changes 🛠 + labels: + - breaking-change + - title: Documentation improvements 📖 + labels: + - documentation + - title: Bug fixes 🐛 + labels: + - bug + - title: New features 🎉 + labels: + - "*" diff --git a/Cargo.toml b/Cargo.toml index 46d3a94..6232aac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ resolver = "2" [package] name = "lade" -version = "0.8.1-beta.1" +version = "0.8.1" 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" @@ -20,16 +20,16 @@ self_update = { version = "0.37.0", features = [ "compression-zip-deflate", "compression-zip-bzip2", ] } -serde = { version = "1.0.180", features = ["derive"] } +serde = { version = "1.0.183", features = ["derive"] } serde_yaml = "0.9.25" -clap = { version = "4.3.19", features = ["derive"] } -regex = "1.9.1" -lade-sdk = { path = "./sdk", version = "0.8.1-beta.1" } +clap = { version = "4.3.21", features = ["derive"] } +regex = "1.9.3" +lade-sdk = { path = "./sdk", version = "0.8.1" } tokio = { version = "1", features = ["full"] } indexmap = { version = "2.0.0", features = ["serde"] } clap-verbosity-flag = "2.0.1" env_logger = "0.10.0" -openssl = { version = "0.10.55", features = ["vendored"] } +openssl = { version = "0.10.56", features = ["vendored"] } serde_json = "1.0.104" futures = "0.3.28" path-clean = "1.0.1" diff --git a/README.md b/README.md index 5f34ba1..d0193d4 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,8 @@ cargo install --git https://github.com/zifeo/lade --locked # upgrade lade upgrade -# install/uninstall shell auto launch (only required once, see below) +# install shell hooks (only required once) lade install -lade uninstall ``` Compatible shells: [Fish](https://fishshell.com), @@ -53,19 +52,11 @@ using a regex and load them into environment variables or files for the time of the run. ```bash -eval "$(lade on)" - -cd examples/terraform terraform apply - +cd examples/terraform +terraform apply # example = "hello world" - -eval "$(lade off)" ``` -You can also add `eval "$(lade on)"` to your shell configuration file (e.g. -`~/.bashrc`, `~/.zshrc` or `~/.config/fish/config.fish`) to automatically enable -Lade on each shell session (`lade install` will configure this for you). - See [lade.yml](lade.yml) or the [examples](./examples) folders for other uses cases. diff --git a/installer.sh b/installer.sh index 43016e0..e6efdea 100755 --- a/installer.sh +++ b/installer.sh @@ -15,6 +15,7 @@ LATEST_VERSION=$(curl "$RELEASE_URL/latest" -s -L -I -o /dev/null -w '%{url_effe LATEST_VERSION="${LATEST_VERSION##*v}" PLATFORM="${PLATFORM:-}" +TMP_DIR=$(mktemp -d) OUT_DIR="${OUT_DIR:-/usr/local/bin}" VERSION="${VERSION:-$LATEST_VERSION}" MACHINE=$(uname -m) @@ -64,7 +65,7 @@ printf "Detected version: %s\n" "$VERSION" ASSET="$NAME-v$VERSION-$PLATFORM" DOWNLOAD_URL="$RELEASE_URL/download/v$VERSION/$ASSET.$EXT" -if curl --fail --silent --location --output "$ASSET.$EXT" "$DOWNLOAD_URL"; then +if curl --fail --silent --location --output "$TMP_DIR/$ASSET.$EXT" "$DOWNLOAD_URL"; then printf "Downloaded successfully: %s\n" "$ASSET.$EXT" else cat >&2 < 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 1) )); then + PROMPT_COMMAND+=('__bp_interactive_mode') + else + # shellcheck disable=SC2179 # PROMPT_COMMAND is not an array in bash <= 5.0 + PROMPT_COMMAND+=$'\n__bp_interactive_mode' + fi # Add two functions to our arrays for convenience # of definition. @@ -359,8 +367,10 @@ __bp_install_after_session_init() { local sanitized_prompt_command __bp_sanitize_string sanitized_prompt_command "${PROMPT_COMMAND:-}" if [[ -n "$sanitized_prompt_command" ]]; then + # shellcheck disable=SC2178 # PROMPT_COMMAND is not an array in bash <= 5.0 PROMPT_COMMAND=${sanitized_prompt_command}$'\n' fi; + # shellcheck disable=SC2179 # PROMPT_COMMAND is not an array in bash <= 5.0 PROMPT_COMMAND+=${__bp_install_string} } diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index e4513f1..0fa6b41 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lade-sdk" -version = "0.8.1-beta.1" +version = "0.8.1" edition = "2021" description = "Lade SDK" license = "MPL-2.0" @@ -15,12 +15,12 @@ futures = "0.3.28" itertools = "0.11.0" log = "0.4.19" once_cell = "1.18.0" -regex = "1.9.1" +regex = "1.9.3" rust-ini = "0.19.0" -serde = { version = "1.0.180", features = ["derive"] } +serde = { version = "1.0.183", features = ["derive"] } serde_json = "1.0.104" serde_yaml = "0.9.25" -tempfile = "3.7.0" -tokio = { version = "1.29.1", features = ["fs"] } +tempfile = "3.7.1" +tokio = { version = "1.30.0", features = ["fs"] } toml = "0.7.6" url = "2.4.0" diff --git a/sdk/src/providers/onepassword.rs b/sdk/src/providers/onepassword.rs index 3f71d42..4c50687 100644 --- a/sdk/src/providers/onepassword.rs +++ b/sdk/src/providers/onepassword.rs @@ -89,7 +89,14 @@ impl Provider for OnePassword { let loaded = serde_json::from_slice::(&child.stdout).map_err(|err| { let stderr = String::from_utf8_lossy(&child.stderr); - anyhow!("1Password error: {err} (stderr: {stderr})",) + if stderr.contains("could not resolve item UUID") { + anyhow!( + "One item does not seem to exist in the vault: {stderr}", + ) + } else { + anyhow!("1Password error: {err} (stderr: {stderr})",) + } + })?; let hydration = vars diff --git a/src/shell.rs b/src/shell.rs index 38ef499..af9bfb7 100644 --- a/src/shell.rs +++ b/src/shell.rs @@ -101,7 +101,11 @@ impl Shell { let user = directories::UserDirs::new().expect("cannot get HOME location"); let home_dir = user.home_dir(); let curr_exe = std::env::current_exe().expect("cannot get current executable path"); - let command = format!("eval \"$({} on)\"", curr_exe.display()); + let command = match self { + Shell::Bash => format!("source <(echo \"$({} on)\")", curr_exe.display()), + Shell::Zsh => format!("eval \"$({} on)\"", curr_exe.display()), + Shell::Fish => format!("eval \"$({} on)\"", curr_exe.display()), + }; let marker = "lade-do-not-edit".to_string(); let config_file = match self { Shell::Bash => home_dir.join(".bashrc"),