You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by pv...@apache.org on 2021/07/20 13:05:59 UTC
[nifi] branch main updated: NIFI-8762
ADLSCredentialControllerService does not support EL for Storage Account
name
This is an automated email from the ASF dual-hosted git repository.
pvillard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new 47eeabd NIFI-8762 ADLSCredentialControllerService does not support EL for Storage Account name
47eeabd is described below
commit 47eeabd8a5045d21bbcd0d2001bebac8344cec4c
Author: Denes Arvay <de...@apache.org>
AuthorDate: Mon Jul 19 11:23:12 2021 +0200
NIFI-8762 ADLSCredentialControllerService does not support EL for Storage Account name
- Added FLOWFILE_ATTRIBUTES expression language support to the Storage Account Name and
and also to the Storage Account Key property to be consistent with
AzureStorageCredentialsControllerService
- ADLSCredentialControllerService.ACCOUNT_KEY and ADLSCredentialControllerService.SAS_TOKEN
PropertyDescriptor public constants are the same as AzureStorageUtils.ACCOUNT_KEY and
AzureStorageUtils.PROP_SAS_TOKEN respectively, but they haven't been removed to keep
backward compatibility.
NIFI-8762 Removed ADLSCredentialsControllerService.ACCOUNT_KEY and SAS_TOKEN static fields
NIFI-8762 Add test for EL in Account Name and Account Key
Signed-off-by: Pierre Villard <pi...@gmail.com>
This closes #5229.
---
.../storage/ADLSCredentialsControllerService.java | 26 ++++-----------
.../TestADLSCredentialsControllerService.java | 37 ++++++++++++++++++++--
2 files changed, 41 insertions(+), 22 deletions(-)
diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/services/azure/storage/ADLSCredentialsControllerService.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/services/azure/storage/ADLSCredentialsControllerService.java
index d275cac..394670d 100644
--- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/services/azure/storage/ADLSCredentialsControllerService.java
+++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/services/azure/storage/ADLSCredentialsControllerService.java
@@ -50,9 +50,8 @@ public class ADLSCredentialsControllerService extends AbstractControllerService
public static final PropertyDescriptor ACCOUNT_NAME = new PropertyDescriptor.Builder()
.fromPropertyDescriptor(AzureStorageUtils.ACCOUNT_NAME)
- .description(AzureStorageUtils.ACCOUNT_NAME_BASE_DESCRIPTION)
+ .description(AzureStorageUtils.ACCOUNT_NAME_BASE_DESCRIPTION + AzureStorageUtils.ACCOUNT_NAME_SECURITY_DESCRIPTION)
.required(true)
- .expressionLanguageSupported(ExpressionLanguageScope.NONE)
.build();
public static final PropertyDescriptor ENDPOINT_SUFFIX = new PropertyDescriptor.Builder()
@@ -65,17 +64,6 @@ public class ADLSCredentialsControllerService extends AbstractControllerService
.expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
.build();
- public static final PropertyDescriptor ACCOUNT_KEY = new PropertyDescriptor.Builder()
- .fromPropertyDescriptor(AzureStorageUtils.ACCOUNT_KEY)
- .description(AzureStorageUtils.ACCOUNT_KEY_BASE_DESCRIPTION)
- .expressionLanguageSupported(ExpressionLanguageScope.NONE)
- .build();
-
- public static final PropertyDescriptor SAS_TOKEN = new PropertyDescriptor.Builder()
- .fromPropertyDescriptor(AzureStorageUtils.PROP_SAS_TOKEN)
- .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
- .build();
-
public static final PropertyDescriptor USE_MANAGED_IDENTITY = new PropertyDescriptor.Builder()
.name("storage-use-managed-identity")
.displayName("Use Azure Managed Identity")
@@ -119,8 +107,8 @@ public class ADLSCredentialsControllerService extends AbstractControllerService
private static final List<PropertyDescriptor> PROPERTIES = Collections.unmodifiableList(Arrays.asList(
ACCOUNT_NAME,
ENDPOINT_SUFFIX,
- ACCOUNT_KEY,
- SAS_TOKEN,
+ AzureStorageUtils.ACCOUNT_KEY,
+ AzureStorageUtils.PROP_SAS_TOKEN,
USE_MANAGED_IDENTITY,
SERVICE_PRINCIPAL_TENANT_ID,
SERVICE_PRINCIPAL_CLIENT_ID,
@@ -138,8 +126,8 @@ public class ADLSCredentialsControllerService extends AbstractControllerService
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
final List<ValidationResult> results = new ArrayList<>();
- boolean accountKeySet = StringUtils.isNotBlank(validationContext.getProperty(ACCOUNT_KEY).getValue());
- boolean sasTokenSet = StringUtils.isNotBlank(validationContext.getProperty(SAS_TOKEN).getValue());
+ boolean accountKeySet = StringUtils.isNotBlank(validationContext.getProperty(AzureStorageUtils.ACCOUNT_KEY).getValue());
+ boolean sasTokenSet = StringUtils.isNotBlank(validationContext.getProperty(AzureStorageUtils.PROP_SAS_TOKEN).getValue());
boolean useManagedIdentitySet = validationContext.getProperty(USE_MANAGED_IDENTITY).asBoolean();
boolean servicePrincipalTenantIdSet = StringUtils.isNotBlank(validationContext.getProperty(SERVICE_PRINCIPAL_TENANT_ID).getValue());
@@ -196,8 +184,8 @@ public class ADLSCredentialsControllerService extends AbstractControllerService
ADLSCredentialsDetails.Builder credentialsBuilder = ADLSCredentialsDetails.Builder.newBuilder();
setValue(credentialsBuilder, ACCOUNT_NAME, PropertyValue::getValue, ADLSCredentialsDetails.Builder::setAccountName, attributes);
- setValue(credentialsBuilder, ACCOUNT_KEY, PropertyValue::getValue, ADLSCredentialsDetails.Builder::setAccountKey, attributes);
- setValue(credentialsBuilder, SAS_TOKEN, PropertyValue::getValue, ADLSCredentialsDetails.Builder::setSasToken, attributes);
+ setValue(credentialsBuilder, AzureStorageUtils.ACCOUNT_KEY, PropertyValue::getValue, ADLSCredentialsDetails.Builder::setAccountKey, attributes);
+ setValue(credentialsBuilder, AzureStorageUtils.PROP_SAS_TOKEN, PropertyValue::getValue, ADLSCredentialsDetails.Builder::setSasToken, attributes);
setValue(credentialsBuilder, ENDPOINT_SUFFIX, PropertyValue::getValue, ADLSCredentialsDetails.Builder::setEndpointSuffix, attributes);
setValue(credentialsBuilder, USE_MANAGED_IDENTITY, PropertyValue::asBoolean, ADLSCredentialsDetails.Builder::setUseManagedIdentity, attributes);
setValue(credentialsBuilder, SERVICE_PRINCIPAL_TENANT_ID, PropertyValue::getValue, ADLSCredentialsDetails.Builder::setServicePrincipalTenantId, attributes);
diff --git a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestADLSCredentialsControllerService.java b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestADLSCredentialsControllerService.java
index 04a9a18..043dbf6 100644
--- a/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestADLSCredentialsControllerService.java
+++ b/nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/services/azure/storage/TestADLSCredentialsControllerService.java
@@ -17,6 +17,7 @@
package org.apache.nifi.services.azure.storage;
import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils;
import org.apache.nifi.reporting.InitializationException;
import org.apache.nifi.util.NoOpProcessor;
import org.apache.nifi.util.TestRunner;
@@ -306,6 +307,28 @@ public class TestADLSCredentialsControllerService {
}
@Test
+ public void testGetCredentialsDetailsWithAccountKeyUsingEL() throws Exception {
+ // GIVEN
+ configureAccountNameUsingEL();
+ configureAccountKeyUsingEL();
+
+ runner.enableControllerService(credentialsService);
+
+ // WHEN
+ ADLSCredentialsDetails actual = credentialsService.getCredentialsDetails(new HashMap<>());
+
+ // THEN
+ assertEquals(ACCOUNT_NAME_VALUE, actual.getAccountName());
+ assertEquals(ACCOUNT_KEY_VALUE, actual.getAccountKey());
+ assertNull(actual.getSasToken());
+ assertFalse(actual.getUseManagedIdentity());
+ assertNotNull(actual.getEndpointSuffix());
+ assertNull(actual.getServicePrincipalTenantId());
+ assertNull(actual.getServicePrincipalClientId());
+ assertNull(actual.getServicePrincipalClientSecret());
+ }
+
+ @Test
public void testGetCredentialsDetailsWithSasToken() throws Exception {
// GIVEN
configureAccountName();
@@ -427,17 +450,25 @@ public class TestADLSCredentialsControllerService {
runner.setProperty(credentialsService, ADLSCredentialsControllerService.ACCOUNT_NAME, ACCOUNT_NAME_VALUE);
}
+ private void configureAccountNameUsingEL() {
+ configurePropertyUsingEL(ADLSCredentialsControllerService.ACCOUNT_NAME, "account.name", ACCOUNT_NAME_VALUE);
+ }
+
private void configureAccountKey() {
- runner.setProperty(credentialsService, ADLSCredentialsControllerService.ACCOUNT_KEY, ACCOUNT_KEY_VALUE);
+ runner.setProperty(credentialsService, AzureStorageUtils.ACCOUNT_KEY, ACCOUNT_KEY_VALUE);
+ }
+
+ private void configureAccountKeyUsingEL() {
+ configurePropertyUsingEL(AzureStorageUtils.ACCOUNT_KEY, "account.key", ACCOUNT_KEY_VALUE);
}
private void configureSasToken() {
- runner.setProperty(credentialsService, ADLSCredentialsControllerService.SAS_TOKEN, SAS_TOKEN_VALUE);
+ runner.setProperty(credentialsService, AzureStorageUtils.PROP_SAS_TOKEN, SAS_TOKEN_VALUE);
}
private void configureSasTokenUsingEL() {
String variableName = "sas.token";
- configurePropertyUsingEL(ADLSCredentialsControllerService.SAS_TOKEN, variableName, SAS_TOKEN_VALUE);
+ configurePropertyUsingEL(AzureStorageUtils.PROP_SAS_TOKEN, variableName, SAS_TOKEN_VALUE);
}
private void configureUseManagedIdentity() {