Skip to content

Commit

Permalink
confidential-data-hub: use LazyLock from std library
Browse files Browse the repository at this point in the history
LazyLock has been part of the standard library since 1.80.x
and is already used by other dependencies in this repository.

Replace lazy_static macro with LazyLock.

Signed-off-by: Mikko Ylinen <[email protected]>
  • Loading branch information
mythi authored and Xynnn007 committed Jan 3, 2025
1 parent 133efd0 commit 24d6936
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion confidential-data-hub/hub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ env_logger = { workspace = true, optional = true }
hex = { workspace = true, optional = true }
image-rs = { path = "../../image-rs", default-features = false, features = ["kata-cc-rustls-tls"] }
kbs_protocol = { path = "../../attestation-agent/kbs_protocol", default-features = false, features = ["passport", "aa_token", "openssl"], optional = true }
lazy_static.workspace = true
log.workspace = true
p12 = { version = "0.6.3", optional = true }
prost = { workspace = true, optional = true }
Expand Down
8 changes: 3 additions & 5 deletions confidential-data-hub/hub/src/kms/plugins/kbs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ mod sev;

mod offline_fs;

use std::{env, sync::Arc};
use std::{env, sync::Arc, sync::LazyLock};

use async_trait::async_trait;
use attestation_agent::config::aa_kbc_params::AaKbcParams;
use lazy_static::lazy_static;
pub use resource_uri::ResourceUri;
use tokio::sync::Mutex;

Expand Down Expand Up @@ -50,9 +49,8 @@ impl RealClient {
}
}

lazy_static! {
static ref KBS_CLIENT: Arc<Mutex<Option<RealClient>>> = Arc::new(Mutex::new(None));
}
static KBS_CLIENT: LazyLock<Arc<Mutex<Option<RealClient>>>> =
LazyLock::new(|| Arc::new(Mutex::new(None)));

#[async_trait]
pub trait Kbc: Send + Sync {
Expand Down
6 changes: 2 additions & 4 deletions confidential-data-hub/hub/src/kms/plugins/kbs/sev/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
//

use std::collections::HashMap;
use std::sync::LazyLock;

use async_trait::async_trait;
use base64::{engine::general_purpose::STANDARD, Engine};
use crypto::WrapType;
use lazy_static::lazy_static;
use resource_uri::ResourceUri;
use serde::Deserialize;
use tokio::{fs, sync::RwLock};
Expand All @@ -25,9 +25,7 @@ use super::keybroker::{

const KEYS_PATH: &str = "/sys/kernel/security/secrets/coco/1ee27366-0c87-43a6-af48-28543eaf7cb0";

lazy_static! {
static ref ONLINE_SEV_KBC: RwLock<Option<RealKbc>> = RwLock::new(None);
}
static ONLINE_SEV_KBC: LazyLock<RwLock<Option<RealKbc>>> = LazyLock::new(|| RwLock::new(None));

#[derive(Deserialize, Clone)]
struct Connection {
Expand Down

0 comments on commit 24d6936

Please sign in to comment.