Add a versioned backend catalog and YAML deployment configuration
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use url::Url;
|
||||
|
||||
use crate::{ConfigError, ObjectStoreDriver};
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ObjectStorage {
|
||||
pub driver: ObjectStoreDriver,
|
||||
pub bucket: String,
|
||||
pub region: String,
|
||||
pub endpoint: Option<String>,
|
||||
}
|
||||
|
||||
impl ObjectStorage {
|
||||
pub(crate) fn validate(&self) -> Result<(), ConfigError> {
|
||||
if self.bucket.trim().is_empty() || self.region.trim().is_empty() {
|
||||
return Err(ConfigError::ObjectStorage);
|
||||
}
|
||||
if let Some(endpoint) = &self.endpoint {
|
||||
let url = Url::parse(endpoint).map_err(|_| ConfigError::ObjectStorage)?;
|
||||
if !matches!(url.scheme(), "http" | "https")
|
||||
|| url.host_str().is_none()
|
||||
|| !url.username().is_empty()
|
||||
|| url.password().is_some()
|
||||
|| url.query().is_some()
|
||||
|| url.fragment().is_some()
|
||||
{
|
||||
return Err(ConfigError::ObjectStorage);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user