From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id AD7241FF187 for ; Mon, 28 Jul 2025 08:45:52 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AEE6C1A3C4; Mon, 28 Jul 2025 08:47:09 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Date: Mon, 28 Jul 2025 08:46:43 +0200 Message-ID: <20250728064645.158414-9-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250728064645.158414-1-c.ebner@proxmox.com> References: <20250728064645.158414-1-c.ebner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1753685214455 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.045 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 4/6] api: config s3: add bucket list api endpoint X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" This endpoint allows to list buckets accessible given the provided endpoint configuration. The bucket list is intended to be used for ease of datastore setup by providing a list of bucket names to the user in the frontend. Signed-off-by: Christian Ebner --- src/api2/config/s3.rs | 48 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/src/api2/config/s3.rs b/src/api2/config/s3.rs index 04b801028..047bf1fb1 100644 --- a/src/api2/config/s3.rs +++ b/src/api2/config/s3.rs @@ -5,8 +5,8 @@ use serde_json::Value; use proxmox_router::{http_bail, Permission, Router, RpcEnvironment}; use proxmox_s3_client::{ - S3ClientConf, S3ClientConfig, S3ClientConfigUpdater, S3ClientConfigWithoutSecret, - S3_CLIENT_ID_SCHEMA, + S3BucketListItem, S3Client, S3ClientConf, S3ClientConfig, S3ClientConfigUpdater, + S3ClientConfigWithoutSecret, S3ClientOptions, S3_CLIENT_ID_SCHEMA, }; use proxmox_schema::{api, param_bail, ApiType}; @@ -273,6 +273,45 @@ pub fn delete_s3_client_config( s3::save_config(&config) } +#[api( + input: { + properties: { + id: { + schema: S3_CLIENT_ID_SCHEMA, + }, + }, + }, + access: { + permission: &Permission::Privilege(&[], PRIV_SYS_AUDIT, false), + }, +)] +/// List buckets accessible by given s3 client configuration +pub async fn list_buckets( + id: String, + _rpcenv: &mut dyn RpcEnvironment, +) -> Result, Error> { + let (config, _digest) = pbs_config::s3::config()?; + let config: S3ClientConf = config + .lookup(S3_CFG_TYPE_ID, &id) + .context("config lookup failed")?; + + let empty_prefix = String::new(); + let options = + S3ClientOptions::from_config(config.config, config.secret_key, None, empty_prefix); + let client = S3Client::new(options).context("client creation failed")?; + let list_buckets_response = client + .list_buckets() + .await + .context("failed to list buckets")?; + let buckets = list_buckets_response + .buckets + .into_iter() + .map(|bucket| S3BucketListItem { name: bucket.name }) + .collect(); + + Ok(buckets) +} + // Check if the configured s3 client is still in-use by a datastore backend. // // If so, return the first datastore name with the configured client. @@ -294,10 +333,13 @@ fn s3_client_in_use(id: &str) -> Result, Error> { Ok(None) } +const LIST_BUCKETS_ROUTER: Router = Router::new().get(&API_METHOD_LIST_BUCKETS); + const ITEM_ROUTER: Router = Router::new() .get(&API_METHOD_READ_S3_CLIENT_CONFIG) .put(&API_METHOD_UPDATE_S3_CLIENT_CONFIG) - .delete(&API_METHOD_DELETE_S3_CLIENT_CONFIG); + .delete(&API_METHOD_DELETE_S3_CLIENT_CONFIG) + .subdirs(&[("list-buckets", &LIST_BUCKETS_ROUTER)]); pub const ROUTER: Router = Router::new() .get(&API_METHOD_LIST_S3_CLIENT_CONFIG) -- 2.47.2 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel