diff --git a/fbpcf/io/cloud_util/CloudFileUtil.cpp b/fbpcf/io/cloud_util/CloudFileUtil.cpp index 8097c751..465b786e 100644 --- a/fbpcf/io/cloud_util/CloudFileUtil.cpp +++ b/fbpcf/io/cloud_util/CloudFileUtil.cpp @@ -5,12 +5,15 @@ * LICENSE file in the root directory of this source tree. */ -#include "fbpcf/io/cloud_util/CloudFileUtil.h" #include +#include #include + #include "fbpcf/aws/S3Util.h" #include "fbpcf/exception/PcfException.h" #include "fbpcf/gcp/GCSUtil.h" +#include "fbpcf/io/cloud_util/CloudFileUtil.h" +#include "fbpcf/io/cloud_util/GCSClient.h" #include "fbpcf/io/cloud_util/GCSFileReader.h" #include "fbpcf/io/cloud_util/GCSFileUploader.h" #include "fbpcf/io/cloud_util/S3Client.h" @@ -65,7 +68,10 @@ std::unique_ptr getCloudFileReader(const std::string& filePath) { fbpcf::aws::S3ClientOption{.region = ref.region}) .getS3Client()); } else if (fileType == CloudFileType::GCS) { - return std::make_unique(fbpcf::gcp::createGCSClient()); + const auto& ref = fbpcf::gcp::uriToObjectReference(filePath); + return std::make_unique( + fbpcf::cloudio::GCSClient::getInstance(fbpcf::gcp::GCSClientOption{}) + .getGCSClient()); } else { throw fbpcf::PcfException("Not supported yet."); } @@ -82,8 +88,11 @@ std::unique_ptr getCloudFileUploader( .getS3Client(), filePath); } else if (fileType == CloudFileType::GCS) { + const auto& ref = fbpcf::gcp::uriToObjectReference(filePath); return std::make_unique( - fbpcf::gcp::createGCSClient(), filePath); + fbpcf::cloudio::GCSClient::getInstance(fbpcf::gcp::GCSClientOption{}) + .getGCSClient(), + filePath); } else { throw fbpcf::PcfException("Not supported yet."); } diff --git a/fbpcf/io/cloud_util/GCSClient.cpp b/fbpcf/io/cloud_util/GCSClient.cpp new file mode 100644 index 00000000..06829fc0 --- /dev/null +++ b/fbpcf/io/cloud_util/GCSClient.cpp @@ -0,0 +1,17 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include + +#include "fbpcf/io/cloud_util/GCSClient.h" + +namespace fbpcf::cloudio { +GCSClient& GCSClient::getInstance(const fbpcf::gcp::GCSClientOption& option) { + static GCSClient GCSClient(option); + return GCSClient; +} +} // namespace fbpcf::cloudio diff --git a/fbpcf/io/cloud_util/GCSClient.h b/fbpcf/io/cloud_util/GCSClient.h new file mode 100644 index 00000000..049ff171 --- /dev/null +++ b/fbpcf/io/cloud_util/GCSClient.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +#include + +#include +#include "fbpcf/gcp/GCSUtil.h" + +namespace fbpcf::cloudio { + +class GCSClient { + private: + explicit GCSClient(const fbpcf::gcp::GCSClientOption& option) { + GCSClient_ = fbpcf::gcp::createGCSClient(); + } + + public: + static GCSClient& getInstance(const fbpcf::gcp::GCSClientOption& option); + + std::shared_ptr getGCSClient() { + return GCSClient_; + } + + private: + std::shared_ptr GCSClient_; +}; + +} // namespace fbpcf::cloudio