ryerraguntla commented on code in PR #3103:
URL: https://github.com/apache/iggy/pull/3103#discussion_r3431428797


##########
core/connectors/sinks/s3_sink/src/client.rs:
##########
@@ -0,0 +1,168 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::S3SinkConfig;
+use iggy_connector_sdk::Error;
+use s3::creds::Credentials;
+use s3::{Bucket, Region};
+use secrecy::ExposeSecret;
+use tracing::info;
+
+pub(crate) async fn create_bucket(config: &S3SinkConfig) -> 
Result<Box<Bucket>, Error> {
+    if config.access_key_id.is_some() != config.secret_access_key.is_some() {
+        return Err(Error::InvalidConfigValue(
+            "Partially configured credentials. You must provide both 
access_key_id \
+             and secret_access_key, or omit both."
+                .to_owned(),
+        ));
+    }
+
+    let credentials = match (&config.access_key_id, &config.secret_access_key) 
{
+        (Some(key), Some(secret)) => {
+            let key_len = key.expose_secret().len();
+            info!("Using explicit S3 credentials (key length: {key_len} 
chars)");
+            Credentials::new(
+                Some(key.expose_secret()),
+                Some(secret.expose_secret()),
+                None,
+                None,
+                None,
+            )
+            .map_err(|e| Error::InitError(format!("Failed to create S3 
credentials: {e}")))?
+        }
+        _ => {
+            info!(
+                "No explicit credentials provided, using default credential 
chain (env vars / instance profile)"
+            );
+            Credentials::default().map_err(|e| {
+                Error::InitError(format!("Failed to load default S3 
credentials: {e}"))
+            })?
+        }
+    };
+
+    let region = match &config.endpoint {
+        Some(endpoint) => {
+            info!("Using custom S3 endpoint: {endpoint}");
+            Region::Custom {
+                region: config.region.clone(),
+                endpoint: endpoint.clone(),
+            }
+        }
+        None => config.region.parse::<Region>().map_err(|e| {
+            Error::InvalidConfigValue(format!("Invalid S3 region '{}': {e}", 
config.region))
+        })?,
+    };
+
+    let mut bucket = Bucket::new(&config.bucket, region, credentials)
+        .map_err(|e| Error::InitError(format!("Failed to create S3 bucket 
handle: {e}")))?;
+
+    let use_path_style = 
config.path_style.unwrap_or(config.endpoint.is_some());
+    if use_path_style {
+        bucket.set_path_style();
+    }
+
+    Ok(bucket)
+}
+
+/// Verify bucket connectivity by listing zero objects. Fatal on failure.

Review Comment:
   **[nit]** verify_bucket — uses bucket.list_page(...) to verify connectivity:
   
   ```
   bucket
       .list_page("".to_string(), None, None, None, Some(1))
       .await
   ```
   This requires s3:ListBucket IAM permission. Write-only IAM policies (common 
for data-pipeline roles) that grant only s3:PutObject will fail open() with 
InitError. A HeadBucket call (or a zero-byte PutObject to a probe key) requires 
only s3:GetBucketLocation or s3:PutObject. Consider bucket.head_object or 
simply skip verification and let the first put_object call surface the error. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to