Skip to content

Commit 172ab6d

Browse files
sbernauerTechassi
andcommitted
Refactor stuff into generate_new_certificatei
Co-authored-by: Techassi <[email protected]>
1 parent 3f32982 commit 172ab6d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

crates/stackable-webhook/src/tls/cert_resolver.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ impl CertificateResolver {
6969
) -> Result<Self> {
7070
let subject_alterative_dns_names = Arc::new(subject_alterative_dns_names);
7171
let certified_key =
72-
Self::generate_new_cert(&cert_tx, subject_alterative_dns_names.clone()).await?;
72+
Self::generate_new_certificate_inner(subject_alterative_dns_names.clone(), &cert_tx)
73+
.await?;
7374

7475
Ok(Self {
7576
subject_alterative_dns_names,
@@ -79,26 +80,29 @@ impl CertificateResolver {
7980
}
8081

8182
pub async fn rotate_certificate(&self) -> Result<()> {
82-
let certified_key =
83-
Self::generate_new_cert(&self.cert_tx, self.subject_alterative_dns_names.clone())
84-
.await?;
83+
let certified_key = self.generate_new_certificate().await?;
8584

8685
// TODO: Sign the new cert somehow with the old cert. See https://github.com/stackabletech/decisions/issues/56
8786
self.current_certified_key.store(certified_key);
8887

8988
Ok(())
9089
}
9190

91+
async fn generate_new_certificate(&self) -> Result<Arc<CertifiedKey>> {
92+
let subject_alterative_dns_names = self.subject_alterative_dns_names.clone();
93+
Self::generate_new_certificate_inner(subject_alterative_dns_names, &self.cert_tx).await
94+
}
95+
9296
/// Creates a new certificate and returns the certified key.
9397
///
9498
/// The certificate is send to the passed `cert_tx`.
9599
///
96100
/// FIXME: This should *not* construct a CA cert and cert, but only a cert!
97101
/// This needs some changes in stackable-certs though.
98102
/// See [the relevant decision](https://github.com/stackabletech/decisions/issues/56)
99-
async fn generate_new_cert(
100-
cert_tx: &mpsc::Sender<Certificate>,
103+
async fn generate_new_certificate_inner(
101104
subject_alterative_dns_names: Arc<Vec<String>>,
105+
cert_tx: &mpsc::Sender<Certificate>,
102106
) -> Result<Arc<CertifiedKey>> {
103107
// The certificate generations can take a while, so we use `spawn_blocking`
104108
let (cert, certified_key) = tokio::task::spawn_blocking(move || {

0 commit comments

Comments
 (0)