hubcio commented on code in PR #2889: URL: https://github.com/apache/iggy/pull/2889#discussion_r3140609209
########## core/connectors/sinks/delta_sink/src/storage.rs: ########## @@ -0,0 +1,313 @@ +/* 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::{DeltaSinkConfig, StorageBackendType}; +use iggy_connector_sdk::Error; +use secrecy::ExposeSecret; +use std::collections::HashMap; + +pub(crate) fn build_storage_options( + config: &DeltaSinkConfig, +) -> Result<HashMap<String, String>, Error> { + let mut opts = HashMap::new(); + + match config.storage_backend_type { + Some(StorageBackendType::S3) => { + let access_key = config.aws_s3_access_key.as_ref().ok_or_else(|| { + Error::InitError("S3 backend requires 'aws_s3_access_key'".into()) + })?; + let secret_key = config.aws_s3_secret_key.as_ref().ok_or_else(|| { + Error::InitError("S3 backend requires 'aws_s3_secret_key'".into()) + })?; + let region = config + .aws_s3_region + .as_ref() + .ok_or_else(|| Error::InitError("S3 backend requires 'aws_s3_region'".into()))?; + + opts.insert("AWS_ACCESS_KEY_ID".into(), access_key.clone()); + opts.insert( + "AWS_SECRET_ACCESS_KEY".into(), + secret_key.expose_secret().to_owned(), + ); + opts.insert("AWS_REGION".into(), region.clone()); + + if let Some(endpoint_url) = config.aws_s3_endpoint_url.as_ref() { + opts.insert("AWS_ENDPOINT_URL".into(), endpoint_url.clone()); + } + if let Some(allow_http) = config.aws_s3_allow_http { + opts.insert("AWS_ALLOW_HTTP".into(), allow_http.to_string()); + opts.insert("AWS_S3_ALLOW_HTTP".into(), allow_http.to_string()); + } + } + Some(StorageBackendType::Azure) => { + let account_name = config.azure_storage_account_name.as_ref().ok_or_else(|| { + Error::InitError("Azure backend requires 'azure_storage_account_name'".into()) + })?; + let container_name = config.azure_container_name.as_ref().ok_or_else(|| { + Error::InitError("Azure backend requires 'azure_container_name'".into()) + })?; + + opts.insert("AZURE_STORAGE_ACCOUNT_NAME".into(), account_name.clone()); + opts.insert("AZURE_CONTAINER_NAME".into(), container_name.clone()); + + match ( + config.azure_storage_account_key.as_ref(), + config.azure_storage_sas_token.as_ref(), + ) { + (Some(key), None) => { + opts.insert( + "AZURE_STORAGE_ACCOUNT_KEY".into(), + key.expose_secret().to_owned(), + ); + } + (None, Some(sas)) => { + opts.insert( + "AZURE_STORAGE_SAS_TOKEN".into(), + sas.expose_secret().to_owned(), + ); + } + (Some(_), Some(_)) => { + return Err(Error::InitError("Azure backend requires exactly one of 'azure_storage_account_key' or 'azure_storage_sas_token', but both were provided".into())); + } + (None, None) => { + return Err(Error::InitError("Azure backend requires one of 'azure_storage_account_key' or 'azure_storage_sas_token'".into())); + } + } + } + Some(StorageBackendType::Gcs) => { + let service_account_key = config.gcs_service_account_key.as_ref().ok_or_else(|| { + Error::InitError("GCS backend requires 'gcs_service_account_key'".into()) + })?; + let bucket = config + .gcs_bucket + .as_ref() + .ok_or_else(|| Error::InitError("GCS backend requires 'gcs_bucket'".into()))?; + + opts.insert( + "GOOGLE_SERVICE_ACCOUNT_KEY".into(), + service_account_key.expose_secret().to_owned(), + ); + opts.insert("GCS_BUCKET".into(), bucket.clone()); Review Comment: this option is silently dropped. `deltalake-gcp` (both 0.14.0 currently pinned and 0.16.0 latest) maps storage_options through `GoogleConfigKey::from_str(key.to_ascii_lowercase()).ok()?` inside a `filter_map`, and `object_store-0.12.5/src/gcp/builder.rs:197` only accepts `google_bucket | google_bucket_name | bucket | bucket_name` — `gcs_bucket` doesn't match and gets filtered out. bumping deltalake won't fix it; the rejection is in `object_store`. the bucket actually comes from the `gs://bucket/...` url via `GoogleCloudStorageBuilder::new().with_url(...)`. rename to `google_bucket` (or just `bucket`) to match the upstream key, or drop the field + the readme entry. (azure's `AZURE_CONTAINER_NAME` at line 66 does work — `object_store-0.12.5/src/azure/builder.rs:459` accepts `azure_container_name | container_name`.) -- 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]
