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


##########
core/connectors/sinks/s3_sink/src/client.rs:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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 tracing::info;
+
+fn validate_credential_pair(config: &S3SinkConfig) -> Result<(), 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(),
+        ));
+    }
+    Ok(())
+}
+
+pub async fn create_bucket(config: &S3SinkConfig) -> Result<Box<Bucket>, 
Error> {
+    validate_credential_pair(config)?;
+
+    let credentials = match (&config.access_key_id, &config.secret_access_key) 
{
+        (Some(key), Some(secret)) => {
+            let redacted_key = key.chars().take(3).collect::<String>();

Review Comment:
   Now logging `key.len()` only, no prefix chars exposed



##########
core/connectors/sinks/s3_sink/src/client.rs:
##########
@@ -0,0 +1,154 @@
+/*
+ * 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 tracing::info;
+
+fn validate_credential_pair(config: &S3SinkConfig) -> Result<(), 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(),
+        ));
+    }
+    Ok(())
+}
+
+pub async fn create_bucket(config: &S3SinkConfig) -> Result<Box<Bucket>, 
Error> {
+    validate_credential_pair(config)?;
+
+    let credentials = match (&config.access_key_id, &config.secret_access_key) 
{
+        (Some(key), Some(secret)) => {
+            let redacted_key = key.chars().take(3).collect::<String>();
+            info!("Using explicit S3 credentials (access key: 
{redacted_key}***)");
+            Credentials::new(Some(key), Some(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)
+}
+
+pub async fn verify_bucket(bucket: &Bucket) -> Result<(), Error> {
+    bucket.head_object("/").await.map_err(|e| {

Review Comment:
   Replaced with `bucket.list_page(..., Some(1))`, failure is now fatal in 
`open()`



-- 
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