-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
77 changed files
with
3,516 additions
and
880 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...src/main/java/org/apache/nifi/processors/aws/AbstractAWSCredentialsProviderProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* 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.processors.aws; | ||
import org.apache.nifi.annotation.lifecycle.OnScheduled; | ||
import org.apache.nifi.components.PropertyDescriptor; | ||
import org.apache.nifi.controller.ControllerService; | ||
import org.apache.nifi.processor.ProcessContext; | ||
import org.apache.nifi.processors.aws.credentials.provider.service.AWSCredentialsProviderService; | ||
|
||
import com.amazonaws.AmazonWebServiceClient; | ||
import com.amazonaws.ClientConfiguration; | ||
import com.amazonaws.auth.AWSCredentialsProvider; | ||
|
||
/** | ||
* Base class for aws processors that uses AWSCredentialsProvider interface for creating aws clients. | ||
* | ||
* @param <ClientType> client type | ||
* | ||
* @see <a href="http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/AWSCredentialsProvider.html">AWSCredentialsProvider</a> | ||
*/ | ||
public abstract class AbstractAWSCredentialsProviderProcessor<ClientType extends AmazonWebServiceClient> | ||
extends AbstractAWSProcessor<ClientType> { | ||
|
||
/** | ||
* AWS credentials provider service | ||
* | ||
* @see <a href="http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/AWSCredentialsProvider.html">AWSCredentialsProvider</a> | ||
*/ | ||
public static final PropertyDescriptor AWS_CREDENTIALS_PROVIDER_SERVICE = new PropertyDescriptor.Builder() | ||
.name("AWS Credentials Provider service") | ||
.description("The Controller Service that is used to obtain aws credentials provider") | ||
.required(false) | ||
.identifiesControllerService(AWSCredentialsProviderService.class) | ||
.build(); | ||
|
||
/** | ||
* This method checks if {#link {@link #AWS_CREDENTIALS_PROVIDER_SERVICE} is available and if it | ||
* is, uses the credentials provider, otherwise it invokes the {@link AbstractAWSProcessor#onScheduled(ProcessContext)} | ||
* which uses static AWSCredentials for the aws processors | ||
*/ | ||
@OnScheduled | ||
public void onScheduled(ProcessContext context) { | ||
ControllerService service = context.getProperty(AWS_CREDENTIALS_PROVIDER_SERVICE).asControllerService(); | ||
if (service != null) { | ||
getLogger().debug("Using aws credentials provider service for creating client"); | ||
onScheduledUsingControllerService(context); | ||
} else { | ||
getLogger().debug("Using aws credentials for creating client"); | ||
super.onScheduled(context); | ||
} | ||
} | ||
|
||
/** | ||
* Create aws client using credentials provider | ||
* @param context the process context | ||
*/ | ||
protected void onScheduledUsingControllerService(ProcessContext context) { | ||
final ClientType awsClient = createClient(context, getCredentialsProvider(context), createConfiguration(context)); | ||
this.client = awsClient; | ||
super.intializeRegionAndEndpoint(context); | ||
|
||
} | ||
|
||
/** | ||
* Get credentials provider using the {@link AWSCredentialsProviderService} | ||
* @param context the process context | ||
* @return AWSCredentialsProvider the credential provider | ||
* @see <a href="http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/AWSCredentialsProvider.html">AWSCredentialsProvider</a> | ||
*/ | ||
protected AWSCredentialsProvider getCredentialsProvider(final ProcessContext context) { | ||
|
||
final AWSCredentialsProviderService awsCredentialsProviderService = | ||
context.getProperty(AWS_CREDENTIALS_PROVIDER_SERVICE).asControllerService(AWSCredentialsProviderService.class); | ||
|
||
return awsCredentialsProviderService.getCredentialsProvider(); | ||
|
||
} | ||
|
||
/** | ||
* Abstract method to create aws client using credetials provider. This is the preferred method | ||
* for creating aws clients | ||
* @param context process context | ||
* @param credentialsProvider aws credentials provider | ||
* @param config aws client configuraiton | ||
* @return ClientType the client | ||
*/ | ||
protected abstract ClientType createClient(final ProcessContext context, final AWSCredentialsProvider credentialsProvider, final ClientConfiguration config); | ||
} |
Oops, something went wrong.