-
Notifications
You must be signed in to change notification settings - Fork 489
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
367 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
TEST_API_KEY=test value | ||
TEST_API_CLIENT_ID=client1 |
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
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
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
pub mod metadata; | ||
pub mod config; | ||
pub mod secret; | ||
mod render; | ||
|
||
pub use render::render_config_str; |
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,83 @@ | ||
use std::collections::HashMap; | ||
|
||
use serde::Serialize; | ||
use minijinja::value::Value; | ||
|
||
use crate::{secret::SecretStore, config::ConnectorConfig}; | ||
|
||
/// Context for the template engine | ||
/// This is the data that is available to the template engine | ||
/// when it is rendering the template. | ||
#[derive(Serialize, Default)] | ||
pub(crate) struct Context(pub(crate) HashMap<&'static str, Value>); | ||
|
||
/// ContextStore is a trait that allows for adding additional | ||
/// context to the template engine. | ||
pub(crate) trait ContextStore { | ||
/// values to add to the context | ||
fn extract_context_values(&self, input: &str) -> anyhow::Result<Value>; | ||
/// key name for the context | ||
fn context_name(&self) -> &'static str; | ||
} | ||
impl dyn ContextStore { | ||
pub(crate) fn add_to_context(&self, context: &mut Context, input: &str) -> anyhow::Result<()> { | ||
let value = self.extract_context_values(input)?; | ||
|
||
context.0.insert(self.context_name(), value); | ||
Ok(()) | ||
} | ||
} | ||
impl ContextStore for &dyn SecretStore { | ||
fn extract_context_values(&self, input: &str) -> anyhow::Result<Value> { | ||
let connector_config: ConnectorConfig = serde_yaml::from_reader(input.as_bytes())?; | ||
let mut values = HashMap::default(); | ||
|
||
for secret in connector_config.secrets().iter() { | ||
let secret_value = self.read(secret.name())?; | ||
values.insert(secret.name().to_owned(), secret_value); | ||
} | ||
Ok(values.into()) | ||
} | ||
|
||
fn context_name(&self) -> &'static str { | ||
"secrets" | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
|
||
use minijinja::value::Value; | ||
|
||
use super::ContextStore; | ||
|
||
pub struct TestStore; | ||
|
||
impl ContextStore for TestStore { | ||
fn extract_context_values(&self, _input: &str) -> anyhow::Result<Value> { | ||
Ok([("test", "value")].into_iter().collect()) | ||
} | ||
|
||
fn context_name(&self) -> &'static str { | ||
"test" | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_context_store() { | ||
let store = &TestStore as &dyn ContextStore; | ||
let mut context = super::Context::default(); | ||
store.add_to_context(&mut context, "").unwrap(); | ||
assert_eq!( | ||
context | ||
.0 | ||
.get("test") | ||
.unwrap() | ||
.get_attr("test") | ||
.unwrap() | ||
.as_str() | ||
.unwrap(), | ||
"value" | ||
); | ||
} | ||
} |
Oops, something went wrong.