-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lookup): Add find reusing module logic
Resolves #22. Signed-off-by: Alexander Gil <[email protected]>
- Loading branch information
Showing
8 changed files
with
109 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/// ANCHOR: lookup | ||
/// # find | ||
/// | ||
/// Use [find module](./module_find.html) as a lookup. Returns the extra field of the module result. | ||
/// | ||
/// ANCHOR_END: lookup | ||
/// ANCHOR: examples | ||
/// ## Example | ||
/// | ||
/// ```yaml | ||
/// - debug: | ||
/// msg: "{{ find(paths='/') }}" | ||
/// ``` | ||
/// ANCHOR_END: examples | ||
use crate::jinja::lookup::utils::to_minijinja_error; | ||
use crate::modules::find::find; | ||
use crate::modules::parse_params; | ||
|
||
use std::result::Result as StdResult; | ||
|
||
use minijinja::{Error as MinijinjaError, Value}; | ||
|
||
pub fn function(config: Value) -> StdResult<Value, MinijinjaError> { | ||
parse_params(serde_yaml::to_value(config).map_err(to_minijinja_error)?) | ||
.map_err(to_minijinja_error) | ||
.and_then(|params| { | ||
Ok(find(params) | ||
.map_err(to_minijinja_error) | ||
.map(|x| serde_yaml::to_value(x.get_extra())) | ||
.map_err(to_minijinja_error)? | ||
.map(Value::from_serialize)) | ||
}) | ||
.map_err(to_minijinja_error)? | ||
.map_err(to_minijinja_error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
mod find; | ||
#[cfg(feature = "passwordstore")] | ||
mod passwordstore; | ||
|
||
mod utils; | ||
|
||
use rash_derive::generate_lookup_functions; | ||
|
||
generate_lookup_functions!(passwordstore); | ||
generate_lookup_functions!((find, false), (passwordstore, true),); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
use minijinja::{Error as MinijinjaError, ErrorKind as MinijinjaErrorKind}; | ||
|
||
pub fn to_minijinja_error<E: std::fmt::Display>(err: E) -> MinijinjaError { | ||
MinijinjaError::new(MinijinjaErrorKind::InvalidOperation, err.to_string()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters