martinzink commented on code in PR #2153:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2153#discussion_r3022821925


##########
extensions/gcp/controllerservices/GCPCredentialsControllerService.cpp:
##########
@@ -18,34 +18,36 @@
 
 #include "GCPCredentialsControllerService.h"
 
-#include "core/Resource.h"
 #include "google/cloud/storage/client.h"
-#include "utils/ProcessorConfigUtils.h"
-#include "utils/file/FileUtils.h"
 
 namespace org::apache::nifi::minifi::extensions::gcp {
 
-void GCPCredentialsControllerService::initialize() {
-  setSupportedProperties(Properties);
+namespace {
+// TODO(MINIFICPP-2763) use utils::file::get_content instead
+std::string get_content(const std::filesystem::path& file_name) {
+  std::ifstream file(file_name, std::ifstream::binary);
+  std::string content((std::istreambuf_iterator<char>(file)), 
std::istreambuf_iterator<char>());
+  return content;
+}

Review Comment:
   its not regression so we dont care about that there is already a ticket to 
refactor fileutils



##########
extensions/gcp/controllerservices/GCPCredentialsControllerService.cpp:
##########
@@ -18,34 +18,36 @@
 
 #include "GCPCredentialsControllerService.h"
 
-#include "core/Resource.h"
 #include "google/cloud/storage/client.h"
-#include "utils/ProcessorConfigUtils.h"
-#include "utils/file/FileUtils.h"
 
 namespace org::apache::nifi::minifi::extensions::gcp {
 
-void GCPCredentialsControllerService::initialize() {
-  setSupportedProperties(Properties);
+namespace {
+// TODO(MINIFICPP-2763) use utils::file::get_content instead
+std::string get_content(const std::filesystem::path& file_name) {
+  std::ifstream file(file_name, std::ifstream::binary);
+  std::string content((std::istreambuf_iterator<char>(file)), 
std::istreambuf_iterator<char>());
+  return content;
+}
 }
 
-std::shared_ptr<google::cloud::Credentials> 
GCPCredentialsControllerService::createCredentialsFromJsonPath() const {
-  const auto json_path = getProperty(JsonFilePath.name);
+std::shared_ptr<google::cloud::Credentials> 
GCPCredentialsControllerService::createCredentialsFromJsonPath(api::core::ControllerServiceContext&
 ctx) const {
+  const auto json_path = ctx.getProperty(JsonFilePath.name);
   if (!json_path) {
     logger_->log_error("Missing or invalid {}", JsonFilePath.name);
     return nullptr;
   }
 
-  if (!utils::file::exists(*json_path)) {
+  if (std::error_code ec; !std::filesystem::exists(*json_path, ec) || ec) {
     logger_->log_error("JSON file for GCP credentials '{}' does not exist", 
*json_path);
     return nullptr;
   }
 
-  return 
google::cloud::MakeServiceAccountCredentials(utils::file::get_content(*json_path));
+  return google::cloud::MakeServiceAccountCredentials(get_content(*json_path));

Review Comment:
   its not regression so we dont care about that there is already a ticket to 
refactor fileutils



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