build: validate CFG_SRC_URL and simplify CFG_RELEASE handling

This commit is contained in:
oxalica 2024-09-25 12:45:34 -04:00
parent fa14844d0d
commit fac146e859
6 changed files with 32 additions and 12 deletions

View file

@ -10,7 +10,7 @@ use tokio::signal::unix::{signal, SignalKind};
/// Blah Chat Server
#[derive(Debug, clap::Parser)]
#[clap(about, version = option_env!("CFG_RELEASE").unwrap_or(env!("CARGO_PKG_VERSION")))]
#[clap(about, version = env!("CFG_RELEASE"))]
enum Cli {
/// Run the server with given configuration.
Serve {

View file

@ -100,11 +100,7 @@ impl AppState {
pub fn new(db: Database, config: ServerConfig) -> Self {
let meta = ServerMetadata {
server: SERVER_AND_VERSION.into(),
// TODO: Validate this at compile time?
src_url: SERVER_SRC_URL.map(|url| {
url.parse()
.expect("BLAHD_SRC_URL from compile time should be valid")
}),
src_url: SERVER_SRC_URL.map(|url| url.parse().expect("checked by build script")),
capabilities: ServerCapabilities {
allow_public_register: config.register.enable_public,
},

View file

@ -15,9 +15,7 @@ use serde::Deserialize;
use sha2::{Digest, Sha256};
use crate::database::TransactionOps;
use crate::{ApiError, AppState};
const USER_AGENT: &str = concat!("blahd/", env!("CARGO_PKG_VERSION"));
use crate::{ApiError, AppState, SERVER_AND_VERSION};
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
#[serde(default, deny_unknown_fields)]
@ -94,7 +92,7 @@ impl State {
pub fn new(config: Config) -> Self {
// TODO: Audit this.
let client = reqwest::ClientBuilder::new()
.user_agent(USER_AGENT)
.user_agent(SERVER_AND_VERSION)
.redirect(reqwest::redirect::Policy::none())
.timeout(Duration::from_secs(config.request_timeout_secs))
.build()