Skip to content

Commit

Permalink
NIFI-13867 Removed legacy code component Proxy Properties (#9381)
Browse files Browse the repository at this point in the history
Signed-off-by: David Handermann <[email protected]>
  • Loading branch information
turcsanyip authored Oct 12, 2024
1 parent 0f8b570 commit c3122b2
Show file tree
Hide file tree
Showing 27 changed files with 37 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import org.apache.nifi.processor.util.StandardValidators;
import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderService;
import org.apache.nifi.proxy.ProxyConfiguration;
import org.apache.nifi.proxy.ProxyConfigurationService;
import org.apache.nifi.proxy.ProxySpec;
import org.apache.nifi.ssl.SSLContextService;

import javax.net.ssl.SSLContext;
Expand Down Expand Up @@ -119,13 +119,7 @@ public abstract class AbstractAWSCredentialsProviderProcessor<ClientType extends
.identifiesControllerService(AWSCredentialsProviderService.class)
.build();

public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE = new PropertyDescriptor.Builder()
.name("proxy-configuration-service")
.displayName("Proxy Configuration Service")
.description("Specifies the Proxy Configuration Controller Service to proxy network requests.")
.identifiesControllerService(ProxyConfigurationService.class)
.required(false)
.build();
public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE = ProxyConfiguration.createProxyConfigPropertyDescriptor(ProxySpec.HTTP, ProxySpec.HTTP_AUTH);


// Relationships
Expand Down Expand Up @@ -219,14 +213,7 @@ protected ClientConfiguration createConfiguration(final PropertyContext context,
}
}

final ProxyConfiguration proxyConfig = ProxyConfiguration.getConfiguration(context, () -> {
if (context.getProperty(PROXY_CONFIGURATION_SERVICE).isSet()) {
final ProxyConfigurationService configurationService = context.getProperty(PROXY_CONFIGURATION_SERVICE).asControllerService(ProxyConfigurationService.class);
return configurationService.getConfiguration();
}

return ProxyConfiguration.DIRECT_CONFIGURATION;
});
final ProxyConfiguration proxyConfig = ProxyConfiguration.getConfiguration(context);

if (Proxy.Type.HTTP.equals(proxyConfig.getProxyType())) {
config.setProxyHost(proxyConfig.getProxyServerHost());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import org.apache.nifi.processor.util.StandardValidators;
import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderService;
import org.apache.nifi.proxy.ProxyConfiguration;
import org.apache.nifi.proxy.ProxyConfigurationService;
import org.apache.nifi.proxy.ProxySpec;
import org.apache.nifi.ssl.SSLContextService;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.awscore.client.builder.AwsClientBuilder;
Expand Down Expand Up @@ -139,13 +139,7 @@ public abstract class AbstractAwsProcessor<T extends SdkClient> extends Abstract
.identifiesControllerService(AWSCredentialsProviderService.class)
.build();

public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE = new PropertyDescriptor.Builder()
.name("proxy-configuration-service")
.displayName("Proxy Configuration Service")
.description("Specifies the Proxy Configuration Controller Service to proxy network requests.")
.identifiesControllerService(ProxyConfigurationService.class)
.required(false)
.build();
public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE = ProxyConfiguration.createProxyConfigPropertyDescriptor(ProxySpec.HTTP, ProxySpec.HTTP_AUTH);


protected static final String DEFAULT_USER_AGENT = "NiFi";
Expand Down Expand Up @@ -304,13 +298,7 @@ protected void configureSdkHttpClient(final ProcessContext context, final AwsHtt
}
}

final ProxyConfiguration proxyConfig = ProxyConfiguration.getConfiguration(context, () -> {
if (context.getProperty(ProxyConfigurationService.PROXY_CONFIGURATION_SERVICE).isSet()) {
final ProxyConfigurationService configurationService = context.getProperty(ProxyConfigurationService.PROXY_CONFIGURATION_SERVICE).asControllerService(ProxyConfigurationService.class);
return configurationService.getConfiguration();
}
return ProxyConfiguration.DIRECT_CONFIGURATION;
});
final ProxyConfiguration proxyConfig = ProxyConfiguration.getConfiguration(context);

