agent:cdh: initialize cdhclient with the input cdh socket uri

Refactor cdh code to initialize cdhclient with the input cdh socket uri.

Signed-off-by: ChengyuZhu6 <chengyu.zhu@intel.com>
This commit is contained in:
ChengyuZhu6 2024-09-30 12:51:31 +08:00
parent 1f33fd4cd4
commit 974d6b0736
2 changed files with 7 additions and 6 deletions

View File

@ -8,7 +8,6 @@
// https://github.com/confidential-containers/guest-components/tree/main/confidential-data-hub
use crate::AGENT_CONFIG;
use crate::CDH_SOCKET_URI;
use anyhow::{bail, Context, Result};
use derivative::Derivative;
use protocols::{
@ -43,8 +42,8 @@ pub struct CDHClient {
}
impl CDHClient {
pub fn new() -> Result<Self> {
let client = ttrpc::asynchronous::Client::connect(CDH_SOCKET_URI)?;
pub fn new(cdh_socket_uri: &str) -> Result<Self> {
let client = ttrpc::asynchronous::Client::connect(cdh_socket_uri)?;
let sealed_secret_client =
confidential_data_hub_ttrpc_async::SealedSecretServiceClient::new(client.clone());
let secure_mount_client =
@ -87,9 +86,11 @@ impl CDHClient {
}
}
pub async fn init_cdh_client() -> Result<()> {
pub async fn init_cdh_client(cdh_socket_uri: &str) -> Result<()> {
CDH_CLIENT
.get_or_try_init(|| async { CDHClient::new().context("Failed to create CDH Client") })
.get_or_try_init(|| async {
CDHClient::new(cdh_socket_uri).context("Failed to create CDH Client")
})
.await?;
Ok(())
}

View File

@ -498,7 +498,7 @@ async fn init_attestation_components(logger: &Logger, config: &AgentConfig) -> R
.map_err(|e| anyhow!("launch_process {} failed: {:?}", CDH_PATH, e))?;
// initialize cdh client
cdh::init_cdh_client().await?;
cdh::init_cdh_client(CDH_SOCKET_URI).await?;
// skip launch of api-server-rest
if config.guest_components_procs == GuestComponentsProcs::ConfidentialDataHub {