add Dockerfile
This commit is contained in:
52
src/main.rs
52
src/main.rs
@@ -2,7 +2,11 @@ use anyhow::{anyhow, Context, Result};
|
||||
use clap::Parser;
|
||||
use encoding::{label::encoding_from_whatwg_label, EncoderTrap};
|
||||
use regex::Regex;
|
||||
use std::{collections::BTreeMap, path::{Path, PathBuf}, pin::Pin};
|
||||
use std::{
|
||||
collections::BTreeMap,
|
||||
path::{Path, PathBuf},
|
||||
pin::Pin,
|
||||
};
|
||||
use tokio::{
|
||||
fs::{self, File},
|
||||
io::{AsyncBufReadExt, BufReader},
|
||||
@@ -80,8 +84,11 @@ async fn is_file_exist(filepath: &PathBuf) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
async fn read_file<'a, S, P>(filepath: P, encoding: S) -> Result<String>
|
||||
where S: AsRef<str> + std::cmp::PartialEq<&'a str>, P: AsRef<Path> {
|
||||
async fn read_file<'a, S, P>(filepath: P, encoding: S) -> Result<String>
|
||||
where
|
||||
S: AsRef<str> + std::cmp::PartialEq<&'a str>,
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
let filepath = PathBuf::from(filepath.as_ref());
|
||||
if encoding == "utf8" {
|
||||
return Ok(fs::read_to_string(filepath).await?);
|
||||
@@ -283,12 +290,18 @@ impl Certs {
|
||||
}
|
||||
|
||||
let status = Command::new("openssl")
|
||||
.raw_arg(format!(
|
||||
"req -nodes -new -keyout {} -out {} -config {} -batch",
|
||||
.args(&[
|
||||
"req",
|
||||
"-nodes",
|
||||
"-new",
|
||||
"-keyout",
|
||||
&self.key_file.to_str().unwrap(),
|
||||
"-out",
|
||||
&self.req_file.to_str().unwrap(),
|
||||
&self.openssl_cnf.to_str().unwrap()
|
||||
))
|
||||
"-config",
|
||||
&self.openssl_cnf.to_str().unwrap(),
|
||||
"-batch",
|
||||
])
|
||||
.current_dir(&self.base_dir)
|
||||
.envs(&self.vars)
|
||||
.status()
|
||||
@@ -313,13 +326,18 @@ impl Certs {
|
||||
}
|
||||
|
||||
let status = Command::new("openssl")
|
||||
.raw_arg(format!(
|
||||
"ca -days {} -out {} -in {} -config {} -batch",
|
||||
self.req_days,
|
||||
.args(&[
|
||||
"ca",
|
||||
"-days",
|
||||
format!("{}", self.req_days).as_str(),
|
||||
"-out",
|
||||
&self.cert_file.to_str().unwrap(),
|
||||
"-in",
|
||||
&self.req_file.to_str().unwrap(),
|
||||
&self.openssl_cnf.to_str().unwrap()
|
||||
))
|
||||
"-config",
|
||||
&self.openssl_cnf.to_str().unwrap(),
|
||||
"-batch",
|
||||
])
|
||||
.current_dir(&self.base_dir)
|
||||
.envs(&self.vars)
|
||||
.status()
|
||||
@@ -327,7 +345,7 @@ impl Certs {
|
||||
|
||||
match status.success() {
|
||||
true => Ok(()),
|
||||
false => Err(anyhow!("openssl ca execution failed")),
|
||||
false => Err(anyhow!("ssl ca execution failed")),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,12 +361,10 @@ impl Certs {
|
||||
self.template_file.clone(),
|
||||
self.ca_file.clone(),
|
||||
self.cert_file.clone(),
|
||||
self.key_file.clone()
|
||||
self.key_file.clone(),
|
||||
);
|
||||
let enc = self.encoding.clone();
|
||||
let (enc1, enc2, enc3, enc4) = (
|
||||
enc.clone(), enc.clone(), enc.clone(), enc.clone()
|
||||
);
|
||||
let (enc1, enc2, enc3, enc4) = (enc.clone(), enc.clone(), enc.clone(), enc.clone());
|
||||
|
||||
if let (Ok(Ok(template)), Ok(Ok(ca)), Ok(Ok(cert)), Ok(Ok(key))) = tokio::join!(
|
||||
tokio::spawn(read_file(template_file, enc1)),
|
||||
@@ -370,7 +386,7 @@ impl Certs {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main(flavor="current_thread")]
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn main() -> Result<()> {
|
||||
let args = Args::parse();
|
||||
let default_directory = ".".to_string();
|
||||
|
Reference in New Issue
Block a user