diff --git a/flake.nix b/flake.nix index 20292b8..642571c 100644 --- a/flake.nix +++ b/flake.nix @@ -34,6 +34,11 @@ buildInputs = deps; nativeBuildInputs = [pkgs.pkg-config]; env = {GIT_HASH = self.rev or self.dirtyRev or "nix-dirty";}; + + meta = { + mainProgram = "ursa-minor"; + license = lib.licenses.agpl3Only; + }; }; devShells.default = mkShell { buildInputs = diff --git a/src/lbin.rs b/src/lbin.rs index 71f47ab..e860755 100644 --- a/src/lbin.rs +++ b/src/lbin.rs @@ -98,11 +98,8 @@ impl Auction { #[tracing::instrument(skip_all)] fn item_bytes(&self) -> anyhow::Result> { - let base64_decoded = base64::engine::general_purpose::STANDARD.decode( - self.item_bytes_compressed - .as_ref() - .as_bytes(), - )?; + let base64_decoded = base64::engine::general_purpose::STANDARD + .decode(self.item_bytes_compressed.as_ref().as_bytes())?; Ok(base64_decoded.into()) } diff --git a/src/main.rs b/src/main.rs index 2ee14f8..0aea290 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,8 @@ extern crate core; use std::env; -use std::net::SocketAddr; +use std::net::{IpAddr, SocketAddr}; +use std::str::FromStr as _; use std::time::Duration; use crate::hypixel::Rule; @@ -39,8 +40,8 @@ use hyper_tls::HttpsConnector; use tokio::task::JoinHandle; use tokio::time::Instant; use tokio_util::sync::CancellationToken; -use tracing::{error, info, warn}; use tracing::instrument::WithSubscriber; +use tracing::{error, info, warn}; pub mod hypixel; pub mod meta; @@ -67,6 +68,7 @@ pub struct RequestContext { pub struct GlobalApplicationContext { client: Client>, hypixel_token: Obscure, + address: IpAddr, port: u16, rules: Vec, allow_anonymous: bool, @@ -173,6 +175,8 @@ fn init_config() -> anyhow::Result { }) }) .collect::, _>>()?; + let address = IpAddr::from_str(&config_var("ADDRESS").unwrap_or("172.0.0.1".to_owned())) + .with_context(|| "Could not parse bind address at URSA_ADDRESS")?; let port = config_var("PORT")? .parse::() .with_context(|| "Could not parse port at URSA_PORT")?; @@ -191,6 +195,7 @@ fn init_config() -> anyhow::Result { let rate_limit_bucket = config_var("RATE_LIMIT_BUCKET")?.parse::()?; Ok(GlobalApplicationContext { client, + address, port, hypixel_token: Obscure(hypixel_token), rules, @@ -200,6 +205,7 @@ fn init_config() -> anyhow::Result { default_token_duration: Duration::from_secs(token_lifespan), rate_limit_lifespan, rate_limit_bucket, + #[cfg(feature = "influxdb")] influx_url, }) } @@ -267,7 +273,10 @@ async fn run_server() -> anyhow::Result<()> { "Launching with configuration: {:#?}", *global_application_config ); - let addr = SocketAddr::from(([127, 0, 0, 1], global_application_config.port)); + let addr = SocketAddr::from(( + global_application_config.address, + global_application_config.port, + )); let redis_client = redis::Client::open(global_application_config.redis_url.clone())?; let managed = redis::aio::ConnectionManager::new(redis_client).await?; let service = make_service_fn(|_conn| { diff --git a/src/util.rs b/src/util.rs index bb36380..666dda0 100644 --- a/src/util.rs +++ b/src/util.rs @@ -17,6 +17,7 @@ use chrono::Utc; use hyper::http::request::Builder; use hyper::Uri; +#[cfg(feature = "influxdb")] use influxdb::Timestamp; use serde::{Deserialize, Serialize}; use std::fmt::{Debug, Formatter, Write}; @@ -69,11 +70,14 @@ impl Debug for MillisecondTimestamp { } } +#[cfg(feature = "influxdb")] impl From for Timestamp { fn from(value: MillisecondTimestamp) -> Self { chrono::DateTime::::from(SystemTime::from(value)).into() } } + +#[cfg(feature = "influxdb")] impl From for MillisecondTimestamp { fn from(value: Timestamp) -> Self { let datetime: chrono::DateTime = value.into();