s3util-rs 1.4.0

Tools for managing Amazon S3 objects and buckets
Documentation
use anyhow::Result;
use tracing::info;

use s3util_rs::config::ClientConfig;
use s3util_rs::config::args::get_bucket_accelerate_configuration::GetBucketAccelerateConfigurationArgs;
use s3util_rs::output::json::get_bucket_accelerate_configuration_to_json;
use s3util_rs::storage::s3::api::{self, HeadError};

use super::ExitStatus;

/// Runtime entry for `s3util get-bucket-accelerate-configuration s3://<BUCKET>`.
///
/// Builds the SDK client from `client_config`, issues
/// `GetBucketAccelerateConfiguration`, and prints the response as
/// AWS-CLI-shape pretty-printed JSON followed by a newline. When the bucket
/// has never had Transfer Acceleration configured, the response is empty
/// and nothing is printed (matches `aws s3api`).
/// Returns `ExitStatus::NotFound` (exit code 4) when S3 reports `NoSuchBucket`.
pub async fn run_get_bucket_accelerate_configuration(
    args: GetBucketAccelerateConfigurationArgs,
    client_config: ClientConfig,
) -> Result<ExitStatus> {
    let bucket = args
        .bucket_name()
        .map_err(|e| anyhow::anyhow!("{}", e.trim_end()))?;
    let client = client_config.create_client().await;
    match api::get_bucket_accelerate_configuration(&client, &bucket).await {
        Ok(out) => {
            let json = get_bucket_accelerate_configuration_to_json(&out);
            if json.as_object().is_some_and(|m| m.is_empty()) {
                info!(bucket = %bucket, "Bucket Transfer Acceleration not configured.");
            } else {
                let pretty = serde_json::to_string_pretty(&json)?;
                println!("{pretty}");
            }
            Ok(ExitStatus::Success)
        }
        Err(HeadError::BucketNotFound) | Err(HeadError::NotFound) => {
            tracing::error!("bucket s3://{bucket} not found");
            Ok(ExitStatus::NotFound)
        }
        Err(HeadError::Other(e)) => Err(e),
    }
}