#[macro_use] extern crate anyhow; use structopt::StructOpt; mod cert; mod cert_store; mod consul; mod http; mod https; mod proxy_config; mod reverse_proxy; use log::*; #[derive(StructOpt, Debug)] #[structopt(name = "tricot")] struct Opt { /// Address of consul server #[structopt(long = "consul-addr", env = "TRICOT_CONSUL_HOST", default_value = "http://127.0.0.1:8500/")] pub consul_addr: String, /// Prefix of Tricot's entries in Consul KV space #[structopt(long = "consul-kv-prefix", env = "TRICOT_CONSUL_KV_PREFIX", default_value = "tricot/")] pub consul_kv_prefix: String, /// Node name #[structopt(long = "node-name", env = "TRICOT_NODE_NAME", default_value = "")] pub node_name: String, } #[tokio::main(flavor = "multi_thread", worker_threads = 10)] async fn main() { if std::env::var("RUST_LOG").is_err() { std::env::set_var("RUST_LOG", "tricot=debug") } pretty_env_logger::init(); let opt = Opt::from_args(); info!("Starting Tricot"); let consul = consul::Consul::new(&opt.consul_addr, &opt.consul_kv_prefix, &opt.node_name); let mut rx_proxy_config = proxy_config::spawn_proxy_config_task(consul.clone()); let cert_store = cert_store::CertStore::new(consul.clone()); tokio::spawn( cert_store .clone() .watch_proxy_config(rx_proxy_config.clone()), ); tokio::spawn(http::serve_http(consul.clone())); tokio::spawn(https::serve_https( cert_store.clone(), rx_proxy_config.clone(), )); while rx_proxy_config.changed().await.is_ok() { info!("Proxy config: {:#?}", *rx_proxy_config.borrow()); } }