Browse Source

Format the code correctly

pull/31/head
Rodolphe Breard 5 years ago
parent
commit
41f2bda7d3
  1. 5
      acmed/src/acme_proto.rs
  2. 10
      acmed/src/certificate.rs
  3. 13
      acmed/src/endpoint.rs

5
acmed/src/acme_proto.rs

@ -177,6 +177,9 @@ pub fn request_certificate(
let crt = http::get_certificate(endpoint, root_certs, &data_builder, &crt_url)?;
storage::write_certificate(cert, &crt.as_bytes())?;
cert.info(&format!("Certificate renewed (domains: {})", cert.domain_list()));
cert.info(&format!(
"Certificate renewed (domains: {})",
cert.domain_list()
));
Ok(())
}

10
acmed/src/certificate.rs

@ -102,7 +102,10 @@ impl Certificate {
fn is_expiring(&self, cert: &X509Certificate) -> Result<bool, Error> {
let expires_in = cert.expires_in()?;
self.debug(&format!("Certificate expires in {} days", expires_in.as_secs() / 86400));
self.debug(&format!(
"Certificate expires in {} days",
expires_in.as_secs() / 86400
));
// TODO: allow a custom duration (using time-parse ?)
// 1814400 is 3 weeks (3 * 7 * 24 * 60 * 60)
let renewal_time = Duration::new(1_814_400, 0);
@ -141,7 +144,10 @@ impl Certificate {
}
pub fn should_renew(&self) -> Result<bool, Error> {
self.debug(&format!("Checking for renewal (domains: {})", self.domain_list()));
self.debug(&format!(
"Checking for renewal (domains: {})",
self.domain_list()
));
if !certificate_files_exists(&self) {
self.debug("certificate does not exist: requesting one");
return Ok(true);

13
acmed/src/endpoint.rs

@ -20,7 +20,12 @@ pub struct Endpoint {
}
impl Endpoint {
pub fn new(name: &str, url: &str, tos_agreed: bool, limits: &[(usize, String)]) -> Result<Self, Error> {
pub fn new(
name: &str,
url: &str,
tos_agreed: bool,
limits: &[(usize, String)],
) -> Result<Self, Error> {
let rl = RateLimit::new(limits)?;
Ok(Self {
name: name.to_string(),
@ -99,7 +104,11 @@ impl RateLimit {
fn request_allowed(&self) -> bool {
for (max_allowed, duration) in self.limits.iter() {
let max_date = Instant::now() - *duration;
let nb_req = self.query_log.iter().filter(move |x| **x > max_date).count();
let nb_req = self
.query_log
.iter()
.filter(move |x| **x > max_date)
.count();
if nb_req >= *max_allowed {
return false;
}

Loading…
Cancel
Save