szaszm commented on a change in pull request #1178:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1178#discussion_r720214936



##########
File path: extensions/azure/storage/BlobStorageClient.h
##########
@@ -24,40 +24,23 @@
 #include <utility>
 #include <vector>
 
-namespace org {
-namespace apache {
-namespace nifi {
-namespace minifi {
-namespace azure {
-namespace storage {
+#include "azure/storage/blobs/protocol/blob_rest_client.hpp"
+#include "AzureStorageClient.h"
+#include "gsl/gsl-lite.hpp"
 
-struct UploadBlobResult {
-  std::string primary_uri;
-  std::string etag;
-  std::size_t length;
-  std::string timestamp;
+namespace org::apache::nifi::minifi::azure::storage {
+
+struct PutAzureBlobStorageParameters {
+  AzureStorageCredentials credentials;
+  std::string container_name;
+  std::string blob_name;
 };
 
-class BlobStorage {
+class BlobStorageClient : public AzureStorageClient {

Review comment:
       Please also update the file description comment on lines 2-3. Removing 
them is also fine for me.

##########
File path: extensions/azure/storage/AzureStorageCredentials.h
##########
@@ -21,53 +21,32 @@
 
 #include <string>
 
-#include "utils/StringUtils.h"
-
-namespace org {
-namespace apache {
-namespace nifi {
-namespace minifi {
-namespace azure {
-namespace storage {
-
-struct AzureStorageCredentials {
-  std::string storage_account_name;
-  std::string storage_account_key;
-  std::string sas_token;
-  std::string endpoint_suffix;
-  std::string connection_string;
-
-  std::string getConnectionString() const {
-    if (!connection_string.empty()) {
-      return connection_string;
-    }
-
-    if (storage_account_name.empty() || (storage_account_key.empty() && 
sas_token.empty())) {
-      return "";
-    }
-
-    std::string credentials;
-    credentials += "AccountName=" + storage_account_name;
-
-    if (!storage_account_key.empty()) {
-      credentials += ";AccountKey=" + storage_account_key;
-    }
-
-    if (!sas_token.empty()) {
-      credentials += ";SharedAccessSignature=" + (sas_token[0] == '?' ? 
sas_token.substr(1) : sas_token);
-    }
-
-    if (!endpoint_suffix.empty()) {
-      credentials += ";EndpointSuffix=" + endpoint_suffix;
-    }
-
-    return credentials;
-  }
+namespace org::apache::nifi::minifi::azure::storage {
+
+class AzureStorageCredentials {
+ public:
+  void setStorageAccountName(const std::string& storage_account_name);
+  void setStorageAccountKey(const std::string& storage_account_key);
+  void setSasToken(const std::string& sas_token);
+  void setEndpontSuffix(const std::string& endpoint_suffix);
+  void setConnectionString(const std::string& connection_string);
+  void setUseManagedIdentityCredentials(bool use_managed_identity_credentials);
+
+  std::string getStorageAccountName() const;
+  std::string getEndpointSuffix() const;
+  bool getUseManagedIdentityCredentials() const;
+  std::string buildConnectionString() const;
+  bool isValid() const;

Review comment:
       Providing both getters and setters for all private data members is not 
really different from just leaving them as public data members, so I wonder if 
this change is really an improvement, other than the addition of 
`use_managed_identity_credentials_`.

##########
File path: extensions/azure/storage/AzureStorageClient.h
##########
@@ -0,0 +1,34 @@
+/**
+ * @file AzureStorageClient.h
+ * AzureStorageClient class declaration
+ *
+ * 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.
+ */
+#pragma once
+
+#include "AzureStorageCredentials.h"
+
+namespace org::apache::nifi::minifi::azure::storage {
+
+class AzureStorageClient {
+ public:
+  virtual ~AzureStorageClient() = default;
+
+ protected:
+  AzureStorageCredentials credentials_;
+};

Review comment:
       This class doesn't seem to be used for polymorphism, but only for 
inheriting the credentials data member. I think it would be simpler to just 
include the credentials member in all of the classes that currently inherit 
from this, and remove `AzureStorageClient`.

##########
File path: extensions/azure/storage/AzureBlobStorage.cpp
##########
@@ -23,61 +23,39 @@
 #include <memory>
 #include <utility>
 
-namespace org {
-namespace apache {
-namespace nifi {
-namespace minifi {
-namespace azure {
-namespace storage {
+#include "azure/identity.hpp"
+#include "AzureBlobStorageClient.h"
 
-AzureBlobStorage::AzureBlobStorage(std::string connection_string, std::string 
container_name)
-  : BlobStorage(std::move(connection_string), std::move(container_name))
-  , 
container_client_(std::make_unique<Azure::Storage::Blobs::BlobContainerClient>(
-      
Azure::Storage::Blobs::BlobContainerClient::CreateFromConnectionString(connection_string_,
 container_name_))) {
-}
+namespace org::apache::nifi::minifi::azure::storage {
 
-void AzureBlobStorage::resetClientIfNeeded(const std::string 
&connection_string, const std::string &container_name) {
-  if (connection_string == connection_string_ && container_name_ == 
container_name) {
-    logger_->log_debug("Client credentials have not changed, no need to reset 
client");
-    return;
-  }
-  connection_string_ = connection_string;
-  container_name_ = container_name;
-  logger_->log_debug("Client has been reset with new credentials");
-  container_client_ = 
std::make_unique<Azure::Storage::Blobs::BlobContainerClient>(Azure::Storage::Blobs::BlobContainerClient::CreateFromConnectionString(connection_string,
 container_name));
+AzureBlobStorage::AzureBlobStorage(std::unique_ptr<BlobStorageClient> 
blob_storage_client)
+  : blob_storage_client_(blob_storage_client ? std::move(blob_storage_client) 
: std::make_unique<AzureBlobStorageClient>()) {

Review comment:
       I would prefer wrapping it in `gsl::not_null`, because a constructor 
postcondition is not necessarily a class invariant.

##########
File path: extensions/azure/processors/PutAzureBlobStorage.h
##########
@@ -77,11 +77,8 @@ class PutAzureBlobStorage final : public 
AzureStorageProcessorBase {
         return -1;
       }
 
-      result_ = blob_storage_wrapper_.uploadBlob(blob_name_, buffer.data(), 
flow_size_);
-      if (!result_) {
-        return read_ret;
-      }
-      return result_->length;
+      result_ = azure_blob_storage_.uploadBlob(params_, gsl::span<const 
uint8_t>{buffer.data(), flow_size_});

Review comment:
       Specifying the span template argument should be unnecessary. CTAD may 
work, but `gsl::make_span` definitely does.




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