mirror of https://github.com/apache/nifi.git
NIFI-11146 Proxy usage in BoxFile processors
This closes #6932. Signed-off-by: Peter Turcsanyi <turcsanyi@apache.org>
This commit is contained in:
parent
b375f4b138
commit
3e2e081d4b
|
@ -29,7 +29,7 @@
|
|||
<dependency>
|
||||
<groupId>com.box</groupId>
|
||||
<artifactId>box-java-sdk</artifactId>
|
||||
<version>3.8.2</version>
|
||||
<version>4.0.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
|
|
|
@ -42,6 +42,10 @@
|
|||
<artifactId>nifi-json-utils</artifactId>
|
||||
<version>1.20.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.nifi</groupId>
|
||||
<artifactId>nifi-proxy-configuration-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.nifi</groupId>
|
||||
<artifactId>nifi-mock</artifactId>
|
||||
|
|
|
@ -19,6 +19,16 @@ package org.apache.nifi.box.controllerservices;
|
|||
import com.box.sdk.BoxAPIConnection;
|
||||
import com.box.sdk.BoxConfig;
|
||||
import com.box.sdk.BoxDeveloperEditionAPIConnection;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.net.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.apache.nifi.annotation.documentation.CapabilityDescription;
|
||||
import org.apache.nifi.annotation.documentation.Tags;
|
||||
import org.apache.nifi.annotation.lifecycle.OnEnabled;
|
||||
|
@ -33,16 +43,9 @@ import org.apache.nifi.expression.ExpressionLanguageScope;
|
|||
import org.apache.nifi.processor.exception.ProcessException;
|
||||
import org.apache.nifi.processor.util.JsonValidator;
|
||||
import org.apache.nifi.processor.util.StandardValidators;
|
||||
import org.apache.nifi.proxy.ProxyConfiguration;
|
||||
import org.apache.nifi.proxy.ProxySpec;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@CapabilityDescription("Provides Box client objects through which Box API calls can be used.")
|
||||
@Tags({"box", "client", "provider"})
|
||||
|
@ -75,10 +78,13 @@ public class JsonConfigBasedBoxClientService extends AbstractControllerService i
|
|||
.expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
|
||||
.build();
|
||||
|
||||
private static final ProxySpec[] PROXY_SPECS = {ProxySpec.HTTP, ProxySpec.HTTP_AUTH};
|
||||
|
||||
private static final List<PropertyDescriptor> PROPERTIES = Collections.unmodifiableList(Arrays.asList(
|
||||
ACCOUNT_ID,
|
||||
APP_CONFIG_FILE,
|
||||
APP_CONFIG_JSON
|
||||
APP_CONFIG_JSON,
|
||||
ProxyConfiguration.createProxyConfigPropertyDescriptor(false, PROXY_SPECS)
|
||||
));
|
||||
|
||||
private volatile BoxAPIConnection boxAPIConnection;
|
||||
|
@ -128,15 +134,16 @@ public class JsonConfigBasedBoxClientService extends AbstractControllerService i
|
|||
}
|
||||
|
||||
private BoxAPIConnection createBoxApiConnection(ConfigurationContext context) {
|
||||
BoxAPIConnection api;
|
||||
final BoxAPIConnection api;
|
||||
|
||||
String accountId = context.getProperty(ACCOUNT_ID).evaluateAttributeExpressions().getValue();
|
||||
final String accountId = context.getProperty(ACCOUNT_ID).evaluateAttributeExpressions().getValue();
|
||||
final ProxyConfiguration proxyConfiguration = ProxyConfiguration.getConfiguration(context);
|
||||
|
||||
BoxConfig boxConfig;
|
||||
final BoxConfig boxConfig;
|
||||
if (context.getProperty(APP_CONFIG_FILE).isSet()) {
|
||||
String appConfigFile = context.getProperty(APP_CONFIG_FILE).evaluateAttributeExpressions().getValue();
|
||||
try (
|
||||
Reader reader = new FileReader(appConfigFile);
|
||||
Reader reader = new FileReader(appConfigFile)
|
||||
) {
|
||||
boxConfig = BoxConfig.readFrom(reader);
|
||||
} catch (FileNotFoundException e) {
|
||||
|
@ -145,7 +152,7 @@ public class JsonConfigBasedBoxClientService extends AbstractControllerService i
|
|||
throw new ProcessException("Couldn't read Box config file", e);
|
||||
}
|
||||
} else {
|
||||
String appConfig = context.getProperty(APP_CONFIG_JSON).evaluateAttributeExpressions().getValue();
|
||||
final String appConfig = context.getProperty(APP_CONFIG_JSON).evaluateAttributeExpressions().getValue();
|
||||
boxConfig = BoxConfig.readFrom(appConfig);
|
||||
}
|
||||
|
||||
|
@ -153,6 +160,13 @@ public class JsonConfigBasedBoxClientService extends AbstractControllerService i
|
|||
|
||||
api.asUser(accountId);
|
||||
|
||||
if (!Proxy.Type.DIRECT.equals(proxyConfiguration.getProxyType())) {
|
||||
api.setProxy(proxyConfiguration.createProxy());
|
||||
|
||||
if (proxyConfiguration.hasCredential()) {
|
||||
api.setProxyBasicAuthentication(proxyConfiguration.getProxyUserName(), proxyConfiguration.getProxyUserPassword());
|
||||
}
|
||||
}
|
||||
return api;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue