mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 07:48:55 +00:00
agent:cdh: Initialize CDH client as a global asynchronous instance
Introduced a global `CDH_CLIENT` instance to hold the cdh client and implemented `init_cdh_client` function to initialize the cdh client if not already set. Fixes: #10231 Signed-off-by: ChengyuZhu6 <chengyu.zhu@intel.com>
This commit is contained in:
parent
4698235e59
commit
0ad35dc91b
@ -7,19 +7,20 @@
|
|||||||
// Confidential Data Hub is a service running inside guest to provide resource related APIs.
|
// Confidential Data Hub is a service running inside guest to provide resource related APIs.
|
||||||
// https://github.com/confidential-containers/guest-components/tree/main/confidential-data-hub
|
// https://github.com/confidential-containers/guest-components/tree/main/confidential-data-hub
|
||||||
|
|
||||||
use anyhow::Result;
|
use crate::AGENT_CONFIG;
|
||||||
|
use crate::CDH_SOCKET_URI;
|
||||||
|
use anyhow::{Context, Result};
|
||||||
use derivative::Derivative;
|
use derivative::Derivative;
|
||||||
use protocols::{
|
use protocols::{
|
||||||
confidential_data_hub, confidential_data_hub_ttrpc_async,
|
confidential_data_hub, confidential_data_hub_ttrpc_async,
|
||||||
confidential_data_hub_ttrpc_async::{SealedSecretServiceClient, SecureMountServiceClient},
|
confidential_data_hub_ttrpc_async::{SealedSecretServiceClient, SecureMountServiceClient},
|
||||||
};
|
};
|
||||||
|
use tokio::sync::OnceCell;
|
||||||
use crate::AGENT_CONFIG;
|
|
||||||
use crate::CDH_SOCKET_URI;
|
|
||||||
|
|
||||||
// Nanoseconds
|
// Nanoseconds
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref CDH_API_TIMEOUT: i64 = AGENT_CONFIG.cdh_api_timeout.as_nanos() as i64;
|
static ref CDH_API_TIMEOUT: i64 = AGENT_CONFIG.cdh_api_timeout.as_nanos() as i64;
|
||||||
|
pub static ref CDH_CLIENT: OnceCell<CDHClient> = OnceCell::new();
|
||||||
}
|
}
|
||||||
const SEALED_SECRET_PREFIX: &str = "sealed.";
|
const SEALED_SECRET_PREFIX: &str = "sealed.";
|
||||||
|
|
||||||
@ -90,6 +91,13 @@ impl CDHClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn init_cdh_client() -> Result<()> {
|
||||||
|
CDH_CLIENT
|
||||||
|
.get_or_try_init(|| async { CDHClient::new().context("Failed to create CDH Client") })
|
||||||
|
.await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[cfg(feature = "sealed-secret")]
|
#[cfg(feature = "sealed-secret")]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user