Skip to content

Commit

Permalink
feat: manual injection (#51)
Browse files Browse the repository at this point in the history
* feat: fix bash

* feat: write with abs path

* feat: manual injection

* feat: upgrade
  • Loading branch information
zifeo authored Oct 2, 2023
1 parent 44cdd9c commit 9d1e7cc
Show file tree
Hide file tree
Showing 8 changed files with 199 additions and 98 deletions.
26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@ resolver = "2"

[package]
name = "lade"
version = "0.8.2-beta.1"
version = "0.9.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.72"
anyhow = "1.0.75"
self_update = { version = "0.38.0", features = [
"archive-tar",
"archive-zip",
"compression-flate2",
"compression-zip-deflate",
"compression-zip-bzip2",
] }
serde = { version = "1.0.183", features = ["derive"] }
serde = { version = "1.0.188", features = ["derive"] }
serde_yaml = "0.9.25"
clap = { version = "4.3.21", features = ["derive"] }
regex = "1.9.3"
lade-sdk = { path = "./sdk", version = "0.8.2-beta.1" }
clap = { version = "4.4.6", features = ["derive"] }
regex = "1.9.6"
lade-sdk = { path = "./sdk", version = "0.9.0" }
tokio = { version = "1", features = ["full"] }
indexmap = { version = "2.0.0", features = ["serde"] }
indexmap = { version = "2.0.2", features = ["serde"] }
clap-verbosity-flag = "2.0.1"
env_logger = "0.10.0"
openssl = { version = "0.10.56", features = ["vendored"] }
serde_json = "1.0.104"
openssl = { version = "0.10.57", features = ["vendored"] }
serde_json = "1.0.107"
futures = "0.3.28"
path-clean = "1.0.1"
directories = "5.0.1"
chrono = { version = "0.4.26", features = ["serde"] }
log = "0.4.19"
semver = "1.0.18"
sysinfo = "0.29.7"
chrono = { version = "0.4.31", features = ["serde"] }
log = "0.4.20"
semver = "1.0.19"
sysinfo = "0.29.10"
textwrap = "0.16.0"

[dev-dependencies]
Expand Down
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ Compatible vaults: [Infisical](https://infisical.com),

## Usage

Lade will run before and after any command you run in your shell. On each run,
it will recursively look for `lade.yml` files in the current directory and its
parents. It will then aggregate any secrets matching the command you are running
using a regex and load them into environment variables or files for the time of
the run.
Lade will run before and after any command you run in your shell thanks to
command hooks installed by `lade install`. On each run, it will recursively look
for `lade.yml` files in the current directory and its parents. It will then
aggregate any secrets matching the command you are running using a regex and
load them into environment variables or files for the time of the run.

```bash
cd examples/terraform
Expand All @@ -60,6 +60,19 @@ terraform apply
See [lade.yml](lade.yml) or the [examples](./examples) folders for other uses
cases.

### Manual injections

In case you prefer to decide when to load secrets, you can manually decide when
to inject them using the `inject` command. Note that when running scripts or a
non-interactive shell session, there is no guarantee that the shell hooks will
be triggered. In that case, the `inject` command is the only way to load
secrets.

```bash
cd examples/terraform
lade inject terraform apply
```

### Outputting as files

By default, Lade will load secrets into environment variables. You can change
Expand Down
3 changes: 3 additions & 0 deletions lade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@
.: a.yaml
A1: "1"

^printenv:
SHELL: "overriden"

^echo z:
DEBUG: "true"
20 changes: 10 additions & 10 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
[package]
name = "lade-sdk"
version = "0.8.2-beta.1"
version = "0.9.0"
edition = "2021"
description = "Lade SDK"
license = "MPL-2.0"

[dependencies]
access-json = "0.1.0"
anyhow = "1.0.72"
anyhow = "1.0.75"
async-process = "1.7.0"
async-trait = "0.1.72"
async-trait = "0.1.73"
directories = "5.0.1"
futures = "0.3.28"
itertools = "0.11.0"
log = "0.4.19"
log = "0.4.20"
once_cell = "1.18.0"
regex = "1.9.3"
regex = "1.9.6"
rust-ini = "0.19.0"
serde = { version = "1.0.183", features = ["derive"] }
serde_json = "1.0.104"
serde = { version = "1.0.188", features = ["derive"] }
serde_json = "1.0.107"
serde_yaml = "0.9.25"
tempfile = "3.7.1"
tokio = { version = "1.30.0", features = ["fs"] }
tempfile = "3.8.0"
tokio = { version = "1.32.0", features = ["fs"] }
toml = "0.8.1"
url = "2.4.0"
url = "2.4.1"
2 changes: 2 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub enum Command {
Install,
/// Uninstall auto launcher in shell profile.
Uninstall,
/// Inject environment into nested command.
Inject(EvalCommand),
/// Set environment for shell.
Set(EvalCommand),
/// Unset environment for shell.
Expand Down
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ pub struct Config {
}

impl Config {
fn collect(&self, command: String) -> Vec<(PathBuf, LadeRule)> {
fn collect(&self, command: &str) -> Vec<(PathBuf, LadeRule)> {
self.matches
.clone()
.into_iter()
.filter(|(regex, _, _)| regex.is_match(&command))
.filter(|(regex, _, _)| regex.is_match(command))
.map(|(_, path, env)| (path, env))
.collect()
}
Expand All @@ -99,7 +99,7 @@ impl Config {

pub async fn collect_hydrate(
&self,
command: String,
command: &str,
) -> Result<HashMap<Output, HashMap<String, String>>> {
let ret = try_join_all(
self.collect(command)
Expand All @@ -117,7 +117,7 @@ impl Config {
Ok(ret)
}

pub fn collect_keys(&self, command: String) -> HashMap<Output, Vec<String>> {
pub fn collect_keys(&self, command: &str) -> HashMap<Output, Vec<String>> {
self.collect(command)
.into_iter()
.map(|(_, env)| (env.output, env.secrets.keys().cloned().collect::<Vec<_>>()))
Expand Down
Loading

0 comments on commit 9d1e7cc

Please sign in to comment.