v0.14.15-fix
This commit is contained in:
@@ -21,6 +21,8 @@ pub struct Config {
|
||||
pub app_token: String,
|
||||
#[arg(long, env = "GREE_CONTROLLER_BASE_PATH", default_value = "")]
|
||||
pub base_path: String,
|
||||
#[arg(long, env = "GREE_CONTROLLER_PUBLIC_CHART_BASE_URL", default_value = "")]
|
||||
pub public_chart_base_url: String,
|
||||
#[arg(long, env = "GREE_CONTROLLER_SIMULATE", default_value_t = false)]
|
||||
pub simulate: bool,
|
||||
#[arg(long, env = "GREE_CONTROLLER_AUTO_SEED", default_value_t = false)]
|
||||
@@ -60,6 +62,7 @@ impl Config {
|
||||
dotenvy::dotenv().ok();
|
||||
let mut config = Self::parse();
|
||||
config.base_path = normalize_base_path(&config.base_path)?;
|
||||
config.public_chart_base_url = normalize_public_chart_base_url(&config.public_chart_base_url)?;
|
||||
if let Some(parent) = config.database.parent() {
|
||||
std::fs::create_dir_all(parent).with_context(|| {
|
||||
format!("cannot create database directory {}", parent.display())
|
||||
@@ -282,6 +285,27 @@ fn normalize_base_path(value: &str) -> Result<String> {
|
||||
Ok(format!("/{}", value.trim_matches('/')))
|
||||
}
|
||||
|
||||
fn normalize_public_chart_base_url(value: &str) -> Result<String> {
|
||||
let value = value.trim();
|
||||
if value.is_empty() {
|
||||
return Ok(String::new());
|
||||
}
|
||||
|
||||
let parsed = url::Url::parse(value)
|
||||
.with_context(|| "GREE_CONTROLLER_PUBLIC_CHART_BASE_URL must be an absolute HTTP(S) URL")?;
|
||||
if !matches!(parsed.scheme(), "http" | "https")
|
||||
|| parsed.host_str().is_none()
|
||||
|| !parsed.username().is_empty()
|
||||
|| parsed.password().is_some()
|
||||
|| parsed.query().is_some()
|
||||
|| parsed.fragment().is_some()
|
||||
{
|
||||
anyhow::bail!("GREE_CONTROLLER_PUBLIC_CHART_BASE_URL must be an absolute HTTP(S) URL without credentials, query or fragment");
|
||||
}
|
||||
|
||||
Ok(value.trim_end_matches('/').to_string())
|
||||
}
|
||||
|
||||
fn env_bool(name: &str) -> Option<bool> {
|
||||
env::var(name)
|
||||
.ok()
|
||||
|
||||
Reference in New Issue
Block a user