Skip to content

Commit

Permalink
chore: test correct path (#9)
Browse files Browse the repository at this point in the history
Signed-off-by: James Petersen <jpetersenames@gmail.com>
  • Loading branch information
found-it authored Dec 12, 2024
1 parent 1545e49 commit 31954c7
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,42 @@ fn set_certs_dir() -> Result<String> {
Ok(certs_dir)
}

fn set_crt_file() -> Result<String> {
fn set_crt_path(certs_dir: &String) -> Result<String> {
let crt_file = env::var("WEBHOOK_CRT_FILE").unwrap_or("tls.crt".to_string());
let crt_path = format!("{}/{}", certs_dir, &crt_file);

let meta = match fs::metadata(&crt_file) {
let meta = match fs::metadata(&crt_path) {
Err(e) => return Err(anyhow!("Error reading metadata for {}: {}", crt_file, e)),
Ok(meta) => meta,
};

if !meta.is_file() {
return Err(anyhow!("{} is not a file", crt_file));
return Err(anyhow!("{} is not a file", crt_path));
}

Ok(crt_file)
Ok(crt_path)
}

fn set_key_file() -> Result<String> {
fn set_key_path(certs_dir: &String) -> Result<String> {
let key_file = env::var("WEBHOOK_KEY_FILE").unwrap_or("tls.key".to_string());
let key_path = format!("{}/{}", certs_dir, &key_file);

let meta = match fs::metadata(&key_file) {
let meta = match fs::metadata(&key_path) {
Err(e) => return Err(anyhow!("Error reading metadata for {}: {}", key_file, e)),
Ok(meta) => meta,
};

if !meta.is_file() {
return Err(anyhow!("{} is not a file", key_file));
return Err(anyhow!("{} is not a file", key_path));
}

Ok(key_file)
Ok(key_path)
}

pub async fn start() -> Result<()> {
let certs_dir = set_certs_dir()?;
let crt_file = set_crt_file()?;
let key_file = set_key_file()?;
let crt_path = set_crt_path(&certs_dir)?;
let key_path = set_key_path(&certs_dir)?;
info!("configured certs directory to: {}", certs_dir);

// TODO: Make healthz and livez listen on http rather than https if they need to do more
Expand All @@ -70,8 +72,8 @@ pub async fn start() -> Result<()> {
info!("listening on 8443");
warp::serve(routes)
.tls()
.cert_path(format!("{}/{}", certs_dir, crt_file))
.key_path(format!("{}/{}", certs_dir, key_file))
.cert_path(crt_path)
.key_path(key_path)
.run(([0, 0, 0, 0], 8443))
.await;

Expand Down

0 comments on commit 31954c7

Please sign in to comment.