From c83335d645b4f7c7c3b3221614417414a0ccb630 Mon Sep 17 00:00:00 2001 From: pycanis Date: Sat, 21 Sep 2024 14:27:25 +0200 Subject: [PATCH] Fix openssl + support ~ (home) dir --- Cargo.lock | 11 +++++++++++ Cargo.toml | 1 + Dockerfile-build | 1 + src/config.rs | 25 +++++++++++++------------ 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index def258b..3798960 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -838,6 +838,7 @@ dependencies = [ "cron", "env_logger", "log", + "openssl", "reqwest", "serde", "serde_json", @@ -990,6 +991,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-src" +version = "300.3.2+3.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a211a18d945ef7e648cc6e0058f4c548ee46aab922ea203e0d30e966ea23647b" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.103" @@ -998,6 +1008,7 @@ checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" dependencies = [ "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] diff --git a/Cargo.toml b/Cargo.toml index 69e85a4..1df2eae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ clap = { version = "4.5.16", features = ["derive"] } cron = "0.12.1" env_logger = "0.11.5" log = "0.4.22" +openssl = { version = "0.10", features = ["vendored"] } reqwest = { version = "0.12.7", features = ["json"] } serde = { version = "1.0.209", features = ["derive"] } serde_json = "1.0.128" diff --git a/Dockerfile-build b/Dockerfile-build index 3241396..602671a 100644 --- a/Dockerfile-build +++ b/Dockerfile-build @@ -1,6 +1,7 @@ FROM rust:1.81-slim-bullseye AS build RUN apt-get update && apt-get install -y \ + build-essential \ pkg-config \ libssl-dev diff --git a/src/config.rs b/src/config.rs index a8d379a..acafb1d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,7 +1,7 @@ use crate::job::Job; use log::error; use serde::Deserialize; -use std::{fs, path::Path, process}; +use std::{env, fs, path::Path, process}; const DEFAULT_CONFIG_PATH: &str = "config.yaml"; @@ -38,7 +38,7 @@ impl ValidConfig { if !Path::new(path).exists() { let default_config = r#"macaroon_path: "~/.lnd/data/chain/bitcoin/mainnet/admin.macaroon" cert_path: "~/.lnd/tls.cert" -server_url: "https://127.0.0.1:10009" +server_url: "https://localhost:10009" jobs: # - name: "My first job" # schedule: "0 30 9,12,15 1,15 May-Aug Mon,Wed,Fri 2018/2" @@ -81,18 +81,19 @@ jobs: Some(jobs) => jobs.iter().map(|job| Job::new(job.to_owned())).collect(), }; - tonic_lnd::connect( - config.server_url.to_owned(), - config.cert_path.to_owned(), - config.macaroon_path.to_owned(), - ) - .await - .expect("Failed to verify connection to LND node."); + let home_dir = env::var("HOME").unwrap_or("~".to_string()); + + let cert_path = config.cert_path.replacen("~", &home_dir, 1); + let macaroon_path = config.macaroon_path.replacen("~", &home_dir, 1); + + tonic_lnd::connect(config.server_url.to_owned(), &cert_path, &macaroon_path) + .await + .expect("Failed to verify connection to LND node."); Self { - cert_path: config.cert_path.to_owned(), - macaroon_path: config.macaroon_path.to_owned(), - server_url: config.server_url.to_owned(), + cert_path, + macaroon_path, + server_url: config.server_url, jobs, } }