mirror of https://github.com/apache/nifi.git
NIFI-7386 Added Azure Azurite emulator credentials service
This closes #4286 Signed-off-by: Joey Frazee <jfrazee@apache.org>
This commit is contained in:
parent
989287adaf
commit
942030579a
|
@ -68,15 +68,8 @@ public abstract class AbstractAzureQueueStorage extends AbstractProcessor {
|
||||||
|
|
||||||
protected final CloudQueueClient createCloudQueueClient(final ProcessContext context, final FlowFile flowFile) throws URISyntaxException {
|
protected final CloudQueueClient createCloudQueueClient(final ProcessContext context, final FlowFile flowFile) throws URISyntaxException {
|
||||||
final AzureStorageCredentialsDetails storageCredentialsDetails = AzureStorageUtils.getStorageCredentialsDetails(context, flowFile);
|
final AzureStorageCredentialsDetails storageCredentialsDetails = AzureStorageUtils.getStorageCredentialsDetails(context, flowFile);
|
||||||
final CloudStorageAccount cloudStorageAccount =
|
final CloudStorageAccount cloudStorageAccount = AzureStorageUtils.getCloudStorageAccount(storageCredentialsDetails);
|
||||||
new CloudStorageAccount(
|
|
||||||
storageCredentialsDetails.getStorageCredentials(),
|
|
||||||
true,
|
|
||||||
storageCredentialsDetails.getStorageSuffix(),
|
|
||||||
storageCredentialsDetails.getStorageAccountName()
|
|
||||||
);
|
|
||||||
final CloudQueueClient cloudQueueClient = cloudStorageAccount.createCloudQueueClient();
|
final CloudQueueClient cloudQueueClient = cloudStorageAccount.createCloudQueueClient();
|
||||||
|
|
||||||
return cloudQueueClient;
|
return cloudQueueClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.nifi.processors.azure.storage.utils;
|
package org.apache.nifi.processors.azure.storage.utils;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -44,6 +45,7 @@ import org.apache.nifi.proxy.ProxyConfiguration;
|
||||||
import org.apache.nifi.proxy.ProxySpec;
|
import org.apache.nifi.proxy.ProxySpec;
|
||||||
import org.apache.nifi.services.azure.storage.AzureStorageCredentialsDetails;
|
import org.apache.nifi.services.azure.storage.AzureStorageCredentialsDetails;
|
||||||
import org.apache.nifi.services.azure.storage.AzureStorageCredentialsService;
|
import org.apache.nifi.services.azure.storage.AzureStorageCredentialsService;
|
||||||
|
import org.apache.nifi.services.azure.storage.AzureStorageEmulatorCredentialsDetails;
|
||||||
|
|
||||||
public final class AzureStorageUtils {
|
public final class AzureStorageUtils {
|
||||||
public static final String BLOCK = "Block";
|
public static final String BLOCK = "Block";
|
||||||
|
@ -152,14 +154,29 @@ public final class AzureStorageUtils {
|
||||||
*/
|
*/
|
||||||
public static CloudBlobClient createCloudBlobClient(ProcessContext context, ComponentLog logger, FlowFile flowFile) throws URISyntaxException {
|
public static CloudBlobClient createCloudBlobClient(ProcessContext context, ComponentLog logger, FlowFile flowFile) throws URISyntaxException {
|
||||||
final AzureStorageCredentialsDetails storageCredentialsDetails = getStorageCredentialsDetails(context, flowFile);
|
final AzureStorageCredentialsDetails storageCredentialsDetails = getStorageCredentialsDetails(context, flowFile);
|
||||||
final CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(
|
final CloudStorageAccount cloudStorageAccount = getCloudStorageAccount(storageCredentialsDetails);
|
||||||
|
final CloudBlobClient cloudBlobClient = cloudStorageAccount.createCloudBlobClient();
|
||||||
|
return cloudBlobClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CloudStorageAccount getCloudStorageAccount(final AzureStorageCredentialsDetails storageCredentialsDetails) throws URISyntaxException {
|
||||||
|
final CloudStorageAccount cloudStorageAccount;
|
||||||
|
if (storageCredentialsDetails instanceof AzureStorageEmulatorCredentialsDetails) {
|
||||||
|
AzureStorageEmulatorCredentialsDetails emulatorCredentials = (AzureStorageEmulatorCredentialsDetails) storageCredentialsDetails;
|
||||||
|
final String proxyUri = emulatorCredentials.getDevelopmentStorageProxyUri();
|
||||||
|
if (proxyUri != null) {
|
||||||
|
cloudStorageAccount = CloudStorageAccount.getDevelopmentStorageAccount(new URI(proxyUri));
|
||||||
|
} else {
|
||||||
|
cloudStorageAccount = CloudStorageAccount.getDevelopmentStorageAccount();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cloudStorageAccount = new CloudStorageAccount(
|
||||||
storageCredentialsDetails.getStorageCredentials(),
|
storageCredentialsDetails.getStorageCredentials(),
|
||||||
true,
|
true,
|
||||||
storageCredentialsDetails.getStorageSuffix(),
|
storageCredentialsDetails.getStorageSuffix(),
|
||||||
storageCredentialsDetails.getStorageAccountName());
|
storageCredentialsDetails.getStorageAccountName());
|
||||||
final CloudBlobClient cloudBlobClient = cloudStorageAccount.createCloudBlobClient();
|
}
|
||||||
|
return cloudStorageAccount;
|
||||||
return cloudBlobClient;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AzureStorageCredentialsDetails getStorageCredentialsDetails(PropertyContext context, FlowFile flowFile) {
|
public static AzureStorageCredentialsDetails getStorageCredentialsDetails(PropertyContext context, FlowFile flowFile) {
|
||||||
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.nifi.services.azure.storage;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.nifi.annotation.documentation.CapabilityDescription;
|
||||||
|
import org.apache.nifi.annotation.documentation.Tags;
|
||||||
|
import org.apache.nifi.annotation.lifecycle.OnEnabled;
|
||||||
|
import org.apache.nifi.components.PropertyDescriptor;
|
||||||
|
import org.apache.nifi.components.ValidationContext;
|
||||||
|
import org.apache.nifi.components.ValidationResult;
|
||||||
|
import org.apache.nifi.controller.AbstractControllerService;
|
||||||
|
import org.apache.nifi.controller.ConfigurationContext;
|
||||||
|
import org.apache.nifi.processor.util.StandardValidators;
|
||||||
|
|
||||||
|
@Tags({ "azure", "microsoft", "emulator", "storage", "blob", "queue", "credentials" })
|
||||||
|
@CapabilityDescription("Defines credentials for Azure Storage processors that connects to Azurite emulator.")
|
||||||
|
public class AzureStorageEmulatorCredentialsControllerService extends AbstractControllerService implements AzureStorageCredentialsService {
|
||||||
|
|
||||||
|
public static final PropertyDescriptor DEVELOPMENT_STORAGE_PROXY_URI = new PropertyDescriptor.Builder()
|
||||||
|
.name("azurite-uri")
|
||||||
|
.displayName("Storage Emulator URI")
|
||||||
|
.description("URI to connect to Azure Storage Emulator (Azurite)")
|
||||||
|
.required(false)
|
||||||
|
.sensitive(false)
|
||||||
|
.addValidator(StandardValidators.URI_VALIDATOR)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
private static final List<PropertyDescriptor> PROPERTIES =
|
||||||
|
Collections.unmodifiableList(Arrays.asList(DEVELOPMENT_STORAGE_PROXY_URI));
|
||||||
|
|
||||||
|
private String azuriteProxyUri;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
|
||||||
|
return PROPERTIES;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) {
|
||||||
|
final List<ValidationResult> results = new ArrayList<>();
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
@OnEnabled
|
||||||
|
public void onEnabled(final ConfigurationContext context) {
|
||||||
|
this.azuriteProxyUri = context.getProperty(DEVELOPMENT_STORAGE_PROXY_URI).getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProxyUri() {
|
||||||
|
return azuriteProxyUri;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AzureStorageCredentialsDetails getStorageCredentialsDetails(final Map<String, String> attributes) {
|
||||||
|
return new AzureStorageEmulatorCredentialsDetails(azuriteProxyUri);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.nifi.services.azure.storage;
|
||||||
|
|
||||||
|
public class AzureStorageEmulatorCredentialsDetails extends AzureStorageCredentialsDetails {
|
||||||
|
private String developmentStorageProxyUri;
|
||||||
|
|
||||||
|
public AzureStorageEmulatorCredentialsDetails(String developmentStorageProxyUri) {
|
||||||
|
this.developmentStorageProxyUri = developmentStorageProxyUri;
|
||||||
|
}
|
||||||
|
public String getDevelopmentStorageProxyUri() {
|
||||||
|
return developmentStorageProxyUri;
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,3 +16,4 @@ org.apache.nifi.services.azure.storage.AzureStorageCredentialsControllerService
|
||||||
org.apache.nifi.services.azure.storage.AzureStorageCredentialsControllerServiceLookup
|
org.apache.nifi.services.azure.storage.AzureStorageCredentialsControllerServiceLookup
|
||||||
org.apache.nifi.services.azure.storage.ADLSCredentialsControllerService
|
org.apache.nifi.services.azure.storage.ADLSCredentialsControllerService
|
||||||
org.apache.nifi.services.azure.cosmos.document.AzureCosmosDBClientService
|
org.apache.nifi.services.azure.cosmos.document.AzureCosmosDBClientService
|
||||||
|
org.apache.nifi.services.azure.storage.AzureStorageEmulatorCredentialsControllerService
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership.
|
||||||
|
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
* (the "License"); you may not use this file except in compliance with
|
||||||
|
* the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.apache.nifi.services.azure.storage;
|
||||||
|
|
||||||
|
import org.apache.nifi.reporting.InitializationException;
|
||||||
|
import org.apache.nifi.util.NoOpProcessor;
|
||||||
|
import org.apache.nifi.util.TestRunner;
|
||||||
|
import org.apache.nifi.util.TestRunners;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class TestAzureStorageEmulatorCredentialsControllerService {
|
||||||
|
|
||||||
|
private static final String TEST_ENVIRONMENT_URI = "http://127.0.0.1";
|
||||||
|
|
||||||
|
private TestRunner runner;
|
||||||
|
private AzureStorageCredentialsService credentialsService;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws InitializationException {
|
||||||
|
runner = TestRunners.newTestRunner(NoOpProcessor.class);
|
||||||
|
credentialsService = new AzureStorageEmulatorCredentialsControllerService();
|
||||||
|
runner.addControllerService("credentials-service", credentialsService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidWithProxyURI() {
|
||||||
|
configureProxyURI();
|
||||||
|
|
||||||
|
runner.assertValid(credentialsService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidWithoutProxyURI() {
|
||||||
|
runner.assertValid(credentialsService);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configureProxyURI() {
|
||||||
|
runner.setProperty(credentialsService, AzureStorageEmulatorCredentialsControllerService.DEVELOPMENT_STORAGE_PROXY_URI, TEST_ENVIRONMENT_URI);
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,10 @@ public class AzureStorageCredentialsDetails {
|
||||||
|
|
||||||
private final StorageCredentials storageCredentials;
|
private final StorageCredentials storageCredentials;
|
||||||
|
|
||||||
|
public AzureStorageCredentialsDetails() {
|
||||||
|
this(null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public AzureStorageCredentialsDetails(String storageAccountName, StorageCredentials storageCredentials) {
|
public AzureStorageCredentialsDetails(String storageAccountName, StorageCredentials storageCredentials) {
|
||||||
this(storageAccountName, null, storageCredentials);
|
this(storageAccountName, null, storageCredentials);
|
||||||
|
|
Loading…
Reference in New Issue