cleanup acme client

This commit is contained in:
Dietmar Maurer 2021-05-04 09:28:53 +02:00
parent f2f526b61d
commit 73c607497e
1 changed files with 13 additions and 17 deletions

View File

@ -57,7 +57,7 @@ pub struct AcmeClient {
account: Option<Account>, account: Option<Account>,
directory: Option<Directory>, directory: Option<Directory>,
nonce: Option<String>, nonce: Option<String>,
http_client: Option<SimpleHttp>, http_client: SimpleHttp,
} }
impl AcmeClient { impl AcmeClient {
@ -71,7 +71,7 @@ impl AcmeClient {
account: None, account: None,
directory: None, directory: None,
nonce: None, nonce: None,
http_client: None, http_client: SimpleHttp::new(None),
} }
} }
@ -87,16 +87,13 @@ impl AcmeClient {
let account = Account::from_parts(data.location, data.key, data.account); let account = Account::from_parts(data.location, data.key, data.account);
Ok(Self { let mut me = Self::new(data.directory_url);
directory_url: data.directory_url, me.debug = data.debug;
debug: data.debug, me.account_path = Some(account_path);
account_path: Some(account_path), me.tos = data.tos;
tos: data.tos, me.account = Some(account);
account: Some(account),
directory: None, Ok(me)
nonce: None,
http_client: None,
})
} }
pub async fn new_account<'a>( pub async fn new_account<'a>(
@ -468,7 +465,7 @@ impl AcmeResponse {
impl AcmeClient { impl AcmeClient {
/// Non-self-borrowing run_request version for borrow workarounds. /// Non-self-borrowing run_request version for borrow workarounds.
async fn execute( async fn execute(
http_client: &mut Option<SimpleHttp>, http_client: &mut SimpleHttp,
request: AcmeRequest, request: AcmeRequest,
nonce: &mut Option<String>, nonce: &mut Option<String>,
) -> Result<AcmeResponse, Error> { ) -> Result<AcmeResponse, Error> {
@ -485,7 +482,6 @@ impl AcmeClient {
.map_err(|err| Error::Custom(format!("failed to create http request: {}", err)))?; .map_err(|err| Error::Custom(format!("failed to create http request: {}", err)))?;
let response = http_client let response = http_client
.get_or_insert_with(|| SimpleHttp::new(None))
.request(http_request) .request(http_request)
.await .await
.map_err(|err| Error::Custom(err.to_string()))?; .map_err(|err| Error::Custom(err.to_string()))?;
@ -573,7 +569,7 @@ impl AcmeClient {
} }
async fn get_directory<'a, 'b>( async fn get_directory<'a, 'b>(
http_client: &mut Option<SimpleHttp>, http_client: &mut SimpleHttp,
directory_url: &str, directory_url: &str,
directory: &'a mut Option<Directory>, directory: &'a mut Option<Directory>,
nonce: &'b mut Option<String>, nonce: &'b mut Option<String>,
@ -606,7 +602,7 @@ impl AcmeClient {
/// Like `get_directory`, but if the directory provides no nonce, also performs a `HEAD` /// Like `get_directory`, but if the directory provides no nonce, also performs a `HEAD`
/// request on the new nonce URL. /// request on the new nonce URL.
async fn get_dir_nonce<'a, 'b>( async fn get_dir_nonce<'a, 'b>(
http_client: &mut Option<SimpleHttp>, http_client: &mut SimpleHttp,
directory_url: &str, directory_url: &str,
directory: &'a mut Option<Directory>, directory: &'a mut Option<Directory>,
nonce: &'b mut Option<String>, nonce: &'b mut Option<String>,
@ -626,7 +622,7 @@ impl AcmeClient {
} }
async fn get_nonce<'a>( async fn get_nonce<'a>(
http_client: &mut Option<SimpleHttp>, http_client: &mut SimpleHttp,
nonce: &'a mut Option<String>, nonce: &'a mut Option<String>,
new_nonce_url: &str, new_nonce_url: &str,
) -> Result<&'a str, Error> { ) -> Result<&'a str, Error> {