Browse Source

Remove a few unwrap

pull/39/head
Rodolphe Breard 4 years ago
parent
commit
43c9eee202
  1. 15
      acmed/src/config.rs
  2. 2
      acmed/src/http.rs
  3. 3
      acmed/src/main_event_loop.rs
  4. 13
      acmed/src/storage.rs

15
acmed/src/config.rs

@ -338,12 +338,17 @@ impl Certificate {
}
}
pub fn get_crt_name(&self) -> String {
match &self.name {
pub fn get_crt_name(&self) -> Result<String, Error> {
let name = match &self.name {
Some(n) => n.to_string(),
None => self.domains.first().unwrap().dns.to_owned(),
}
.replace("*", "_")
None => self
.domains
.first()
.ok_or_else(|| Error::from("Certificate has no domain names."))?
.dns
.to_owned(),
};
Ok(name.replace("*", "_"))
}
pub fn get_crt_name_format(&self) -> String {

2
acmed/src/http.rs

@ -109,7 +109,7 @@ where
let _ = new_nonce(endpoint, root_certs);
}
for _ in 0..crate::DEFAULT_HTTP_FAIL_NB_RETRY {
let nonce = &endpoint.nonce.clone().unwrap();
let nonce = &endpoint.nonce.clone().unwrap_or_default();
let body = data_builder(&nonce, url)?;
rate_limit(endpoint);
let response = session.post(url).text(&body).send()?;

3
acmed/src/main_event_loop.rs

@ -53,7 +53,7 @@ impl MainEventLoop {
hooks: crt.get_hooks(&cnf)?,
account_directory: cnf.get_account_dir(),
crt_directory: crt.get_crt_dir(&cnf),
crt_name: crt.get_crt_name(),
crt_name: crt.get_crt_name()?,
crt_name_format: crt.get_crt_name_format(),
cert_file_mode: cnf.get_cert_file_mode(),
cert_file_owner: cnf.get_cert_file_user(),
@ -109,7 +109,6 @@ impl MainEventLoop {
let handle = thread::spawn(move || {
let mut endpoint = lock.write().unwrap();
for crt in certs_to_renew {
//let root_certs = rc.clone();
renew_certificate(&crt, &rc, &mut endpoint);
}
});

13
acmed/src/storage.rs

@ -93,7 +93,9 @@ fn set_owner(cert: &Certificate, path: &PathBuf, file_type: FileType) -> Result<
let uid = match uid {
Some(u) => {
if u.bytes().all(|b| b.is_ascii_digit()) {
let raw_uid = u.parse::<u32>().unwrap();
let raw_uid = u
.parse::<u32>()
.map_err(|_| Error::from("Unable to parse the UID"))?;
let nix_uid = nix::unistd::Uid::from_raw(raw_uid);
Some(nix_uid)
} else {
@ -106,7 +108,9 @@ fn set_owner(cert: &Certificate, path: &PathBuf, file_type: FileType) -> Result<
let gid = match gid {
Some(g) => {
if g.bytes().all(|b| b.is_ascii_digit()) {
let raw_gid = g.parse::<u32>().unwrap();
let raw_gid = g
.parse::<u32>()
.map_err(|_| Error::from("Unable to parse the GID"))?;
let nix_gid = nix::unistd::Gid::from_raw(raw_gid);
Some(nix_gid)
} else {
@ -219,7 +223,10 @@ fn check_files(cert: &Certificate, file_types: &[FileType]) -> bool {
return false;
}
};
cert.trace(&format!("Testing file path: {}", path.to_str().unwrap()));
cert.trace(&format!(
"Testing file path: {}",
path.to_str().unwrap_or_default()
));
if !path.is_file() {
return false;
}

Loading…
Cancel
Save