Compare commits

..

2 commits

3 changed files with 19 additions and 6 deletions

7
Cargo.lock generated
View file

@ -2,6 +2,12 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "anyhow"
version = "1.0.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e1496f8fb1fbf272686b8d37f523dab3e4a7443300055e74cdaa449f3114356"
[[package]] [[package]]
name = "block-buffer" name = "block-buffer"
version = "0.10.4" version = "0.10.4"
@ -179,6 +185,7 @@ checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
name = "secrets-file-builder" name = "secrets-file-builder"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow",
"handlebars", "handlebars",
"serde_json", "serde_json",
"url-escape", "url-escape",

View file

@ -9,6 +9,7 @@ repository = "https://git.nwex.de/networkException/secrets-file-builder"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
anyhow = "1.0.88"
handlebars = "5.1.0" handlebars = "5.1.0"
serde_json = "1.0.114" serde_json = "1.0.114"
url-escape = "0.1.1" url-escape = "0.1.1"

View file

@ -1,16 +1,20 @@
use handlebars::{Context, Handlebars, Helper, HelperResult, JsonRender, Output, RenderContext, RenderErrorReason}; use std::env;
use serde_json::{Map, Value};
use std::{env, error::Error};
use std::fs; use std::fs;
use anyhow::Result;
use serde_json::{Map, Value};
use url_escape; use url_escape;
fn main() -> Result<(), Box<dyn Error>> { use handlebars::{Context, Handlebars, Helper, HelperResult, JsonRender, Output, RenderContext, RenderErrorReason};
fn main() -> Result<()> {
let mut handlebars = Handlebars::new(); let mut handlebars = Handlebars::new();
let path_to_contents = env::args().nth(1).expect("The first argument to be present."); let path_to_contents = env::args().nth(1).expect("The first argument to be present.");
let output_path = env::args().nth(2).expect("The second argument to be present."); let output_path = env::args().nth(2).expect("The second argument to be present.");
let contents = fs::read_to_string(path_to_contents).expect("To be able to open a file at the path passed as the first argument."); let contents = fs::read_to_string(path_to_contents).expect("To be able to read the contents file at the path '{path_to_contents}' passed as the first argument.");
let secret_inputs = env::vars().filter(|(key, _)| key.starts_with("SECRET_")); let secret_inputs = env::vars().filter(|(key, _)| key.starts_with("SECRET_"));
@ -21,7 +25,8 @@ fn main() -> Result<(), Box<dyn Error>> {
panic!("Secret environment variable is not in format 'name:path_to_secret'"); panic!("Secret environment variable is not in format 'name:path_to_secret'");
}; };
let secret_value = fs::read_to_string(path_to_secret)?; let secret_value = fs::read_to_string(path_to_secret)
.expect("To be able to read in secret '{secret_key}' from path '{path_to_secret}'");
println!("Registering secret '{secret_key}' from '{path_to_secret}'."); println!("Registering secret '{secret_key}' from '{path_to_secret}'.");