This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 2a8b0bb CAMEL-12146 - Camel-AWS Lambda: Add the ability to specify credentials and region at component level 2a8b0bb is described below commit 2a8b0bb5adcea121b93bf366ec2d5becf40063eb Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Tue Jan 16 11:31:30 2018 +0100 CAMEL-12146 - Camel-AWS Lambda: Add the ability to specify credentials and region at component level --- .../src/main/docs/aws-lambda-component.adoc | 14 +- .../component/aws/lambda/LambdaComponent.java | 65 ++++++++- .../component/aws/lambda/LambdaConfiguration.java | 16 ++- .../lambda/LambdaComponentConfigurationTest.java | 28 ++++ .../springboot/LambdaComponentConfiguration.java | 158 +++++++++++++++++++++ 5 files changed, 278 insertions(+), 3 deletions(-) diff --git a/components/camel-aws/src/main/docs/aws-lambda-component.adoc b/components/camel-aws/src/main/docs/aws-lambda-component.adoc index 66c1539..85ce05c 100644 --- a/components/camel-aws/src/main/docs/aws-lambda-component.adoc +++ b/components/camel-aws/src/main/docs/aws-lambda-component.adoc @@ -31,7 +31,19 @@ You can append query options to the URI in the following format, // component options: START -The AWS Lambda component has no options. +The AWS Lambda component supports 5 options which are listed below. + + + +[width="100%",cols="2,5,^1,2",options="header"] +|=== +| Name | Description | Default | Type +| *configuration* (advanced) | The AWS Lambda default configuration | | LambdaConfiguration +| *accessKey* (producer) | Amazon AWS Access Key | | String +| *secretKey* (producer) | Amazon AWS Secret Key | | String +| *region* (producer) | Amazon AWS Region | | String +| *resolveProperty Placeholders* (advanced) | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | boolean +|=== // component options: END diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaComponent.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaComponent.java index b90b574..b42655f 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaComponent.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaComponent.java @@ -21,10 +21,20 @@ import java.util.Map; import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; import org.apache.camel.impl.DefaultComponent; +import org.apache.camel.spi.Metadata; import org.apache.camel.util.ObjectHelper; public class LambdaComponent extends DefaultComponent { + @Metadata + private String accessKey; + @Metadata + private String secretKey; + @Metadata + private String region; + @Metadata(label = "advanced") + private LambdaConfiguration configuration; + public LambdaComponent() { this(null); } @@ -32,15 +42,25 @@ public class LambdaComponent extends DefaultComponent { public LambdaComponent(CamelContext context) { super(context); + this.configuration = new LambdaConfiguration(); registerExtension(new LambdaComponentVerifierExtension()); } @Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { - LambdaConfiguration configuration = new LambdaConfiguration(); + LambdaConfiguration configuration = this.configuration.copy(); setProperties(configuration, parameters); configuration.setFunction(remaining); + if (ObjectHelper.isEmpty(configuration.getAccessKey())) { + setAccessKey(accessKey); + } + if (ObjectHelper.isEmpty(configuration.getSecretKey())) { + setSecretKey(secretKey); + } + if (ObjectHelper.isEmpty(configuration.getRegion())) { + setRegion(region); + } if (ObjectHelper.isEmpty(configuration.getAwsLambdaClient()) && (ObjectHelper.isEmpty(configuration.getAccessKey()) || ObjectHelper.isEmpty(configuration.getSecretKey()))) { throw new IllegalArgumentException("accessKey/secretKey or awsLambdaClient must be specified"); } @@ -48,5 +68,48 @@ public class LambdaComponent extends DefaultComponent { LambdaEndpoint endpoint = new LambdaEndpoint(uri, this, configuration); return endpoint; } + + public LambdaConfiguration getConfiguration() { + return configuration; + } + /** + * The AWS Lambda default configuration + */ + public void setConfiguration(LambdaConfiguration configuration) { + this.configuration = configuration; + } + + public String getAccessKey() { + return configuration.getAccessKey(); + } + + /** + * Amazon AWS Access Key + */ + public void setAccessKey(String accessKey) { + configuration.setAccessKey(accessKey); + } + + public String getSecretKey() { + return configuration.getSecretKey(); + } + + /** + * Amazon AWS Secret Key + */ + public void setSecretKey(String secretKey) { + configuration.setSecretKey(secretKey); + } + + public String getRegion() { + return configuration.getRegion(); + } + + /** + * Amazon AWS Region + */ + public void setRegion(String region) { + configuration.setRegion(region); + } } diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaConfiguration.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaConfiguration.java index 1908d1c..e0cdb08 100644 --- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaConfiguration.java +++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/lambda/LambdaConfiguration.java @@ -17,13 +17,15 @@ package org.apache.camel.component.aws.lambda; import com.amazonaws.services.lambda.AWSLambda; + +import org.apache.camel.RuntimeCamelException; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriParams; import org.apache.camel.spi.UriPath; @UriParams -public class LambdaConfiguration { +public class LambdaConfiguration implements Cloneable { @UriPath @Metadata(required = "true") @@ -144,5 +146,17 @@ public class LambdaConfiguration { public void setProxyPort(Integer proxyPort) { this.proxyPort = proxyPort; } + + // ************************************************* + // + // ************************************************* + + public LambdaConfiguration copy() { + try { + return (LambdaConfiguration)super.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeCamelException(e); + } + } } \ No newline at end of file diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/LambdaComponentConfigurationTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/LambdaComponentConfigurationTest.java index ba848af..ce3b2dd 100644 --- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/LambdaComponentConfigurationTest.java +++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/lambda/LambdaComponentConfigurationTest.java @@ -16,7 +16,9 @@ */ package org.apache.camel.component.aws.lambda; +import com.amazonaws.regions.Regions; import com.amazonaws.services.lambda.AWSLambdaClient; + import org.apache.camel.impl.JndiRegistry; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; @@ -66,6 +68,32 @@ public class LambdaComponentConfigurationTest extends CamelTestSupport { LambdaComponent component = new LambdaComponent(context); component.createEndpoint("aws-lambda://myFunction?operation=getFunction&awsLambdaClient=#awsLambdaClient"); } + + @Test + public void createEndpointWithComponentElements() throws Exception { + LambdaComponent component = new LambdaComponent(context); + component.setAccessKey("XXX"); + component.setSecretKey("YYY"); + LambdaEndpoint endpoint = (LambdaEndpoint)component.createEndpoint("aws-lambda://myFunction"); + + assertEquals("myFunction", endpoint.getConfiguration().getFunction()); + assertEquals("XXX", endpoint.getConfiguration().getAccessKey()); + assertEquals("YYY", endpoint.getConfiguration().getSecretKey()); + } + + @Test + public void createEndpointWithComponentAndEndpointElements() throws Exception { + LambdaComponent component = new LambdaComponent(context); + component.setAccessKey("XXX"); + component.setSecretKey("YYY"); + component.setRegion(Regions.US_WEST_1.toString()); + LambdaEndpoint endpoint = (LambdaEndpoint)component.createEndpoint("aws-lambda://myFunction?accessKey=xxxxxx&secretKey=yyyyy®ion=US_EAST_1"); + + assertEquals("myFunction", endpoint.getConfiguration().getFunction()); + assertEquals("xxxxxx", endpoint.getConfiguration().getAccessKey()); + assertEquals("yyyyy", endpoint.getConfiguration().getSecretKey()); + assertEquals("US_EAST_1", endpoint.getConfiguration().getRegion()); + } @Override protected JndiRegistry createRegistry() throws Exception { diff --git a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/lambda/springboot/LambdaComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/lambda/springboot/LambdaComponentConfiguration.java index 5e1025d..327f443 100644 --- a/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/lambda/springboot/LambdaComponentConfiguration.java +++ b/platforms/spring-boot/components-starter/camel-aws-starter/src/main/java/org/apache/camel/component/aws/lambda/springboot/LambdaComponentConfiguration.java @@ -17,6 +17,8 @@ package org.apache.camel.component.aws.lambda.springboot; import javax.annotation.Generated; +import com.amazonaws.services.lambda.AWSLambda; +import org.apache.camel.component.aws.lambda.LambdaOperations; import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -33,12 +35,61 @@ public class LambdaComponentConfiguration ComponentConfigurationPropertiesCommon { /** + * The AWS Lambda default configuration + */ + private LambdaConfigurationNestedConfiguration configuration; + /** + * Amazon AWS Access Key + */ + private String accessKey; + /** + * Amazon AWS Secret Key + */ + private String secretKey; + /** + * Amazon AWS Region + */ + private String region; + /** * Whether the component should resolve property placeholders on itself when * starting. Only properties which are of String type can use property * placeholders. */ private Boolean resolvePropertyPlaceholders = true; + public LambdaConfigurationNestedConfiguration getConfiguration() { + return configuration; + } + + public void setConfiguration( + LambdaConfigurationNestedConfiguration configuration) { + this.configuration = configuration; + } + + public String getAccessKey() { + return accessKey; + } + + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + public String getSecretKey() { + return secretKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } + public Boolean getResolvePropertyPlaceholders() { return resolvePropertyPlaceholders; } @@ -47,4 +98,111 @@ public class LambdaComponentConfiguration Boolean resolvePropertyPlaceholders) { this.resolvePropertyPlaceholders = resolvePropertyPlaceholders; } + + public static class LambdaConfigurationNestedConfiguration { + public static final Class CAMEL_NESTED_CLASS = org.apache.camel.component.aws.lambda.LambdaConfiguration.class; + /** + * Name of the Lambda function. + */ + private String function; + /** + * To use a existing configured AwsLambdaClient as client + */ + private AWSLambda awsLambdaClient; + /** + * Amazon AWS Access Key + */ + private String accessKey; + /** + * Amazon AWS Secret Key + */ + private String secretKey; + /** + * Amazon AWS Region + */ + private String region; + /** + * The region with which the AWS-Lambda client wants to work with. + */ + private String awsLambdaEndpoint; + /** + * The operation to perform. It can be listFunctions, getFunction, + * createFunction, deleteFunction or invokeFunction + */ + private LambdaOperations operation; + private String proxyHost; + private Integer proxyPort; + + public String getFunction() { + return function; + } + + public void setFunction(String function) { + this.function = function; + } + + public AWSLambda getAwsLambdaClient() { + return awsLambdaClient; + } + + public void setAwsLambdaClient(AWSLambda awsLambdaClient) { + this.awsLambdaClient = awsLambdaClient; + } + + public String getAccessKey() { + return accessKey; + } + + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + public String getSecretKey() { + return secretKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } + + public String getAwsLambdaEndpoint() { + return awsLambdaEndpoint; + } + + public void setAwsLambdaEndpoint(String awsLambdaEndpoint) { + this.awsLambdaEndpoint = awsLambdaEndpoint; + } + + public LambdaOperations getOperation() { + return operation; + } + + public void setOperation(LambdaOperations operation) { + this.operation = operation; + } + + public String getProxyHost() { + return proxyHost; + } + + public void setProxyHost(String proxyHost) { + this.proxyHost = proxyHost; + } + + public Integer getProxyPort() { + return proxyPort; + } + + public void setProxyPort(Integer proxyPort) { + this.proxyPort = proxyPort; + } + } } \ No newline at end of file -- To stop receiving notification emails like this one, please contact ['"commits@camel.apache.org" <commits@camel.apache.org>'].