mirror of https://github.com/apache/nifi.git
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 <pierre.villard.fr@gmail.com> This closes #5229.
This commit is contained in:
parent
828b6c1bcc
commit
47eeabd8a5
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue