tpalfy commented on a change in pull request #3742: NIFI-6550: Create 
controller service for Azure Storage Credentials
URL: https://github.com/apache/nifi/pull/3742#discussion_r325141379
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/processors/azure/storage/utils/AzureStorageUtils.java
 ##########
 @@ -112,55 +125,76 @@ private AzureStorageUtils() {
      *                 Account Name, Account Key or SAS Token. This can be 
null if not available.
      */
     public static CloudBlobClient createCloudBlobClient(ProcessContext 
context, ComponentLog logger, FlowFile flowFile) {
-        final String accountName;
-        final String accountKey;
-        final String sasToken;
-
-        if (flowFile == null) {
-            accountName = 
context.getProperty(AzureStorageUtils.ACCOUNT_NAME).evaluateAttributeExpressions().getValue();
-            accountKey = 
context.getProperty(AzureStorageUtils.ACCOUNT_KEY).evaluateAttributeExpressions().getValue();
-            sasToken = 
context.getProperty(AzureStorageUtils.PROP_SAS_TOKEN).evaluateAttributeExpressions().getValue();
+        final AzureStorageCredentialsDetails storageCredentialsDetails = 
getStorageCredentialsDetails(context, flowFile);
+
+        final URI baseUri = getBaseUri(FORMAT_BASE_URI, 
storageCredentialsDetails.getStorageAccountName(), context, logger);
+
+        final CloudBlobClient cloudBlobClient = new CloudBlobClient(baseUri, 
storageCredentialsDetails.getStorageCredentials());
+
+        return cloudBlobClient;
+    }
+
+    public static AzureStorageCredentialsDetails 
getStorageCredentialsDetails(PropertyContext context, FlowFile flowFile) {
+        final Map<String, String> attributes = flowFile != null ? 
flowFile.getAttributes() : Collections.emptyMap();
+
+        final AzureStorageCredentialsService storageCredentialsService = 
context.getProperty(STORAGE_CREDENTIALS_SERVICE).asControllerService(AzureStorageCredentialsService.class);
+
+        if (storageCredentialsService != null) {
+            return 
storageCredentialsService.getStorageCredentialsDetails(attributes);
         } else {
-            accountName = 
context.getProperty(AzureStorageUtils.ACCOUNT_NAME).evaluateAttributeExpressions(flowFile).getValue();
-            accountKey = 
context.getProperty(AzureStorageUtils.ACCOUNT_KEY).evaluateAttributeExpressions(flowFile).getValue();
-            sasToken = 
context.getProperty(AzureStorageUtils.PROP_SAS_TOKEN).evaluateAttributeExpressions(flowFile).getValue();
+            return createStorageCredentialsDetails(context, attributes);
+        }
+    }
+
+    public static AzureStorageCredentialsDetails 
createStorageCredentialsDetails(PropertyContext context, Map<String, String> 
attributes) {
+        final String accountName = 
context.getProperty(ACCOUNT_NAME).evaluateAttributeExpressions(attributes).getValue();
+        final String accountKey = 
context.getProperty(ACCOUNT_KEY).evaluateAttributeExpressions(attributes).getValue();
+        final String sasToken = 
context.getProperty(PROP_SAS_TOKEN).evaluateAttributeExpressions(attributes).getValue();
+
+        if (StringUtils.isBlank(accountName)) {
+            throw new IllegalArgumentException(String.format("'%s' must not be 
empty.", ACCOUNT_NAME.getDisplayName()));
         }
 
-        CloudBlobClient cloudBlobClient;
+        StorageCredentials storageCredentials;
+
+        if (StringUtils.isNotBlank(accountKey)) {
+            storageCredentials = new 
StorageCredentialsAccountAndKey(accountName, accountKey);
 
 Review comment:
   Sure this will work? In the original code the `accountName` + `accountKey` 
case was handled intentionally differently, if we can believe the comment that 
was added:
   `// sas token and acct name/key have different ways of creating a secure 
connection (e.g. new StorageCredentialsAccountAndKey didn't work)`

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to