[pbs-devel] [PATCH proxmox 1/1] s3 client: split config api type into 3 config structs
Christian Ebner
c.ebner at proxmox.com
Tue Jul 22 18:36:01 CEST 2025
Splitting the config into 3 structs allows to use them once with
the full config, once without the password and once to only
serialize/deserialize when writing the config.
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
proxmox-s3-client/src/api_types.rs | 62 ++++++++++++++++++++++++------
proxmox-s3-client/src/client.rs | 3 +-
2 files changed, 52 insertions(+), 13 deletions(-)
diff --git a/proxmox-s3-client/src/api_types.rs b/proxmox-s3-client/src/api_types.rs
index 51f71d84..e05ad0f9 100644
--- a/proxmox-s3-client/src/api_types.rs
+++ b/proxmox-s3-client/src/api_types.rs
@@ -82,9 +82,6 @@ pub const S3_BUCKET_NAME_SCHEMA: Schema = StringSchema::new("Bucket name for S3
#[api(
properties: {
- id: {
- schema: S3_CLIENT_ID_SCHEMA,
- },
endpoint: {
schema: S3_ENDPOINT_SCHEMA,
},
@@ -103,9 +100,6 @@ pub const S3_BUCKET_NAME_SCHEMA: Schema = StringSchema::new("Bucket name for S3
"access-key": {
type: String,
},
- "secret-key": {
- type: String,
- },
"path-style": {
type: bool,
optional: true,
@@ -115,15 +109,12 @@ pub const S3_BUCKET_NAME_SCHEMA: Schema = StringSchema::new("Bucket name for S3
type: u64,
optional: true,
},
- }
+ },
)]
#[derive(Serialize, Deserialize, Updater, Clone, PartialEq)]
#[serde(rename_all = "kebab-case")]
/// S3 client configuration properties.
pub struct S3ClientConfig {
- /// ID to identify s3 client config.
- #[updater(skip)]
- pub id: String,
/// Endpoint to access S3 object store.
pub endpoint: String,
/// Port to access S3 object store.
@@ -137,8 +128,6 @@ pub struct S3ClientConfig {
pub fingerprint: Option<String>,
/// Access key for S3 object store.
pub access_key: String,
- /// Secret key for S3 object store.
- pub secret_key: String,
/// Use path style bucket addressing over vhost style.
#[serde(skip_serializing_if = "Option::is_none")]
pub path_style: Option<bool>,
@@ -154,3 +143,52 @@ impl S3ClientConfig {
Vec::new()
}
}
+
+#[api(
+ properties: {
+ id: {
+ schema: S3_CLIENT_ID_SCHEMA,
+ },
+ config: {
+ type: S3ClientConfig,
+ },
+ "secret-key": {
+ type: String,
+ },
+ },
+)]
+#[derive(Serialize, Deserialize, Updater, Clone, PartialEq)]
+#[serde(rename_all = "kebab-case")]
+/// S3 client configuration.
+pub struct S3ClientConf {
+ /// ID to identify s3 client config.
+ #[updater(skip)]
+ pub id: String,
+ /// S3 client config.
+ #[serde(flatten)]
+ pub config: S3ClientConfig,
+ /// Secret key for S3 object store.
+ pub secret_key: String,
+}
+
+
+#[api(
+ properties: {
+ id: {
+ schema: S3_CLIENT_ID_SCHEMA,
+ },
+ config: {
+ type: S3ClientConfig,
+ },
+ },
+)]
+#[derive(Serialize, Deserialize, Clone, PartialEq)]
+#[serde(rename_all = "kebab-case")]
+/// S3 client configuration properties without secret.
+pub struct S3ClientConfigWithoutSecret {
+ /// ID to identify s3 client config.
+ pub id: String,
+ /// S3 client config.
+ #[serde(flatten)]
+ pub config: S3ClientConfig,
+}
diff --git a/proxmox-s3-client/src/client.rs b/proxmox-s3-client/src/client.rs
index f418ee39..eb5fc7d9 100644
--- a/proxmox-s3-client/src/client.rs
+++ b/proxmox-s3-client/src/client.rs
@@ -75,6 +75,7 @@ impl S3ClientOptions {
/// Construct options for the S3 client give the provided configuration parameters.
pub fn from_config(
config: S3ClientConfig,
+ secret_key: String,
bucket: String,
common_prefix: String,
) -> Self {
@@ -87,7 +88,7 @@ impl S3ClientOptions {
region: config.region.unwrap_or("us-west-1".to_string()),
fingerprint: config.fingerprint,
access_key: config.access_key,
- secret_key: config.secret_key,
+ secret_key,
put_rate_limit: config.put_rate_limit,
}
}
--
2.47.2
More information about the pbs-devel
mailing list