Skip to content

Commit ad50a62

Browse files
committed
fixes for new proxy work
1 parent 63c65ab commit ad50a62

4 files changed

Lines changed: 36 additions & 69 deletions

File tree

nifi-nar-bundles/nifi-aws-bundle/nifi-aws-abstract-processors/src/main/java/org/apache/nifi/processors/aws/AbstractAWSProcessor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ protected Collection<ValidationResult> customValidate(final ValidationContext va
190190

191191
final boolean proxyHostSet = validationContext.getProperty(PROXY_HOST).isSet();
192192
final boolean proxyHostPortSet = validationContext.getProperty(PROXY_HOST_PORT).isSet();
193+
194+
final boolean proxyUserSet = validationContext.getProperty(PROXY_USERNAME).isSet();
195+
final boolean proxyPwdSet = validationContext.getProperty(PROXY_PASSWORD).isSet();
196+
197+
if ((proxyUserSet && !proxyPwdSet) || (!proxyUserSet && proxyPwdSet)) {
198+
problems.add(new ValidationResult.Builder().subject("Proxy User and Password").valid(false).explanation("If Proxy Username or Proxy Password is set, both must be set").build());
199+
}
200+
193201
if ( ((!proxyHostSet) && proxyHostPortSet) || (proxyHostSet && (!proxyHostPortSet)) ) {
194202
problems.add(new ValidationResult.Builder().input("Proxy Host Port").valid(false).explanation("Both proxy host and port must be set").build());
195203
}

nifi-nar-bundles/nifi-aws-bundle/nifi-aws-abstract-processors/src/main/java/org/apache/nifi/processors/aws/wag/AbstractAWSGatewayApiProcessor.java

Lines changed: 21 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ public AbstractAWSGatewayApiProcessor(AmazonHttpClient client) {
117117
"HTTP request method (GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS)."
118118
+ "Methods other than POST, PUT and PATCH will be sent without a message body.")
119119
.required(true)
120-
.defaultValue("GET").expressionLanguageSupported(true)
120+
.defaultValue("GET")
121+
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
121122
.addValidator(StandardValidators
122123
.createAttributeExpressionLanguageValidator(AttributeExpression.ResultType.STRING))
123124
.build();
@@ -127,7 +128,7 @@ public AbstractAWSGatewayApiProcessor(AmazonHttpClient client) {
127128
.displayName("Amazon Gateway Api Key")
128129
.description("The API Key")
129130
.required(false)
130-
.expressionLanguageSupported(ExpressionLanguageScope.VARIABLE_REGISTRY)
131+
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
131132
.sensitive(true)
132133
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
133134
.build();
@@ -163,7 +164,8 @@ public AbstractAWSGatewayApiProcessor(AmazonHttpClient client) {
163164
.description(
164165
"The query parameters for this request in the form of Name=Value separated by &")
165166
.displayName("Query Parameters")
166-
.required(false).expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
167+
.required(false)
168+
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
167169
.addValidator(StandardValidators
168170
.createAttributeExpressionLanguageValidator(AttributeExpression.ResultType.STRING))
169171
.build();
@@ -187,7 +189,8 @@ public AbstractAWSGatewayApiProcessor(AmazonHttpClient client) {
187189
"If set, the response body received back will be put into an attribute of the original FlowFile instead of a separate "
188190
+ "FlowFile. The attribute key to put to is determined by evaluating value of this property. ")
189191
.addValidator(StandardValidators.createAttributeExpressionLanguageValidator(
190-
AttributeExpression.ResultType.STRING)).expressionLanguageSupported(true)
192+
AttributeExpression.ResultType.STRING))
193+
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
191194
.build();
192195

193196
public static final PropertyDescriptor PROP_OUTPUT_RESPONSE_REGARDLESS = new PropertyDescriptor.Builder()
@@ -212,23 +215,6 @@ public AbstractAWSGatewayApiProcessor(AmazonHttpClient client) {
212215
.allowableValues("true", "false")
213216
.build();
214217

215-
// THIS SHOULD BE IN BASE
216-
// Should remove when https://github.com/apache/nifi/pull/2016 hits
217-
public static final PropertyDescriptor PROP_PROXY_USER = new PropertyDescriptor.Builder()
218-
.name("aws-proxy-user")
219-
.displayName("Proxy Username")
220-
.description("Username to set when authenticating against proxy").required(false)
221-
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
222-
.build();
223-
224-
public static final PropertyDescriptor PROP_PROXY_PASSWORD = new PropertyDescriptor.Builder()
225-
.name("aws-proxy-password")
226-
.displayName("Proxy Password")
227-
.description("Password to set when authenticating against proxy")
228-
.required(false)
229-
.sensitive(true).addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
230-
.build();
231-
232218
public static final PropertyDescriptor PROP_PUT_ATTRIBUTE_MAX_LENGTH = new PropertyDescriptor.Builder()
233219
.name("aws-gateway-max-attribute-length")
234220
.displayName("Max Length To Put In Attribute")
@@ -335,37 +321,15 @@ public void onPropertyModified(final PropertyDescriptor descriptor, final String
335321
protected Collection<ValidationResult> customValidate(
336322
final ValidationContext validationContext) {
337323
final List<ValidationResult> results = new ArrayList<>(3);
338-
final boolean proxyHostSet = validationContext.getProperty(PROXY_HOST).isSet();
339-
final boolean proxyPortSet = validationContext.getProperty(PROXY_HOST_PORT).isSet();
324+
results.addAll(super.customValidate(validationContext));
340325
final boolean querySet = validationContext.getProperty(PROP_QUERY_PARAMS).isSet();
341326

342-
if ((proxyHostSet && !proxyPortSet) || (!proxyHostSet && proxyPortSet)) {
343-
results.add(new ValidationResult.Builder().subject("Proxy Host and Port").valid(false)
344-
.explanation(
345-
"If Proxy Host or Proxy Port is set, both must be set")
346-
.build());
347-
}
348-
349-
final boolean proxyUserSet = validationContext.getProperty(PROP_PROXY_USER).isSet();
350-
final boolean proxyPwdSet = validationContext.getProperty(PROP_PROXY_PASSWORD).isSet();
351-
352-
if ((proxyUserSet && !proxyPwdSet) || (!proxyUserSet && proxyPwdSet)) {
353-
results.add(
354-
new ValidationResult.Builder().subject("Proxy User and Password").valid(false)
355-
.explanation(
356-
"If Proxy Username or Proxy Password is set, both must be set")
357-
.build());
358-
}
359-
if (proxyUserSet && !proxyHostSet) {
360-
results.add(new ValidationResult.Builder().subject("Proxy").valid(false).explanation(
361-
"If Proxy username is set, proxy host must be set").build());
362-
}
363-
364327
if (querySet) {
365328
String input = validationContext.getProperty(PROP_QUERY_PARAMS).getValue();
366329
// if we have expressions, we don't do further validation
367330
if (!(validationContext.isExpressionLanguageSupported(PROP_QUERY_PARAMS.getName())
368331
&& validationContext.isExpressionLanguagePresent(input))) {
332+
369333
try {
370334
final String evaluatedInput = validationContext.newPropertyValue(input)
371335
.evaluateAttributeExpressions()
@@ -388,12 +352,17 @@ protected Collection<ValidationResult> customValidate(
388352
}
389353
String method = trimToEmpty(validationContext.getProperty(PROP_METHOD).getValue())
390354
.toUpperCase();
391-
try {
392-
HttpMethodName methodName = HttpMethodName.fromValue(method);
393-
} catch (IllegalArgumentException e) {
394-
results.add(new ValidationResult.Builder().subject(PROP_METHOD.getName()).input(method)
395-
.explanation("Unsupported METHOD")
396-
.valid(false).build());
355+
356+
// if there are expressions do not validate
357+
if (!(validationContext.isExpressionLanguageSupported(PROP_METHOD.getName())
358+
&& validationContext.isExpressionLanguagePresent(method))) {
359+
try {
360+
HttpMethodName methodName = HttpMethodName.fromValue(method);
361+
} catch (IllegalArgumentException e) {
362+
results.add(new ValidationResult.Builder().subject(PROP_METHOD.getName()).input(method)
363+
.explanation("Unsupported METHOD")
364+
.valid(false).build());
365+
}
397366
}
398367

399368
return results;
@@ -404,24 +373,13 @@ protected GenericApiGatewayClient createClient(ProcessContext context,
404373
AWSCredentialsProvider awsCredentialsProvider,
405374
ClientConfiguration clientConfiguration) {
406375

407-
// although the base builds the configuration with support for host and port,
408-
// check for name and password
409-
if (context.getProperty(PROP_PROXY_USER).isSet()) {
410-
String proxyUser = context.getProperty(PROP_PROXY_USER).evaluateAttributeExpressions()
411-
.getValue();
412-
clientConfiguration.setProxyUsername(proxyUser);
413-
String proxyPassword = context.getProperty(PROP_PROXY_PASSWORD)
414-
.evaluateAttributeExpressions().getValue();
415-
clientConfiguration.setProxyPassword(proxyPassword);
416-
}
417-
418376
GenericApiGatewayClientBuilder builder = new GenericApiGatewayClientBuilder()
419377
.withCredentials(awsCredentialsProvider).withClientConfiguration(clientConfiguration)
420378
.withEndpoint(context.getProperty(PROP_AWS_GATEWAY_API_ENDPOINT).getValue()).withRegion(
421379
Region.getRegion(
422380
Regions.fromName(context.getProperty(PROP_AWS_GATEWAY_API_REGION).getValue())));
423381
if (context.getProperty(PROP_AWS_API_KEY).isSet()) {
424-
builder = builder.withApiKey(context.getProperty(PROP_AWS_API_KEY).getValue());
382+
builder = builder.withApiKey(context.getProperty(PROP_AWS_API_KEY).evaluateAttributeExpressions().getValue());
425383
}
426384
if (providedClient != null) {
427385
builder = builder.withHttpClient(providedClient);

nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/main/java/org/apache/nifi/processors/aws/wag/InvokeAWSGatewayApi.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public class InvokeAWSGatewayApi extends AbstractAWSGatewayApiProcessor {
7474

7575
public static final List<PropertyDescriptor> properties = Collections.unmodifiableList(Arrays
7676
.asList(
77+
PROP_METHOD,
7778
PROP_AWS_GATEWAY_API_REGION,
7879
ACCESS_KEY,
7980
SECRET_KEY,
@@ -91,12 +92,12 @@ public class InvokeAWSGatewayApi extends AbstractAWSGatewayApiProcessor {
9192
PROP_PENALIZE_NO_RETRY,
9293
PROXY_HOST,
9394
PROXY_HOST_PORT,
94-
PROP_METHOD,
95-
PROP_PROXY_USER,
96-
PROP_PROXY_PASSWORD,
95+
PROXY_USERNAME,
96+
PROXY_PASSWORD,
9797
PROP_QUERY_PARAMS,
9898
PROP_PUT_ATTRIBUTE_MAX_LENGTH,
99-
PROP_ADD_HEADERS_TO_REQUEST));
99+
PROP_ADD_HEADERS_TO_REQUEST,
100+
PROXY_CONFIGURATION_SERVICE));
100101

101102

102103
public static final Relationship REL_SUCCESS_REQ = new Relationship.Builder()

nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/java/org/apache/nifi/processors/aws/wag/TestInvokeAWSGatewayApiCommon.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,15 +1307,15 @@ public void testProxy() throws Exception {
13071307
}
13081308
runner.setProperty(InvokeAWSGatewayApi.PROXY_HOST_PORT, "${proxy.port}");
13091309

1310-
runner.setProperty(InvokeAWSGatewayApi.PROP_PROXY_USER, "${proxy.username}");
1310+
runner.setProperty(InvokeAWSGatewayApi.PROXY_USERNAME, "${proxy.username}");
13111311

13121312
try {
13131313
runner.run();
13141314
Assert.fail();
13151315
} catch (AssertionError e) {
13161316
// Expect assertion error when proxy password isn't set but host is.
13171317
}
1318-
runner.setProperty(InvokeAWSGatewayApi.PROP_PROXY_PASSWORD, "${proxy.password}");
1318+
runner.setProperty(InvokeAWSGatewayApi.PROXY_PASSWORD, "${proxy.password}");
13191319

13201320
createFlowFiles(runner);
13211321

0 commit comments

Comments
 (0)