use ::reqwest::Error;
use reqwest::blocking as reqwest;
const DEFAULT_HOST: &str = "https://localhost:2746";
#[derive(Debug, Default)]
pub struct ConfigBuilder {
accept_invalid_certs: bool,
bearer_token: Option<String>,
host: String,
}
impl ConfigBuilder {
pub fn new() -> Self {
ConfigBuilder {
host: String::from(DEFAULT_HOST),
..Default::default()
}
}
pub fn build(self) -> Result<Config, Error> {
let mut builder = reqwest::Client::builder();
if self.accept_invalid_certs {
builder = builder.danger_accept_invalid_certs(true);
}
let client = builder.build()?;
Ok(Config {
host: self.host,
bearer_token: self.bearer_token,
client,
})
}
pub fn host(mut self, host: &str) -> Self {
self.host = String::from(host);
self
}
pub fn bearer_token(mut self, token: &str) -> Self {
self.bearer_token = Some(String::from(token));
self
}
pub fn danger_accept_invalid_certs(mut self, allow: bool) -> Self {
self.accept_invalid_certs = allow;
self
}
}
#[derive(Debug, Default, Clone)]
pub struct Config {
pub host: String,
pub bearer_token: Option<String>,
pub client: reqwest::Client,
}
impl Config {
pub fn new() -> Self {
Config {
host: String::from(DEFAULT_HOST),
client: reqwest::Client::new(),
..Default::default()
}
}
pub fn builder() -> ConfigBuilder {
ConfigBuilder::new()
}
}