Skip to content

Commit

Permalink
Log config imported from t-rex
Browse files Browse the repository at this point in the history
  • Loading branch information
pka committed Feb 23, 2024
1 parent 5154926 commit 1a1f0c7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 39 deletions.
6 changes: 3 additions & 3 deletions bbox-core/src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ pub struct Identity {
#[cfg(not(feature = "oidc"))]
pub mod oidc {
use super::Identity;
use serde::Deserialize;
use serde::{Deserialize, Serialize};

type AuthError = std::io::Error;

#[derive(Deserialize, Default, Clone, Debug)]
#[derive(Deserialize, Serialize, Default, Clone, Debug)]
pub struct OidcAuthCfg;

#[derive(Default, Clone)]
Expand All @@ -27,7 +27,7 @@ pub mod oidc {
}
}

#[derive(Deserialize)]
#[derive(Deserialize, Serialize)]
pub struct AuthRequest;

impl AuthRequest {
Expand Down
6 changes: 3 additions & 3 deletions bbox-core/src/auth/oidc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use openidconnect::{
CsrfToken, IssuerUrl, Nonce, OAuth2TokenResponse, RedirectUrl, RequestTokenError, Scope,
StandardErrorResponse,
};
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use serde_json::Value;

#[derive(thiserror::Error, Debug)]
Expand All @@ -26,7 +26,7 @@ pub enum AuthError {
OpenidIdTokenError,
}

#[derive(Deserialize, Default, Clone, Debug)]
#[derive(Deserialize, Serialize, Default, Clone, Debug)]
#[serde(default, deny_unknown_fields)]
pub struct OidcAuthCfg {
pub client_id: String,
Expand Down Expand Up @@ -94,7 +94,7 @@ impl OidcClient {
}
}

#[derive(Deserialize, Debug)]
#[derive(Deserialize, Serialize, Debug)]
pub struct AuthRequest {
pub code: String,
// pub state: String,
Expand Down
24 changes: 12 additions & 12 deletions bbox-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use figment::providers::{Env, Format, Toml};
use figment::Figment;
use log::info;
use once_cell::sync::OnceCell;
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use std::env;
use std::path::PathBuf;

Expand Down Expand Up @@ -70,7 +70,7 @@ pub fn error_exit<T: Display, R>(err: T) -> R {

// -- Common configuration --

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(default, deny_unknown_fields)]
pub struct WebserverCfg {
pub server_addr: String,
Expand Down Expand Up @@ -109,7 +109,7 @@ impl WebserverCfg {
}
}

#[derive(Deserialize, Default, Clone, Debug)]
#[derive(Deserialize, Serialize, Default, Clone, Debug)]
#[serde(default, deny_unknown_fields)]
pub struct AuthCfg {
pub oidc: Option<OidcAuthCfg>,
Expand All @@ -123,20 +123,20 @@ impl AuthCfg {

// -- Metrics --

#[derive(Deserialize, Default, Debug)]
#[derive(Deserialize, Serialize, Default, Debug)]
#[serde(deny_unknown_fields)]
pub struct MetricsCfg {
pub prometheus: Option<PrometheusCfg>,
pub jaeger: Option<JaegerCfg>,
}

#[derive(Deserialize, Debug)]
#[derive(Deserialize, Serialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct PrometheusCfg {
pub path: String,
}

#[derive(Deserialize, Debug)]
#[derive(Deserialize, Serialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct JaegerCfg {
pub agent_endpoint: String,
Expand All @@ -150,15 +150,15 @@ impl MetricsCfg {

// -- Datasources --

#[derive(Deserialize, Debug)]
#[derive(Deserialize, Serialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct NamedDatasourceCfg {
pub name: String,
#[serde(flatten)]
pub datasource: DatasourceCfg,
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
pub enum DatasourceCfg {
// -- vector sources --
#[serde(rename = "postgis")]
Expand All @@ -177,7 +177,7 @@ pub enum DatasourceCfg {
Mbtiles,
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct DsGpkgCfg {
pub path: PathBuf,
Expand All @@ -187,7 +187,7 @@ pub struct DsGpkgCfg {

/*
// t-rex Datasource (top-level Array)
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct DatasourceCfg {
pub name: Option<String>,
pub default: Option<bool>,
Expand All @@ -200,7 +200,7 @@ pub struct DatasourceCfg {
}
*/

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct WmsHttpSourceProviderCfg {
pub baseurl: String,
Expand All @@ -213,7 +213,7 @@ mod tests {
use figment::providers::Env;
use serde::Deserialize;

#[derive(Deserialize, Debug)]
#[derive(Deserialize, Serialize, Debug)]
struct Package {
name: String,
edition: Option<String>,
Expand Down
6 changes: 3 additions & 3 deletions bbox-core/src/pg_ds.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use log::info;
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use sqlx::postgres::{PgPool, PgPoolOptions};
use thiserror::Error;

Expand Down Expand Up @@ -31,15 +31,15 @@ impl PgDatasource {
}
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct DsPostgisCfg {
pub url: String,
}

/*
// t-rex Datasource (top-level Array)
#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct DatasourceCfg {
pub name: Option<String>,
pub default: Option<bool>,
Expand Down
40 changes: 22 additions & 18 deletions bbox-tile-server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use bbox_core::pg_ds::DsPostgisCfg;
use clap::{ArgMatches, FromArgMatches};
use log::{info, warn};
use regex::Regex;
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::convert::From;
use std::num::NonZeroU16;
use std::path::{Path, PathBuf};

#[derive(Deserialize, Default, Debug)]
#[derive(Deserialize, Serialize, Default, Debug)]
#[serde(default)]
pub struct TileserverCfg {
#[serde(rename = "grid")]
Expand All @@ -25,7 +25,7 @@ pub struct TileserverCfg {
pub tilestores: Vec<TileCacheProviderCfg>,
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct TileSetCfg {
pub name: String,
Expand All @@ -44,14 +44,14 @@ pub struct TileSetCfg {
}

/// Custom grid definition
#[derive(Deserialize, Debug)]
#[derive(Deserialize, Serialize, Debug)]
#[serde(deny_unknown_fields)]
pub struct GridCfg {
/// JSON file path
pub json: String,
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub enum SourceParamCfg {
#[serde(rename = "wms_proxy")]
Expand All @@ -66,15 +66,15 @@ pub enum SourceParamCfg {
Pmtiles(PmtilesStoreCfg),
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct WmsHttpSourceParamsCfg {
/// name of WmsHttpSourceProviderCfg
pub source: String,
pub layers: String,
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct WmsFcgiSourceParamsCfg {
pub project: String,
Expand All @@ -87,7 +87,7 @@ pub struct WmsFcgiSourceParamsCfg {
pub tile_size: Option<NonZeroU16>,
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct PostgisSourceParamsCfg {
/// Name of tileserver.source config (Default: first with matching type)
Expand All @@ -107,7 +107,7 @@ pub struct PostgisSourceParamsCfg {
pub layers: Vec<VectorLayerCfg>,
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct ExtentCfg {
pub minx: f64,
Expand All @@ -116,7 +116,7 @@ pub struct ExtentCfg {
pub maxy: f64,
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct VectorLayerCfg {
pub name: String,
Expand Down Expand Up @@ -166,7 +166,7 @@ fn default_tolerance() -> String {
DEFAULT_TOLERANCE.to_string()
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct VectorLayerQueryCfg {
#[serde(default)]
Expand All @@ -179,15 +179,15 @@ pub struct VectorLayerQueryCfg {
pub sql: Option<String>,
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct CacheLimitCfg {
#[serde(default)]
pub minzoom: u8,
pub maxzoom: Option<u8>,
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct TileCacheProviderCfg {
pub name: String,
Expand All @@ -196,7 +196,7 @@ pub struct TileCacheProviderCfg {
pub cache: TileStoreCfg,
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(rename_all = "lowercase", deny_unknown_fields)]
pub enum TileStoreCfg {
Files(FileStoreCfg),
Expand All @@ -205,14 +205,14 @@ pub enum TileStoreCfg {
Pmtiles(PmtilesStoreCfg),
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct FileStoreCfg {
/// Base directory, tileset name will be appended
pub base_dir: PathBuf,
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct S3StoreCfg {
pub path: String,
Expand All @@ -221,13 +221,13 @@ pub struct S3StoreCfg {
// pub aws_secret_access_key: Option<String>,
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct MbtilesStoreCfg {
pub path: PathBuf,
}

#[derive(Deserialize, Clone, Debug)]
#[derive(Deserialize, Serialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct PmtilesStoreCfg {
pub path: PathBuf,
Expand All @@ -243,6 +243,7 @@ impl TileserverCfg {
t_rex::read_config(t_rex_config.to_str().expect("invalid string"))
.unwrap_or_else(error_exit);
cfg = t_rex_cfg.into();
info!("Imported t-rex config: \n{}", cfg.as_toml());
}

// Get config from CLI
Expand All @@ -269,6 +270,9 @@ impl TileserverCfg {
}
cfg
}
pub fn as_toml(&self) -> String {
toml::to_string(&self).unwrap()
}
}

impl From<t_rex::ApplicationCfg> for TileserverCfg {
Expand Down

0 comments on commit 1a1f0c7

Please sign in to comment.