agent/cdh: Use AGENT_CONFIG.cdh_api_timeout for CDH_API_TIMEOUT

This commit updates CDH_API_TIMEOUT to use AGENT_CONFIG.cdh_api_timeout
and changes it from a `const` to `lazy_static` to accommodate runtime-determined values.

Signed-off-by: Hyounggyu Choi <Hyounggyu.Choi@ibm.com>
This commit is contained in:
Hyounggyu Choi 2024-08-22 09:21:48 +02:00
parent 6139e253a0
commit 2512ddeab2

View File

@ -14,10 +14,13 @@ use protocols::{
confidential_data_hub_ttrpc_async::{SealedSecretServiceClient, SecureMountServiceClient}, confidential_data_hub_ttrpc_async::{SealedSecretServiceClient, SecureMountServiceClient},
}; };
use crate::AGENT_CONFIG;
use crate::CDH_SOCKET_URI; use crate::CDH_SOCKET_URI;
// Nanoseconds // Nanoseconds
const CDH_API_TIMEOUT: i64 = 50 * 1000 * 1000 * 1000; lazy_static! {
static ref CDH_API_TIMEOUT: i64 = AGENT_CONFIG.cdh_api_timeout.as_nanos() as i64;
}
const SEALED_SECRET_PREFIX: &str = "sealed."; const SEALED_SECRET_PREFIX: &str = "sealed.";
#[derive(Derivative)] #[derive(Derivative)]
@ -48,7 +51,7 @@ impl CDHClient {
let unsealed_secret = self let unsealed_secret = self
.sealed_secret_client .sealed_secret_client
.unseal_secret(ttrpc::context::with_timeout(CDH_API_TIMEOUT), &input) .unseal_secret(ttrpc::context::with_timeout(*CDH_API_TIMEOUT), &input)
.await?; .await?;
Ok(unsealed_secret.plaintext) Ok(unsealed_secret.plaintext)
} }
@ -81,7 +84,7 @@ impl CDHClient {
..Default::default() ..Default::default()
}; };
self.secure_mount_client self.secure_mount_client
.secure_mount(ttrpc::context::with_timeout(CDH_API_TIMEOUT), &req) .secure_mount(ttrpc::context::with_timeout(*CDH_API_TIMEOUT), &req)
.await?; .await?;
Ok(()) Ok(())
} }