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 d275cacc12..394670d951 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 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 customValidate(ValidationContext validationContext) { final List 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 04a9a18ba7..043dbf6a06 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; @@ -305,6 +306,28 @@ public class TestADLSCredentialsControllerService { assertNull(actual.getServicePrincipalClientSecret()); } + @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 @@ -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() {