if (Proxy.Type.HTTP.equals(proxyConfig.getProxyType())) {
httpClientConfigurer.configureProxy(proxyConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.apache.nifi.processor.util.StandardValidators;
import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderService;
import org.apache.nifi.proxy.ProxyConfiguration;
import org.apache.nifi.proxy.ProxyConfigurationService;
import org.apache.nifi.proxy.ProxySpec;
import org.apache.nifi.schema.access.SchemaField;
import org.apache.nifi.schema.access.SchemaNotFoundException;
Expand Down Expand Up @@ -135,7 +134,7 @@ public class AmazonGlueSchemaRegistry extends AbstractControllerService implemen

private static final ProxySpec[] PROXY_SPECS = {ProxySpec.HTTP_AUTH};

private static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE = ProxyConfiguration.createProxyConfigPropertyDescriptor(true, PROXY_SPECS);
private static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE = ProxyConfiguration.createProxyConfigPropertyDescriptor(PROXY_SPECS);

private static final List<PropertyDescriptor> PROPERTIES = new ArrayList<>(Arrays.asList(
SCHEMA_REGISTRY_NAME,
Expand Down Expand Up @@ -232,13 +231,7 @@ private SdkHttpClient createSdkHttpClient(final ConfigurationContext context) {
}
}
}
final ProxyConfiguration proxyConfig = ProxyConfiguration.getConfiguration(context, () -> {
if (context.getProperty(ProxyConfigurationService.PROXY_CONFIGURATION_SERVICE).isSet()) {
final ProxyConfigurationService configurationService = context.getProperty(ProxyConfigurationService.PROXY_CONFIGURATION_SERVICE).asControllerService(ProxyConfigurationService.class);
return configurationService.getConfiguration();
}
return ProxyConfiguration.DIRECT_CONFIGURATION;
});
final ProxyConfiguration proxyConfig = ProxyConfiguration.getConfiguration(context);

if (Proxy.Type.HTTP.equals(proxyConfig.getProxyType())) {
final software.amazon.awssdk.http.apache.ProxyConfiguration.Builder proxyConfigBuilder = software.amazon.awssdk.http.apache.ProxyConfiguration.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class GetAzureQueueStorage_v12 extends AbstractAzureQueueStorage_v12 {
MESSAGE_BATCH_SIZE,
VISIBILITY_TIMEOUT,
REQUEST_TIMEOUT,
ProxyConfiguration.createProxyConfigPropertyDescriptor(false, PROXY_SPECS)
ProxyConfiguration.createProxyConfigPropertyDescriptor(PROXY_SPECS)
);
private static final Set<Relationship> RELATIONSHIPS = Set.of(REL_SUCCESS);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class PutAzureQueueStorage_v12 extends AbstractAzureQueueStorage_v12 {
MESSAGE_TIME_TO_LIVE,
VISIBILITY_TIMEOUT,
REQUEST_TIMEOUT,
ProxyConfiguration.createProxyConfigPropertyDescriptor(false, PROXY_SPECS)
ProxyConfiguration.createProxyConfigPropertyDescriptor(PROXY_SPECS)
);

// 7 days is the maximum timeout as per https://learn.microsoft.com/en-us/rest/api/storageservices/get-messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private AzureStorageUtils() {

private static final ProxySpec[] PROXY_SPECS = {ProxySpec.HTTP, ProxySpec.SOCKS};
public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE = new PropertyDescriptor.Builder()
.fromPropertyDescriptor(ProxyConfiguration.createProxyConfigPropertyDescriptor(false, PROXY_SPECS))
.fromPropertyDescriptor(ProxyConfiguration.createProxyConfigPropertyDescriptor(PROXY_SPECS))
.build();

public static void validateProxySpec(ValidationContext context, Collection<ValidationResult> results) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface AzureEventHubComponent {
.build();
ProxySpec[] PROXY_SPECS = {ProxySpec.HTTP, ProxySpec.HTTP_AUTH};
PropertyDescriptor PROXY_CONFIGURATION_SERVICE = new PropertyDescriptor.Builder()
.fromPropertyDescriptor(ProxyConfiguration.createProxyConfigPropertyDescriptor(false, PROXY_SPECS))
.fromPropertyDescriptor(ProxyConfiguration.createProxyConfigPropertyDescriptor(PROXY_SPECS))
.dependsOn(TRANSPORT_TYPE, AzureEventHubTransportType.AMQP_WEB_SOCKETS)
.build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class JsonConfigBasedBoxClientService extends AbstractControllerService i
ACCOUNT_ID,
APP_CONFIG_FILE,
APP_CONFIG_JSON,
ProxyConfiguration.createProxyConfigPropertyDescriptor(false, PROXY_SPECS)
ProxyConfiguration.createProxyConfigPropertyDescriptor(PROXY_SPECS)
));

private volatile BoxAPIConnection boxAPIConnection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public class FetchDropbox extends AbstractProcessor implements DropboxTrait {
private static final List<PropertyDescriptor> PROPERTIES = Collections.unmodifiableList(Arrays.asList(
CREDENTIAL_SERVICE,
FILE,
ProxyConfiguration.createProxyConfigPropertyDescriptor(false, ProxySpec.HTTP_AUTH)
ProxyConfiguration.createProxyConfigPropertyDescriptor(ProxySpec.HTTP_AUTH)
));

private volatile DbxClientV2 dropboxApiClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public class ListDropbox extends AbstractListProcessor<DropboxFileInfo> implemen
TRACKING_TIME_WINDOW,
INITIAL_LISTING_TARGET,
RECORD_WRITER,
ProxyConfiguration.createProxyConfigPropertyDescriptor(false, ProxySpec.HTTP_AUTH)
ProxyConfiguration.createProxyConfigPropertyDescriptor(ProxySpec.HTTP_AUTH)
));

private volatile DbxClientV2 dropboxApiClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public class PutDropbox extends AbstractProcessor implements DropboxTrait {
CONFLICT_RESOLUTION,
CHUNKED_UPLOAD_THRESHOLD,
CHUNKED_UPLOAD_SIZE,
ProxyConfiguration.createProxyConfigPropertyDescriptor(false, ProxySpec.HTTP_AUTH)
ProxyConfiguration.createProxyConfigPropertyDescriptor(ProxySpec.HTTP_AUTH)
));

