sumeetgajjar commented on code in PR #4465: URL: https://github.com/apache/iceberg/pull/4465#discussion_r842215709
########## azure/src/main/java/org/apache/iceberg/azure/blob/AzureBlobClientFactory.java: ########## @@ -0,0 +1,86 @@ +/* + * 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. + */ + +package org.apache.iceberg.azure.blob; + +import com.azure.core.credential.AzureSasCredential; +import com.azure.storage.blob.BlobClient; +import com.azure.storage.blob.BlobClientBuilder; +import com.azure.storage.common.StorageSharedKeyCredential; +import java.util.Optional; +import org.apache.iceberg.azure.AuthType; +import org.apache.iceberg.azure.AzureProperties; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AzureBlobClientFactory { + + private static final Logger LOG = LoggerFactory.getLogger(AzureBlobClientFactory.class); + + private AzureBlobClientFactory() { + } + + public static BlobClient createBlobClient(AzureURI azureURI, AzureProperties azureProperties) { + final String storageAccount = azureURI.storageAccount(); + final BlobClientBuilder builder = new BlobClientBuilder(); + + final Optional<String> connectionString = azureProperties.connectionString(storageAccount); + // Connection string should contain storage endpoint and required auth properties. + if (connectionString.isPresent()) { + LOG.debug("Using azure storage connection string to build the blob client for {}", storageAccount); + Preconditions.checkArgument(!connectionString.get().isEmpty(), "Connection string cannot be empty."); + builder.connectionString(connectionString.get()); + } else { + final String endpoint = storageEndpoint(storageAccount, azureProperties); + LOG.debug("Using {} endpoint for {}", endpoint, storageAccount); + builder.endpoint(endpoint); + final AuthType authType = azureProperties.authType(storageAccount); + setAuth(storageAccount, authType, azureProperties, builder); Review Comment: The general form of a connection is as follows: ``` DefaultEndpointsProtocol=http;AccountName=devstoreaccount1; AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==; BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1; QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1; TableEndpoint=http://127.0.0.1:10002/devstoreaccount1; ``` Thus the connection string contains all the necessary auth-related and storage account endpoints information required for establishing a connection and hence it is not necessary to explicitly set the auth. https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string#configure-a-connection-string-for-an-azure-storage-account Note: the above connection string does not leak any actual keys, it is the default connection string used by the Azurite Emulator thus safe to share on public forums. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
