#![cfg(feature = "aws")]
#![cfg_attr(docsrs, doc(cfg(feature = "aws")))]
use std::time::SystemTime;
#[derive(Clone)]
pub struct Config {
pub(crate) access_key_id: String,
pub(crate) access_key_secret: String,
pub(crate) session_token: Option<String>,
pub(crate) expires_in: Option<SystemTime>,
pub(crate) log_group: String,
pub(crate) region: String,
pub(crate) provider: &'static str,
}
impl Config {
pub fn new<S1, S2, S3, S4>(
access_key_id: S1,
access_key_secret: S2,
log_group: S3,
region: S4,
) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
S4: Into<String>,
{
Config {
access_key_id: access_key_id.into(),
access_key_secret: access_key_secret.into(),
session_token: None,
expires_in: None,
log_group: log_group.into(),
region: region.into(),
provider: "timber-rust",
}
}
pub fn get_access_key_id(&self) -> &str {
&self.access_key_id
}
pub fn get_access_key_secret(&self) -> &str {
&self.access_key_secret
}
pub fn get_session_token(&self) -> Option<&str> {
self.session_token.as_deref()
}
pub fn get_expires_in(&self) -> Option<SystemTime> {
self.expires_in
}
pub fn get_log_group(&self) -> &str {
&self.log_group
}
pub fn get_region(&self) -> &str {
&self.region
}
pub fn get_provider(&self) -> &'static str {
&self.provider
}
pub fn access_key_id(mut self, v: impl Into<String>) -> Self {
self.access_key_id = v.into();
self
}
pub fn access_key_secret(mut self, v: impl Into<String>) -> Self {
self.access_key_secret = v.into();
self
}
pub fn session_token(mut self, v: Option<impl Into<String>>) -> Self {
self.session_token = v.map(|v| v.into());
self
}
pub fn expires_in(mut self, v: Option<SystemTime>) -> Self {
self.expires_in = v;
self
}
pub fn log_group(mut self, v: impl Into<String>) -> Self {
self.log_group = v.into();
self
}
pub fn region(mut self, v: impl Into<String>) -> Self {
self.region = v.into();
self
}
pub fn provider(mut self, v: &'static str) -> Self {
self.provider = v;
self
}
}
impl std::fmt::Debug for Config {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut d = f.debug_struct("Config");
d.field("access_key_id", &self.access_key_id)
.field("access_key_secret", &"***")
.field("log_group", &self.log_group)
.field("region", &self.region)
.field("provider", &self.provider);
#[cfg(debug_assertions)]
{
d.field("access_key_secret", &self.access_key_secret);
}
#[cfg(not(debug_assertions))]
{
d.field("access_key_secret", &"***");
}
d.finish()
}
}