Skip to content

Commit baaebad

Browse files
committed
kbs/as: use global kv-storage registry
Every key value storage instance should be alloced via `register_namespace` function. The global registry will help 1. provide an easy way to get a key value storage 2. manage instances Signed-off-by: Xynnn007 <xynnn@linux.alibaba.com>
1 parent 7054d83 commit baaebad

5 files changed

Lines changed: 34 additions & 41 deletions

File tree

attestation-service/src/lib.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,17 @@ pub struct AttestationService {
126126
impl AttestationService {
127127
/// Create a new Attestation Service instance.
128128
pub async fn new(config: Config) -> Result<Self, ServiceError> {
129-
let rvps = rvps::initialize_rvps_client(
130-
&config.rvps_config,
131-
config.storage_backend.storage_type,
132-
&config.storage_backend.backends,
129+
let rvps =
130+
rvps::initialize_rvps_client(&config.rvps_config, config.storage_backend.clone())
131+
.await
132+
.map_err(ServiceError::Rvps)?;
133+
134+
let policy_storage = key_value_storage::register_namespace(
135+
AS_POLICY_STORAGE_NAMESPACE,
136+
&config.storage_backend,
133137
)
134138
.await
135-
.map_err(ServiceError::Rvps)?;
136-
137-
let policy_storage = config
138-
.storage_backend
139-
.backends
140-
.to_client_with_namespace(
141-
config.storage_backend.storage_type,
142-
AS_POLICY_STORAGE_NAMESPACE,
143-
)
144-
.await?;
139+
.context("initialize policy storage")?;
145140
let token_broker =
146141
EarAttestationTokenBroker::new(config.attestation_token_broker.clone(), policy_storage)
147142
.await?;

attestation-service/src/rvps/builtin.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::{Result, RvpsApi};
22
use anyhow::Context;
33
use async_trait::async_trait;
44
use core::result::Result::Ok;
5-
use key_value_storage::{KeyValueStorageStructConfig, KeyValueStorageType};
5+
use key_value_storage::StorageBackendConfig;
66
use reference_value_provider_service::{
77
extractors::ExtractorsConfig, Rvps, REFERENCE_VALUE_STORAGE_NAMESPACE,
88
};
@@ -15,13 +15,14 @@ pub struct BuiltinRvps {
1515
impl BuiltinRvps {
1616
pub async fn new(
1717
config: Option<ExtractorsConfig>,
18-
storage_type: KeyValueStorageType,
19-
storage_config: &KeyValueStorageStructConfig,
18+
storage_backend_config: &StorageBackendConfig,
2019
) -> Result<Self> {
21-
let storage = storage_config
22-
.to_client_with_namespace(storage_type, REFERENCE_VALUE_STORAGE_NAMESPACE)
23-
.await
24-
.context("initialize RVPS storage")?;
20+
let storage = key_value_storage::register_namespace(
21+
REFERENCE_VALUE_STORAGE_NAMESPACE,
22+
storage_backend_config,
23+
)
24+
.await
25+
.context("initialize RVPS storage")?;
2526
let rvps = Rvps::new_with_storage(config, storage)
2627
.await
2728
.context("initialize RVPS")?;

attestation-service/src/rvps/mod.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use std::sync::Arc;
77

8-
use key_value_storage::{KeyValueStorageStructConfig, KeyValueStorageType};
8+
use key_value_storage::{KeyValueStorageType, StorageBackendConfig};
99
pub use reference_value_provider_service::config::Config as RvpsCrateConfig;
1010
use reference_value_provider_service::extractors::ExtractorsConfig;
1111
use serde::Deserialize;
@@ -85,8 +85,7 @@ pub type RvpsClient = Arc<Mutex<dyn RvpsApi + Send + Sync>>;
8585
#[instrument(skip_all, name = "Initialize RVPS")]
8686
pub async fn initialize_rvps_client(
8787
config: &RvpsConfig,
88-
unified_storage_type: KeyValueStorageType,
89-
storage_config: &KeyValueStorageStructConfig,
88+
mut storage_backend_config: StorageBackendConfig,
9089
) -> Result<RvpsClient> {
9190
match config {
9291
RvpsConfig::BuiltIn {
@@ -95,12 +94,12 @@ pub async fn initialize_rvps_client(
9594
} => {
9695
info!("launch a built-in RVPS.");
9796

98-
// Use RVPS-specific storage if provided, otherwise fall back to defaults
99-
let actual_storage_type = storage_type.unwrap_or(unified_storage_type);
97+
if let Some(storage_type) = storage_type {
98+
storage_backend_config.storage_type = *storage_type;
99+
}
100100

101101
Ok(Arc::new(Mutex::new(
102-
builtin::BuiltinRvps::new(extractors.clone(), actual_storage_type, storage_config)
103-
.await?,
102+
builtin::BuiltinRvps::new(extractors.clone(), &storage_backend_config).await?,
104103
)) as RvpsClient)
105104
}
106105
#[cfg(feature = "rvps-grpc")]

kbs/src/api_server.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,11 @@ impl ApiServer {
9090
"Using storage backend type: {:?}",
9191
config.storage_backend.storage_type
9292
);
93-
let policy_storage_backend = config
94-
.storage_backend
95-
.backends
96-
.to_client_with_namespace(config.storage_backend.storage_type, KBS_STORAGE_NAMESPACE)
97-
.await
98-
.map_err(|e| Error::StorageBackendInitialization { source: e })?;
93+
let policy_storage_backend =
94+
key_value_storage::register_namespace(KBS_STORAGE_NAMESPACE, &config.storage_backend)
95+
.await
96+
.map_err(|e| Error::StorageBackendInitialization { source: e })?;
97+
9998
let policy_engine = PolicyEngine::new(policy_storage_backend);
10099

101100
policy_engine

kbs/src/plugins/implementations/resource/backend.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,12 @@ impl ResourceStorage {
111111
) -> Result<Self> {
112112
match value {
113113
RepositoryConfig::KvStorage => {
114-
let storage = storage_backend_config
115-
.backends
116-
.to_client_with_namespace(
117-
storage_backend_config.storage_type,
118-
RESOURCE_STORAGE_NAMESPACE,
119-
)
120-
.await?;
114+
let storage = key_value_storage::register_namespace(
115+
RESOURCE_STORAGE_NAMESPACE,
116+
storage_backend_config,
117+
)
118+
.await?;
119+
121120
let backend = kv_storage::KvStorage::new(storage);
122121
Ok(Self {
123122
backend: Arc::new(backend),

0 commit comments

Comments
 (0)