Skip to content

Commit

Permalink
create ConfigState::get_certificates_by_domain_name
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed May 22, 2023
1 parent f193370 commit 2f79f3c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions command/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,21 @@ impl ConfigState {
.next()
}

pub fn get_certificates_by_domain_name(
&self,
domain_name: String,
) -> Vec<CertificateWithNames> {
self.certificates
.values()
.flat_map(|hash_map| hash_map.values())
.filter(|certificate_and_key| certificate_and_key.names.contains(&domain_name))
.map(|certificate_and_key| CertificateWithNames {
certificate: certificate_and_key.certificate.clone(),
names: certificate_and_key.names.clone(),
})
.collect()
}

pub fn list_frontends(&self, filters: FrontendFilters) -> ListedFrontends {
// if no http / https / tcp filter is provided, list all of them
let list_all = !filters.http && !filters.https && !filters.tcp;
Expand Down Expand Up @@ -1994,5 +2009,10 @@ mod tests {
.expect("could not retrieve certificate by fingerprint");

println!("found certificate: {:#?}", certificate_found_by_fingerprint);

let certificate_found_by_domain_name =
state.get_certificates_by_domain_name("lolcatho.st".to_string());

assert!(certificate_found_by_domain_name.len() >= 1);
}
}

0 comments on commit 2f79f3c

Please sign in to comment.