Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,27 @@ This includes derived works from Apache Solr available under Apache Software Lic

This includes derived works from Apache Hadoop available under Apache Software License V2. Portions of the code found in
https://github.com/apache/hadoop/blob/release-2.7.3-RC2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java
The code can be found nifi-commons/nifi-security-utils/src/main/java/org/apache/nifi/security/krb/KeytabUser.java
The code can be found nifi-commons/nifi-security-utils/src/main/java/org/apache/nifi/security/krb/KeytabUser.java
This includes derived works from apigateway-generic-java-sdk (ASLv2 licenced) project (https://github.com/rpgreen/apigateway-generic-java-sdk):
The derived work is adapted from
main/ca/ryangreen/apigateway/generic/
GenericApiGatewayClient.java
GenericApiGatewayClientBuilder.java
GenericApiGatewayException.java
GenericApiGatewayRequest.java
GenericApiGatewayRequestBuilder.java
test/ca/ryangreen/apigateway/generic/
GenericApiGatewayClientTest.java
LambdaMatcher.java
and can be found in the directories:
nifi-nar-bundles/nifi-aws-bundle/nifi-aws-abstract-processors/src/main/../wag/client/
GenericApiGatewayClient.java
GenericApiGatewayClientBuilder.java
GenericApiGatewayException.java
GenericApiGatewayRequest.java
GenericApiGatewayRequestBuilder.java
Validate.java
nifi-nar-bundles/nifi-aws-bundle/nifi-aws-processors/src/test/../wag/
RequestMatcher.java
GetAWSGatewayApiTest.java

Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sqs</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
Expand Down Expand Up @@ -81,5 +86,19 @@
<artifactId>nifi-proxy-configuration-api</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<configuration>
<excludes>
<!-- 3rd party APL 2.0 code brought in, should not have headers -->
<!--https://www.apache.org/legal/src-headers.html#3party-->
<exclude>src/main/java/org/apache/nifi/processors/aws/wag/client/*.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ public abstract class AbstractAWSProcessor<ClientType extends AmazonWebServiceCl
private static final ProxySpec[] PROXY_SPECS = {ProxySpec.HTTP_AUTH};
public static final PropertyDescriptor PROXY_CONFIGURATION_SERVICE = ProxyConfiguration.createProxyConfigPropertyDescriptor(true, PROXY_SPECS);

private static AllowableValue createAllowableValue(final Regions region) {
protected static AllowableValue createAllowableValue(final Regions region) {
return new AllowableValue(region.getName(), AWSRegions.getRegionDisplayName(region.getName()));
}

private static AllowableValue[] getAvailableRegions() {
protected static AllowableValue[] getAvailableRegions() {
final List<AllowableValue> values = new ArrayList<>();
for (final Regions region : Regions.values()) {
values.add(createAllowableValue(region));
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package org.apache.nifi.processors.aws.wag.client;

import com.amazonaws.AmazonServiceException;
import com.amazonaws.AmazonWebServiceClient;
import com.amazonaws.ClientConfiguration;
import com.amazonaws.DefaultRequest;
import com.amazonaws.auth.AWS4Signer;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.http.AmazonHttpClient;
import com.amazonaws.http.ExecutionContext;
import com.amazonaws.http.HttpMethodName;
import com.amazonaws.http.HttpResponseHandler;
import com.amazonaws.http.JsonResponseHandler;
import com.amazonaws.internal.auth.DefaultSignerProvider;
import com.amazonaws.protocol.json.JsonOperationMetadata;
import com.amazonaws.protocol.json.SdkStructuredPlainJsonFactory;
import com.amazonaws.regions.Region;
import com.amazonaws.transform.JsonErrorUnmarshaller;
import com.amazonaws.transform.JsonUnmarshallerContext;
import com.amazonaws.transform.Unmarshaller;
import com.fasterxml.jackson.databind.JsonNode;
import java.io.InputStream;
import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class GenericApiGatewayClient extends AmazonWebServiceClient {
private static final String API_GATEWAY_SERVICE_NAME = "execute-api";
private static final String API_KEY_HEADER = "x-api-key";

private final JsonResponseHandler<GenericApiGatewayResponse> responseHandler;
private final HttpResponseHandler<AmazonServiceException> errorResponseHandler;
private final AWSCredentialsProvider credentials;
private String apiKey;
private final AWS4Signer signer;

GenericApiGatewayClient(ClientConfiguration clientConfiguration, String endpoint, Region region,
AWSCredentialsProvider credentials, String apiKey, AmazonHttpClient httpClient) {
super(clientConfiguration);
setRegion(region);
setEndpoint(endpoint);
this.credentials = credentials;
this.apiKey = apiKey;
this.signer = new AWS4Signer();
this.signer.setServiceName(API_GATEWAY_SERVICE_NAME);
this.signer.setRegionName(region.getName());

final JsonOperationMetadata metadata = new JsonOperationMetadata().withHasStreamingSuccessResponse(false).withPayloadJson(false);
final Unmarshaller<GenericApiGatewayResponse, JsonUnmarshallerContext> responseUnmarshaller = in -> new GenericApiGatewayResponse(in.getHttpResponse());
this.responseHandler = SdkStructuredPlainJsonFactory.SDK_JSON_FACTORY.createResponseHandler(metadata, responseUnmarshaller);
JsonErrorUnmarshaller defaultErrorUnmarshaller = new JsonErrorUnmarshaller(GenericApiGatewayException.class, null) {
@Override
public AmazonServiceException unmarshall(JsonNode jsonContent) throws Exception {
return new GenericApiGatewayException(jsonContent.toString());
}
};
this.errorResponseHandler = SdkStructuredPlainJsonFactory.SDK_JSON_FACTORY.createErrorResponseHandler(
Collections.singletonList(defaultErrorUnmarshaller), null);

if (httpClient != null) {
super.client = httpClient;
}
}

public GenericApiGatewayResponse execute(GenericApiGatewayRequest request) {
return execute(request.getHttpMethod(), request.getResourcePath(), request.getHeaders(), request.getParameters(), request.getBody());
}

private GenericApiGatewayResponse execute(HttpMethodName method, String resourcePath, Map<String, String> headers, Map<String,List<String>> parameters, InputStream content) {
final ExecutionContext executionContext = buildExecutionContext();

DefaultRequest request = new DefaultRequest(API_GATEWAY_SERVICE_NAME);
request.setHttpMethod(method);
request.setContent(content);
request.setEndpoint(this.endpoint);
request.setResourcePath(resourcePath);
request.setHeaders(buildRequestHeaders(headers, apiKey));
if (parameters != null) {
request.setParameters(parameters);
}
return this.client.execute(request, responseHandler, errorResponseHandler, executionContext).getAwsResponse();
}

private ExecutionContext buildExecutionContext() {
final ExecutionContext executionContext = ExecutionContext.builder().withSignerProvider(
new DefaultSignerProvider(this, signer)).build();
executionContext.setCredentialsProvider(credentials);
executionContext.setSigner(signer);
return executionContext;
}

private Map<String, String> buildRequestHeaders(Map<String, String> headers, String apiKey) {
if (headers == null) {
headers = new HashMap<>();
}
if (apiKey != null) {
headers.put(API_KEY_HEADER, apiKey);
}
return headers;
}

public URI getEndpoint() {
return this.endpoint;
}

@Override
protected String getServiceNameIntern() {
return API_GATEWAY_SERVICE_NAME;
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.apache.nifi.processors.aws.wag.client;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.http.AmazonHttpClient;
import com.amazonaws.regions.Region;

public class GenericApiGatewayClientBuilder {
private String endpoint;
private Region region;
private AWSCredentialsProvider credentials;
private ClientConfiguration clientConfiguration;
private String apiKey;
private AmazonHttpClient httpClient;

public GenericApiGatewayClientBuilder withEndpoint(String endpoint) {
this.endpoint = endpoint;
return this;
}

public GenericApiGatewayClientBuilder withRegion(Region region) {
this.region = region;
return this;
}

public GenericApiGatewayClientBuilder withClientConfiguration(ClientConfiguration clientConfiguration) {
this.clientConfiguration = clientConfiguration;
return this;
}

public GenericApiGatewayClientBuilder withCredentials(AWSCredentialsProvider credentials) {
this.credentials = credentials;
return this;
}

public GenericApiGatewayClientBuilder withApiKey(String apiKey) {
this.apiKey = apiKey;
return this;
}

public GenericApiGatewayClientBuilder withHttpClient(AmazonHttpClient client) {
this.httpClient = client;
return this;
}

public AWSCredentialsProvider getCredentials() {
return credentials;
}

public String getApiKey() {
return apiKey;
}

public AmazonHttpClient getHttpClient() {
return httpClient;
}

public String getEndpoint() {
return endpoint;
}

public Region getRegion() {
return region;
}

public ClientConfiguration getClientConfiguration() {
return clientConfiguration;
}

public GenericApiGatewayClient build() {
Validate.notEmpty(endpoint, "Endpoint");
Validate.notNull(region, "Region");
return new GenericApiGatewayClient(clientConfiguration, endpoint, region, credentials, apiKey, httpClient);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.apache.nifi.processors.aws.wag.client;

import com.amazonaws.AmazonServiceException;

public class GenericApiGatewayException extends AmazonServiceException {
public GenericApiGatewayException(String errorMessage) {
super(errorMessage);
}

public GenericApiGatewayException(String errorMessage, Exception cause) {
super(errorMessage, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.apache.nifi.processors.aws.wag.client;

import com.amazonaws.http.HttpMethodName;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

public class GenericApiGatewayRequest {

private final HttpMethodName httpMethod;
private final String resourcePath;
private final InputStream body;
private final Map<String, String> headers;
private final Map<String, List<String>> parameters;

public GenericApiGatewayRequest(HttpMethodName httpMethod, String resourcePath,
InputStream body, Map<String, String> headers,
Map<String, List<String>> parameters) {
this.httpMethod = httpMethod;
this.resourcePath = resourcePath;
this.body = body;
this.headers = headers;
this.parameters = parameters;
}

public HttpMethodName getHttpMethod() {
return httpMethod;
}

public String getResourcePath() {
return resourcePath;
}

public InputStream getBody() {
return body;
}

public Map<String, String> getHeaders() {
return headers;
}

public Map<String, List<String>> getParameters() {
return parameters;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.apache.nifi.processors.aws.wag.client;

import com.amazonaws.http.HttpMethodName;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

public class GenericApiGatewayRequestBuilder {
private HttpMethodName httpMethod;
private String resourcePath;
private InputStream body;
private Map<String, String> headers;
private Map<String, List<String>> parameters;

public GenericApiGatewayRequestBuilder withHttpMethod(HttpMethodName name) {
httpMethod = name;
return this;
}

public GenericApiGatewayRequestBuilder withResourcePath(String path) {
resourcePath = path;
return this;
}

public GenericApiGatewayRequestBuilder withBody(InputStream content) {
this.body = content;
return this;
}

public GenericApiGatewayRequestBuilder withHeaders(Map<String, String> headers) {
this.headers = headers;
return this;
}

public GenericApiGatewayRequestBuilder withParameters(Map<String,List<String>> parameters) {
this.parameters = parameters;
return this;
}

public boolean hasBody() {
return this.body != null;
}

public GenericApiGatewayRequest build() {
Validate.notNull(httpMethod, "HTTP method");
Validate.notEmpty(resourcePath, "Resource path");
return new GenericApiGatewayRequest(httpMethod, resourcePath, body, headers, parameters);
}
}
Loading