fgerlits commented on a change in pull request #1178:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1178#discussion_r718567508
##########
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>()) {
}
-void AzureBlobStorage::createContainer() {
+std::optional<bool> AzureBlobStorage::createContainerIfNotExists(const
PutAzureBlobStorageParameters& params) {
Review comment:
Would a `bool` return type be enough? It looks like we only use this
from `PutAzureBlobStorage::onTrigger`, and we only check if the return value is
`nullopt` or not.
##########
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:
you could add a `gsl_Ensures(blob_storage_client_)` here to document the
invariant that `blob_storage_client_` is not null
##########
File path: extensions/azure/storage/AzureBlobStorageClient.cpp
##########
@@ -0,0 +1,65 @@
+/**
+ * @file AzureBlobStorageClient.cpp
+ * AzureBlobStorageClient class implementation
+ *
+ * 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 "AzureBlobStorageClient.h"
+
+#include "azure/identity.hpp"
+
+namespace org::apache::nifi::minifi::azure::storage {
+
+void AzureBlobStorageClient::resetClientIfNeeded(const AzureStorageCredentials
&credentials, const std::string &container_name) {
+ if (container_client_ && credentials == credentials_ && container_name ==
container_name_) {
+ logger_->log_debug("Client credentials have not changed, no need to reset
client");
+ return;
+ }
+
+ if (credentials.getUseManagedIdentityCredentials()) {
+ logger_->log_debug("Client has been reset with new managed identity
credentials.");
Review comment:
Can any of this stuff throw? I would move both logs to the end of their
block just to be safe.
##########
File path: extensions/azure/storage/AzureDataLakeStorageClient.cpp
##########
@@ -20,19 +20,28 @@
#include "AzureDataLakeStorageClient.h"
+#include "azure/identity.hpp"
+
namespace org::apache::nifi::minifi::azure::storage {
-void AzureDataLakeStorageClient::resetClientIfNeeded(const std::string&
connection_string, const std::string& file_system_name) {
- if (client_ == nullptr || connection_string_ != connection_string ||
file_system_name_ != file_system_name) {
- client_ =
std::make_unique<Azure::Storage::Files::DataLake::DataLakeFileSystemClient>(
-
Azure::Storage::Files::DataLake::DataLakeFileSystemClient::CreateFromConnectionString(connection_string,
file_system_name));
+void AzureDataLakeStorageClient::resetClientIfNeeded(const
AzureStorageCredentials& credentials, const std::string& file_system_name) {
+ if (client_ == nullptr || credentials_ != credentials || file_system_name_
!= file_system_name) {
Review comment:
I would change this to be more similar to
`AzureBlobStorageClient::resetClientIfNeeded`, with early return and debug
logs, just for consistency.
##########
File path: libminifi/test/azure-tests/PutAzureBlobStorageTests.cpp
##########
@@ -283,24 +278,75 @@ TEST_CASE_METHOD(PutAzureBlobStorageTestsFixture, "Test
credentials settings", "
REQUIRE(failed_flowfiles.size() == 1);
REQUIRE(failed_flowfiles[0] == TEST_DATA);
}
+
+ SECTION("Account name and managed identity are used in properties") {
+ plan->setProperty(put_azure_blob_storage, "Storage Account Name",
STORAGE_ACCOUNT_NAME);
+ plan->setProperty(put_azure_blob_storage, "Use Managed Identity
Credentials", "true");
+ test_controller.runSession(plan, true);
+ REQUIRE(getFailedFlowFileContents().size() == 0);
+ auto passed_params = mock_blob_storage_ptr->getPassedParams();
+ REQUIRE(passed_params.credentials.buildConnectionString().empty());
+ REQUIRE(passed_params.credentials.getStorageAccountName() ==
STORAGE_ACCOUNT_NAME);
Review comment:
most of these `REQUIRE`s could be changed to `CHECK`s, as e.g. a failure
on this line does not invalidate the tests in the next two lines
##########
File path: extensions/azure/storage/DataLakeStorageClient.h
##########
@@ -20,24 +20,27 @@
#pragma once
#include <string>
+#include <optional>
+
+#include "AzureStorageClient.h"
#include "gsl/gsl-lite.hpp"
namespace org::apache::nifi::minifi::azure::storage {
struct PutAzureDataLakeStorageParameters {
- std::string connection_string;
+ AzureStorageCredentials credentials;
std::string file_system_name;
std::string directory_name;
std::string filename;
bool replace_file = false;
};
-class DataLakeStorageClient {
+class DataLakeStorageClient : public AzureStorageClient {
public:
virtual bool createFile(const PutAzureDataLakeStorageParameters& params) = 0;
virtual std::string uploadFile(const PutAzureDataLakeStorageParameters&
params, gsl::span<const uint8_t> buffer) = 0;
- virtual ~DataLakeStorageClient() {}
+ virtual ~DataLakeStorageClient() = default;
Review comment:
this can be removed, the destructor is already virtual because of the
parent class
--
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]