iceberg/encryption/kms/factory.rs
1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18//! Factory trait for creating [`KeyManagementClient`] instances.
19
20use std::collections::HashMap;
21use std::fmt::Debug;
22use std::sync::Arc;
23
24use async_trait::async_trait;
25
26use super::KeyManagementClient;
27use crate::Result;
28
29/// Factory for creating a [`KeyManagementClient`] from catalog properties.
30///
31/// Replaces Java's reflection-based `encryption.kms-impl` + `initialize(properties)`
32/// pattern. Users provide an implementation of this trait to the catalog builder via
33/// [`CatalogBuilder::with_kms_client_factory`](crate::CatalogBuilder::with_kms_client_factory).
34///
35/// The catalog calls [`create_kms_client`](Self::create_kms_client) **once** during
36/// catalog initialization with the catalog's properties. The resulting client is
37/// shared across all tables in the catalog and passed to each table's
38/// [`EncryptionManager`](crate::encryption::EncryptionManager) via
39/// `TableBuilder::kms_client(...)`.
40#[async_trait]
41pub trait KmsClientFactory: Debug + Send + Sync {
42 /// Create a [`KeyManagementClient`] from catalog properties.
43 ///
44 /// Called once during catalog initialization. Properties may include
45 /// KMS endpoint, region, credentials, or any backend-specific
46 /// configuration needed to construct the client.
47 async fn create_kms_client(
48 &self,
49 properties: &HashMap<String, String>,
50 ) -> Result<Arc<dyn KeyManagementClient>>;
51}