Skip to content

Commit 374380a

Browse files
committed
move render_strict helper to lib module
Signed-off-by: Robert Detjens <[email protected]>
1 parent 45c7ba7 commit 374380a

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

src/access_handlers/docker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use minijinja;
1010
use tokio;
1111
use tracing::{debug, error, info, trace, warn};
1212

13-
use crate::clients::{docker, render_strict};
1413
use crate::configparser::{get_config, get_profile_config};
14+
use crate::{clients::docker, utils::render_strict};
1515

1616
/// container registry / daemon access checks
1717
#[tokio::main(flavor = "current_thread")] // make this a sync function

src/clients.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,3 @@ pub async fn wait_for_status(client: &kube::Client, object: &DynamicObject) -> R
345345

346346
Ok(())
347347
}
348-
349-
//
350-
// Minijinja strict rendering with error
351-
//
352-
353-
/// Similar to minijinja.render!(), but return Error if any undefined values.
354-
pub fn render_strict(template: &str, context: minijinja::Value) -> Result<String> {
355-
let mut strict_env = minijinja::Environment::new();
356-
// error on any undefined template variables
357-
strict_env.set_undefined_behavior(minijinja::UndefinedBehavior::Strict);
358-
359-
let r = strict_env
360-
.render_str(template, context)
361-
.context(format!("could not render template {:?}", template))?;
362-
Ok(r)
363-
}

src/configparser/challenge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use std::str::FromStr;
1212
use tracing::{debug, error, info, trace, warn};
1313
use void::Void;
1414

15-
use crate::clients::render_strict;
1615
use crate::configparser::config::Resource;
1716
use crate::configparser::field_coersion::string_or_struct;
1817
use crate::configparser::get_config;
18+
use crate::utils::render_strict;
1919

2020
pub fn parse_all() -> Result<Vec<ChallengeConfig>, Vec<Error>> {
2121
// find all challenge.yaml files

src/utils/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::{Context, Result};
12
use futures::{future::try_join_all, TryFuture};
23

34
/// Helper trait for `Iterator` to add futures::try_await_all() as chain method.
@@ -26,3 +27,19 @@ where
2627
try_join_all(self).await
2728
}
2829
}
30+
31+
//
32+
// Minijinja strict rendering with error
33+
//
34+
35+
/// Similar to minijinja.render!(), but return Error if any undefined values.
36+
pub fn render_strict(template: &str, context: minijinja::Value) -> Result<String> {
37+
let mut strict_env = minijinja::Environment::new();
38+
// error on any undefined template variables
39+
strict_env.set_undefined_behavior(minijinja::UndefinedBehavior::Strict);
40+
41+
let r = strict_env
42+
.render_str(template, context)
43+
.context(format!("could not render template {:?}", template))?;
44+
Ok(r)
45+
}

0 commit comments

Comments
 (0)