use serde::{Deserialize, Serialize}; use url::Url; use crate::{ ConfigError, driver::ObjectStoreDriver, transport::{Address, Tls}, }; #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(deny_unknown_fields)] pub struct ObjectStorage { pub driver: ObjectStoreDriver, pub bucket: String, pub region: String, pub endpoint: Option
, } impl ObjectStorage { pub(crate) fn resolve(&self) -> Result { if self.bucket.trim().is_empty() || self.region.trim().is_empty() { return Err(ConfigError::ObjectStorage); } self.tls()?; Ok(self.clone()) } /// The TLS policy implied by this endpoint. The default S3 endpoint uses HTTPS. pub fn tls(&self) -> Result { let Some(endpoint) = &self.endpoint else { return Ok(Tls::VerifyFull); }; let url = Url::parse(endpoint.connection_string()).map_err(|_| ConfigError::ObjectStorage)?; if 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); } match url.scheme() { "https" => Ok(Tls::VerifyFull), "http" => Ok(Tls::Disabled), _ => Err(ConfigError::ObjectStorage), } } }