private static final Set<Relationship> RELATIONSHIPS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public interface ElasticSearchClientService extends ControllerService, Verifiabl
.identifiesControllerService(SSLContextService.class)
.addValidator(Validator.VALID)
.build();
PropertyDescriptor PROXY_CONFIGURATION_SERVICE = ProxyConfiguration.createProxyConfigPropertyDescriptor(false, ProxySpec.HTTP);
PropertyDescriptor PROXY_CONFIGURATION_SERVICE = ProxyConfiguration.createProxyConfigPropertyDescriptor(ProxySpec.HTTP);

PropertyDescriptor AUTHORIZATION_SCHEME = new PropertyDescriptor.Builder()
.name("authorization-scheme")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public abstract class AbstractGCPProcessor<
.identifiesControllerService(GCPCredentialsService.class)
.build();

public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE = ProxyConfiguration.createProxyConfigPropertyDescriptor(false, ProxyAwareTransportFactory.PROXY_SPECS);
public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE = ProxyConfiguration.createProxyConfigPropertyDescriptor(ProxyAwareTransportFactory.PROXY_SPECS);

protected volatile CloudService cloudService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class GCPCredentialsControllerService extends AbstractControllerService i
props.add(USE_COMPUTE_ENGINE_CREDENTIALS);
props.add(SERVICE_ACCOUNT_JSON_FILE);
props.add(SERVICE_ACCOUNT_JSON);
props.add(ProxyConfiguration.createProxyConfigPropertyDescriptor(false, ProxyAwareTransportFactory.PROXY_SPECS));
props.add(ProxyConfiguration.createProxyConfigPropertyDescriptor(ProxyAwareTransportFactory.PROXY_SPECS));
properties = Collections.unmodifiableList(props);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public class FetchGoogleDrive extends AbstractProcessor implements GoogleDriveTr
private static final List<PropertyDescriptor> PROPERTIES = List.of(
GoogleUtils.GCP_CREDENTIALS_PROVIDER_SERVICE,
FILE_ID,
ProxyConfiguration.createProxyConfigPropertyDescriptor(false, ProxyAwareTransportFactory.PROXY_SPECS),
ProxyConfiguration.createProxyConfigPropertyDescriptor(ProxyAwareTransportFactory.PROXY_SPECS),
GOOGLE_DOC_EXPORT_TYPE,
GOOGLE_SPREADSHEET_EXPORT_TYPE,
GOOGLE_PRESENTATION_EXPORT_TYPE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public class ListGoogleDrive extends AbstractListProcessor<GoogleDriveFileInfo>
TRACKING_TIME_WINDOW,
INITIAL_LISTING_TARGET,
RECORD_WRITER,
ProxyConfiguration.createProxyConfigPropertyDescriptor(false, ProxyAwareTransportFactory.PROXY_SPECS)
ProxyConfiguration.createProxyConfigPropertyDescriptor(ProxyAwareTransportFactory.PROXY_SPECS)
));

