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()
|
public static final PropertyDescriptor ACCOUNT_NAME = new PropertyDescriptor.Builder()
|
||||||
.fromPropertyDescriptor(AzureStorageUtils.ACCOUNT_NAME)
|
.fromPropertyDescriptor(AzureStorageUtils.ACCOUNT_NAME)
|
||||||
.description(AzureStorageUtils.ACCOUNT_NAME_BASE_DESCRIPTION)
|
.description(AzureStorageUtils.ACCOUNT_NAME_BASE_DESCRIPTION + AzureStorageUtils.ACCOUNT_NAME_SECURITY_DESCRIPTION)
|
||||||
.required(true)
|
.required(true)
|
||||||
.expressionLanguageSupported(ExpressionLanguageScope.NONE)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public static final PropertyDescriptor ENDPOINT_SUFFIX = new PropertyDescriptor.Builder()
|
public static final PropertyDescriptor ENDPOINT_SUFFIX = new PropertyDescriptor.Builder()
|
||||||
|
@ -65,17 +64,6 @@ public class ADLSCredentialsControllerService extends AbstractControllerService
|
||||||
.expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
|
.expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
|
||||||
.build();
|
.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()
|
public static final PropertyDescriptor USE_MANAGED_IDENTITY = new PropertyDescriptor.Builder()
|
||||||
.name("storage-use-managed-identity")
|
.name("storage-use-managed-identity")
|
||||||
.displayName("Use Azure 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(
|
private static final List<PropertyDescriptor> PROPERTIES = Collections.unmodifiableList(Arrays.asList(
|
||||||
ACCOUNT_NAME,
|
ACCOUNT_NAME,
|
||||||
ENDPOINT_SUFFIX,
|
ENDPOINT_SUFFIX,
|
||||||
ACCOUNT_KEY,
|
AzureStorageUtils.ACCOUNT_KEY,
|
||||||
SAS_TOKEN,
|
AzureStorageUtils.PROP_SAS_TOKEN,
|
||||||
USE_MANAGED_IDENTITY,
|
USE_MANAGED_IDENTITY,
|
||||||
SERVICE_PRINCIPAL_TENANT_ID,
|
SERVICE_PRINCIPAL_TENANT_ID,
|
||||||
SERVICE_PRINCIPAL_CLIENT_ID,
|
SERVICE_PRINCIPAL_CLIENT_ID,
|
||||||
|
@ -138,8 +126,8 @@ public class ADLSCredentialsControllerService extends AbstractControllerService
|
||||||
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
|
protected Collection<ValidationResult> customValidate(ValidationContext validationContext) {
|
||||||
final List<ValidationResult> results = new ArrayList<>();
|
final List<ValidationResult> results = new ArrayList<>();
|
||||||
|
|
||||||
boolean accountKeySet = StringUtils.isNotBlank(validationContext.getProperty(ACCOUNT_KEY).getValue());
|
boolean accountKeySet = StringUtils.isNotBlank(validationContext.getProperty(AzureStorageUtils.ACCOUNT_KEY).getValue());
|
||||||
boolean sasTokenSet = StringUtils.isNotBlank(validationContext.getProperty(SAS_TOKEN).getValue());
|
boolean sasTokenSet = StringUtils.isNotBlank(validationContext.getProperty(AzureStorageUtils.PROP_SAS_TOKEN).getValue());
|
||||||
boolean useManagedIdentitySet = validationContext.getProperty(USE_MANAGED_IDENTITY).asBoolean();
|
boolean useManagedIdentitySet = validationContext.getProperty(USE_MANAGED_IDENTITY).asBoolean();
|
||||||
|
|
||||||
boolean servicePrincipalTenantIdSet = StringUtils.isNotBlank(validationContext.getProperty(SERVICE_PRINCIPAL_TENANT_ID).getValue());
|
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();
|
ADLSCredentialsDetails.Builder credentialsBuilder = ADLSCredentialsDetails.Builder.newBuilder();
|
||||||
|
|
||||||
setValue(credentialsBuilder, ACCOUNT_NAME, PropertyValue::getValue, ADLSCredentialsDetails.Builder::setAccountName, attributes);
|
setValue(credentialsBuilder, ACCOUNT_NAME, PropertyValue::getValue, ADLSCredentialsDetails.Builder::setAccountName, attributes);
|
||||||
setValue(credentialsBuilder, ACCOUNT_KEY, PropertyValue::getValue, ADLSCredentialsDetails.Builder::setAccountKey, attributes);
|
setValue(credentialsBuilder, AzureStorageUtils.ACCOUNT_KEY, PropertyValue::getValue, ADLSCredentialsDetails.Builder::setAccountKey, attributes);
|
||||||
setValue(credentialsBuilder, SAS_TOKEN, PropertyValue::getValue, ADLSCredentialsDetails.Builder::setSasToken, 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, ENDPOINT_SUFFIX, PropertyValue::getValue, ADLSCredentialsDetails.Builder::setEndpointSuffix, attributes);
|
||||||
setValue(credentialsBuilder, USE_MANAGED_IDENTITY, PropertyValue::asBoolean, ADLSCredentialsDetails.Builder::setUseManagedIdentity, attributes);
|
setValue(credentialsBuilder, USE_MANAGED_IDENTITY, PropertyValue::asBoolean, ADLSCredentialsDetails.Builder::setUseManagedIdentity, attributes);
|
||||||
setValue(credentialsBuilder, SERVICE_PRINCIPAL_TENANT_ID, PropertyValue::getValue, ADLSCredentialsDetails.Builder::setServicePrincipalTenantId, attributes);
|
setValue(credentialsBuilder, SERVICE_PRINCIPAL_TENANT_ID, PropertyValue::getValue, ADLSCredentialsDetails.Builder::setServicePrincipalTenantId, attributes);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.apache.nifi.services.azure.storage;
|
package org.apache.nifi.services.azure.storage;
|
||||||
|
|
||||||
import org.apache.nifi.components.PropertyDescriptor;
|
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.reporting.InitializationException;
|
||||||
import org.apache.nifi.util.NoOpProcessor;
|
import org.apache.nifi.util.NoOpProcessor;
|
||||||
import org.apache.nifi.util.TestRunner;
|
import org.apache.nifi.util.TestRunner;
|
||||||
|
@ -305,6 +306,28 @@ public class TestADLSCredentialsControllerService {
|
||||||
assertNull(actual.getServicePrincipalClientSecret());
|
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
|
@Test
|
||||||
public void testGetCredentialsDetailsWithSasToken() throws Exception {
|
public void testGetCredentialsDetailsWithSasToken() throws Exception {
|
||||||
// GIVEN
|
// GIVEN
|
||||||
|
@ -427,17 +450,25 @@ public class TestADLSCredentialsControllerService {
|
||||||
runner.setProperty(credentialsService, ADLSCredentialsControllerService.ACCOUNT_NAME, ACCOUNT_NAME_VALUE);
|
runner.setProperty(credentialsService, ADLSCredentialsControllerService.ACCOUNT_NAME, ACCOUNT_NAME_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void configureAccountNameUsingEL() {
|
||||||
|
configurePropertyUsingEL(ADLSCredentialsControllerService.ACCOUNT_NAME, "account.name", ACCOUNT_NAME_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
private void configureAccountKey() {
|
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() {
|
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() {
|
private void configureSasTokenUsingEL() {
|
||||||
String variableName = "sas.token";
|
String variableName = "sas.token";
|
||||||
configurePropertyUsingEL(ADLSCredentialsControllerService.SAS_TOKEN, variableName, SAS_TOKEN_VALUE);
|
configurePropertyUsingEL(AzureStorageUtils.PROP_SAS_TOKEN, variableName, SAS_TOKEN_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureUseManagedIdentity() {
|
private void configureUseManagedIdentity() {
|
||||||
|
|
Loading…
Reference in New Issue