use super::region::Region;
#[derive(Debug, Clone)]
pub struct QiniuConfig {
pub access_key: String,
pub secret_key: String,
pub bucket: String,
pub region: Region,
pub download_domain: Option<String>,
pub private_bucket: bool,
pub deadline_offset_secs: i64,
pub use_https: bool,
pub up_host: Option<String>,
pub rs_host: Option<String>,
pub rsf_host: Option<String>,
}
impl QiniuConfig {
pub fn new(
access_key: impl Into<String>,
secret_key: impl Into<String>,
bucket: impl Into<String>,
) -> Self {
QiniuConfig {
access_key: access_key.into(),
secret_key: secret_key.into(),
bucket: bucket.into(),
region: Region::default(),
download_domain: None,
private_bucket: false,
deadline_offset_secs: 0,
use_https: true,
up_host: None,
rs_host: None,
rsf_host: None,
}
}
pub fn region(mut self, region: Region) -> Self {
self.region = region;
self
}
pub fn private_bucket(mut self, domain: impl Into<String>) -> Self {
self.private_bucket = true;
self.download_domain = Some(domain.into());
self
}
pub fn private(mut self) -> Self {
self.private_bucket = true;
self
}
pub fn deadline_offset_secs(mut self, offset: i64) -> Self {
self.deadline_offset_secs = offset;
self
}
pub fn download_domain(mut self, domain: impl Into<String>) -> Self {
self.download_domain = Some(domain.into());
self
}
pub fn use_https(mut self, on: bool) -> Self {
self.use_https = on;
self
}
pub fn up_host(mut self, host: impl Into<String>) -> Self {
self.up_host = Some(host.into());
self
}
pub fn rs_host(mut self, host: impl Into<String>) -> Self {
self.rs_host = Some(host.into());
self
}
pub fn rsf_host(mut self, host: impl Into<String>) -> Self {
self.rsf_host = Some(host.into());
self
}
pub(crate) fn scheme(&self) -> &'static str {
if self.use_https {
"https"
} else {
"http"
}
}
pub(crate) fn up_host_resolved(&self) -> &str {
self.up_host
.as_deref()
.unwrap_or_else(|| self.region.up_host())
}
pub(crate) fn rs_host_resolved(&self) -> &str {
self.rs_host
.as_deref()
.unwrap_or_else(|| self.region.rs_host())
}
pub(crate) fn rsf_host_resolved(&self) -> &str {
self.rsf_host
.as_deref()
.unwrap_or_else(|| self.region.rsf_host())
}
pub(crate) fn download_host(&self) -> &str {
self.download_domain
.as_deref()
.unwrap_or_else(|| self.region.io_host())
}
}