private volatile Drive driveService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public class PutGoogleDrive extends AbstractProcessor implements GoogleDriveTrai
CONFLICT_RESOLUTION,
CHUNKED_UPLOAD_THRESHOLD,
CHUNKED_UPLOAD_SIZE,
ProxyConfiguration.createProxyConfigPropertyDescriptor(false, ProxyAwareTransportFactory.PROXY_SPECS)
ProxyConfiguration.createProxyConfigPropertyDescriptor(ProxyAwareTransportFactory.PROXY_SPECS)
));

public static final Relationship REL_SUCCESS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public class SiteToSiteUtils {
.defaultValue(SiteToSiteTransportProtocol.RAW.name())
.build();
public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE = new PropertyDescriptor.Builder()
.fromPropertyDescriptor(ProxyConfiguration.createProxyConfigPropertyDescriptor(false, ProxySpec.HTTP, ProxySpec.HTTP_AUTH))
.fromPropertyDescriptor(ProxyConfiguration.createProxyConfigPropertyDescriptor(ProxySpec.HTTP, ProxySpec.HTTP_AUTH))
.dependsOn(TRANSPORT_PROTOCOL, SiteToSiteTransportProtocol.HTTP.name())
.build();
public static final PropertyDescriptor PLATFORM = new PropertyDescriptor.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public class InvokeHTTP extends AbstractProcessor {

private static final ProxySpec[] PROXY_SPECS = {ProxySpec.HTTP_AUTH, ProxySpec.SOCKS};

private static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE = ProxyConfiguration.createProxyConfigPropertyDescriptor(true, PROXY_SPECS);
private static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE = ProxyConfiguration.createProxyConfigPropertyDescriptor(PROXY_SPECS);

public static final List<PropertyDescriptor> PROPERTIES = List.of(
HTTP_METHOD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ public class FTPTransfer implements FileTransfer {
private static final FTPClientProvider FTP_CLIENT_PROVIDER = new StandardFTPClientProvider();

private static final ProxySpec[] PROXY_SPECS = {ProxySpec.HTTP_AUTH, ProxySpec.SOCKS_AUTH};
public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE
= ProxyConfiguration.createProxyConfigPropertyDescriptor(false, PROXY_SPECS);
public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE = ProxyConfiguration.createProxyConfigPropertyDescriptor(PROXY_SPECS);

private final ComponentLog logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,10 @@
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.components.ValidationContext;
import org.apache.nifi.components.ValidationResult;
import org.apache.nifi.processor.ProcessContext;
import org.apache.nifi.processor.util.StandardValidators;
import org.apache.nifi.proxy.ProxyConfiguration;
import org.apache.nifi.proxy.ProxySpec;

import java.net.Proxy;
import java.util.Collection;
import java.util.Map;

public class HTTPUtils {
Expand All @@ -54,39 +48,10 @@ public static String getURI(Map<String, String> map) {
}
}

public static final PropertyDescriptor PROXY_HOST = new PropertyDescriptor.Builder()
.name("Proxy Host")
.description("The fully qualified hostname or IP address of the proxy server")
.required(false)
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.build();

public static final PropertyDescriptor PROXY_PORT = new PropertyDescriptor.Builder()
.name("Proxy Port")
.description("The port of the proxy server")
.required(false)
.addValidator(StandardValidators.PORT_VALIDATOR)
.build();

private static final ProxySpec[] PROXY_SPECS = {ProxySpec.HTTP_AUTH};
public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE
= ProxyConfiguration.createProxyConfigPropertyDescriptor(true, PROXY_SPECS);


public static void setProxy(final ProcessContext context, final HttpClientBuilder clientBuilder, final CredentialsProvider credentialsProvider) {
// Set the proxy if specified
final ProxyConfiguration proxyConfig = ProxyConfiguration.getConfiguration(context, () -> {
if (context.getProperty(PROXY_HOST).isSet() && context.getProperty(PROXY_PORT).isSet()) {
final ProxyConfiguration componentProxyConfig = new ProxyConfiguration();
final String host = context.getProperty(PROXY_HOST).getValue();
final int port = context.getProperty(PROXY_PORT).asInteger();
componentProxyConfig.setProxyType(Proxy.Type.HTTP);
componentProxyConfig.setProxyServerHost(host);
componentProxyConfig.setProxyServerPort(port);
return componentProxyConfig;
}
return ProxyConfiguration.DIRECT_CONFIGURATION;
});
final ProxyConfiguration proxyConfig = ProxyConfiguration.getConfiguration(context);

if (Proxy.Type.HTTP.equals(proxyConfig.getProxyType())) {
final String host = proxyConfig.getProxyServerHost();
Expand All @@ -101,16 +66,4 @@ public static void setProxy(final ProcessContext context, final HttpClientBuilde
}
}
}

public static void validateProxyProperties(ValidationContext context, Collection<ValidationResult> results) {
if (context.getProperty(PROXY_HOST).isSet() && !context.getProperty(PROXY_PORT).isSet()) {
results.add(new ValidationResult.Builder()
.explanation("Proxy Host was set but no Proxy Port was specified")
.valid(false)
.subject("Proxy server configuration")
.build());
}

ProxyConfiguration.validateProxySpec(context, results, PROXY_SPECS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ private static boolean isDirectory(FileAttributes attributes) {
.build();

private static final ProxySpec[] PROXY_SPECS = {ProxySpec.HTTP_AUTH, ProxySpec.SOCKS_AUTH};
public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE
= ProxyConfiguration.createProxyConfigPropertyDescriptor(true, PROXY_SPECS);
public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE = ProxyConfiguration.createProxyConfigPropertyDescriptor(PROXY_SPECS);

private final ComponentLog logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public class RestLookupService extends AbstractControllerService implements Reco

private static final ProxySpec[] PROXY_SPECS = {ProxySpec.HTTP_AUTH, ProxySpec.SOCKS};
public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE
= ProxyConfiguration.createProxyConfigPropertyDescriptor(true, PROXY_SPECS);
= ProxyConfiguration.createProxyConfigPropertyDescriptor(PROXY_SPECS);

static final String MIME_TYPE_KEY = "mime.type";
static final String BODY_KEY = "request.body";
Expand Down
Loading

0 comments on commit c3122b2

Please sign in to comment.