shefali163 commented on code in PR #12914: URL: https://github.com/apache/arrow/pull/12914#discussion_r924782468
########## cpp/src/arrow/filesystem/azurefs.cc: ########## @@ -0,0 +1,1722 @@ +// 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. + +#include "arrow/filesystem/azurefs.h" + +#include <algorithm> +#include <atomic> +#include <azure/core/credentials/credentials.hpp> +#include <azure/identity/client_secret_credential.hpp> +#include <azure/identity/managed_identity_credential.hpp> +#include <azure/storage/blobs.hpp> +#include <azure/storage/files/datalake.hpp> +#include <chrono> +#include <condition_variable> +#include <functional> +#include <memory> +#include <mutex> +#include <sstream> +#include <thread> +#include <unordered_map> +#include <utility> + +#include "arrow/util/windows_fixup.h" + +#include "arrow/buffer.h" +#include "arrow/filesystem/filesystem.h" +#include "arrow/filesystem/path_util.h" +#include "arrow/filesystem/util_internal.h" +#include "arrow/io/interfaces.h" +#include "arrow/io/memory.h" +#include "arrow/io/util_internal.h" +#include "arrow/result.h" +#include "arrow/status.h" +#include "arrow/util/async_generator.h" +#include "arrow/util/atomic_shared_ptr.h" +#include "arrow/util/checked_cast.h" +#include "arrow/util/future.h" +#include "arrow/util/key_value_metadata.h" +#include "arrow/util/logging.h" +#include "arrow/util/optional.h" +#include "arrow/util/task_group.h" +#include "arrow/util/thread_pool.h" + +namespace arrow { + +using internal::Uri; + +namespace fs { + +static const char kSep = '/'; + +// ----------------------------------------------------------------------- +// AzureOptions implementation + +AzureOptions::AzureOptions() {} + +std::string AzureOptions::GetAccountNameFromConnectionString( + const std::string& connectionString) { + std::map<std::string, std::string> connectionStringMap; + std::string::const_iterator cur = connectionString.begin(); + + while (cur != connectionString.end()) { + auto key_begin = cur; + auto key_end = std::find(cur, connectionString.end(), '='); + std::string key = std::string(key_begin, key_end); + cur = key_end; + if (cur != connectionString.end()) { + ++cur; + } + auto value_begin = cur; + auto value_end = std::find(cur, connectionString.end(), ';'); + std::string value = std::string(value_begin, value_end); + cur = value_end; + if (cur != connectionString.end()) { + ++cur; + } + if (!key.empty() || !value.empty()) { + connectionStringMap[std::move(key)] = std::move(value); + } + } + + auto getWithDefault = [](const std::map<std::string, std::string>& m, + const std::string& key, + const std::string& defaultValue = std::string()) { + auto ite = m.find(key); + return ite == m.end() ? defaultValue : ite->second; + }; + + std::string accountName = getWithDefault(connectionStringMap, "AccountName"); + if (accountName.empty()) { + throw std::runtime_error("Cannot find account name in connection string."); + } + return accountName; +} + +void AzureOptions::ConfigureAnonymousCredentials(const std::string& account_name) { + account_dfs_url = "https://" + account_name + ".dfs.core.windows.net/"; + account_blob_url = "https://" + account_name + ".blob.core.windows.net/"; + credentials_kind = AzureCredentialsKind::Anonymous; +} + +void AzureOptions::ConfigureAccountKeyCredentials(const std::string& account_name, + const std::string& account_key) { + account_dfs_url = "https://" + account_name + ".dfs.core.windows.net/"; + account_blob_url = "https://" + account_name + ".blob.core.windows.net/"; + storage_credentials_provider = + std::make_shared<Azure::Storage::StorageSharedKeyCredential>(account_name, + account_key); + credentials_kind = AzureCredentialsKind::StorageCredentials; +} + +void AzureOptions::ConfigureConnectionStringCredentials( + const std::string& connection_string_uri) { + auto account_name = GetAccountNameFromConnectionString(connection_string_uri); Review Comment: It parses an Azure Blob Storage connection string, https://docs.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string -- 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]
