2 Commits

Author SHA1 Message Date
Dreaded_X 003b28a841 feat: Add function that applies netmask to ip
Committed / committed (pull_request) Successful in 46s
CI / prek (pull_request) Has been cancelled
CI / cargo shear (pull_request) Has been cancelled
2026-04-21 04:46:31 +02:00
Dreaded_X 108db75dc9 refactor: Use ViaDeserialize to convert ip address 2026-04-21 04:43:18 +02:00
4 changed files with 13 additions and 14 deletions
-7
View File
@@ -7,13 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [0.1.2](https://git.huizinga.dev/infra/crete/compare/v0.1.1...v0.1.2) - 2026-04-17
### <!-- 0 -->Features
- Make dns optional
- Allow more than two dns entries
## [0.1.1](https://git.huizinga.dev/infra/crete/compare/v0.1.0...v0.1.1) - 2026-04-13
### <!-- 2 -->Bug Fixes
Generated
+1 -1
View File
@@ -214,7 +214,7 @@ dependencies = [
[[package]]
name = "crete"
version = "0.1.2"
version = "0.1.1"
dependencies = [
"clap",
"clap_complete",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "crete"
version = "0.1.2"
version = "0.1.1"
edition = "2024"
default-run = "crete"
publish = ["infra"]
+11 -5
View File
@@ -1,8 +1,8 @@
use std::net::Ipv4Addr;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use minijinja::value::ViaDeserialize;
use minijinja::{AutoEscape, Environment, path_loader};
use walkdir::WalkDir;
@@ -16,6 +16,13 @@ pub struct PathEnvironment<'a> {
path: PathBuf,
}
fn apply_netmask(
ip: ViaDeserialize<Ipv4Addr>,
netmask: ViaDeserialize<Ipv4Addr>,
) -> Result<String, minijinja::Error> {
Ok((*ip & *netmask).to_string())
}
impl<'a> PathEnvironment<'a> {
pub fn new(path: &Path) -> Self {
let mut env = Environment::new();
@@ -27,10 +34,7 @@ impl<'a> PathEnvironment<'a> {
env.set_auto_escape_callback(|_| AutoEscape::None);
// Add filters
env.add_filter("to_prefix", |netmask: String| {
let netmask = Ipv4Addr::from_str(&netmask).map_err(|err| {
minijinja::Error::new(minijinja::ErrorKind::InvalidOperation, err.to_string())
})?;
env.add_filter("to_prefix", |netmask: ViaDeserialize<Ipv4Addr>| {
let mask = netmask.to_bits();
let prefix = mask.leading_ones();
@@ -44,6 +48,8 @@ impl<'a> PathEnvironment<'a> {
}
});
env.add_function("apply_netmask", apply_netmask);
// Helper function for getting the path to kubeconfig files
env.add_filter("kubeconfig", move |names: Vec<String>| {
names