Skip to content

Commit

Permalink
feat(lookup): Add subkey option to passwordstore
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Gil <[email protected]>
  • Loading branch information
pando85 committed Sep 15, 2024
1 parent e1b34a8 commit 69868bf
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions rash_core/src/jinja/lookup/passwordstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
///
/// ## Parameters
///
/// | Parameter | Required | Type | Values | Description |
/// |-----------|----------|---------|--------|-----------------------------------------------------------------------------------------|
/// | returnall | | boolean | | Return all the content of the password, not only the first line. **[default: `false`]** |
/// | Parameter | Required | Type | Values | Description |
/// | --------- | -------- | ------- | ------ | ------------------------------------------------------------------------------------------------------------------------ |
/// | returnall | | boolean | | Return all the content of the password, not only the first line. **[default: `false`]** |
/// | subkey | | string | | Return a specific subkey of the password. When set to password, always returns the first line. **[default: `password`]** |
///
/// ANCHOR_END: lookup
/// ANCHOR: examples
Expand Down Expand Up @@ -49,6 +50,14 @@ pub fn function(path: String, options: Kwargs) -> StdResult<Value, MinijinjaErro
.decrypt_file(&secret.path)
.map_err(to_minijinja_error)?;

if let Some(key) = options.get::<Option<String>>("subkey")? {
if key == "password" {
plaintext = plaintext.first_line().map_err(to_minijinja_error)?;
} else {
plaintext = plaintext.property(&key).map_err(to_minijinja_error)?;
}
};

if Some(true) != options.get("returnall")? {
plaintext = plaintext.first_line().map_err(to_minijinja_error)?;
};
Expand Down

0 comments on commit 69868bf

Please sign in to comment.