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
commit aa93aa0792c55db8d93de2e7513b951260a507ce Author: Andrea Cosentino <[email protected]> AuthorDate: Wed Mar 17 08:31:04 2021 +0100 CAMEL-16323 - Create a Camel-AWS-Secret-Manager component - rotateSecret operation --- .../docs/aws-secrets-manager-component.adoc | 4 +-- .../aws/secretsmanager/aws-secrets-manager.json | 4 +-- .../main/docs/aws-secrets-manager-component.adoc | 4 +-- .../secretsmanager/SecretsManagerConstants.java | 1 + .../secretsmanager/SecretsManagerOperations.java | 3 +- .../aws/secretsmanager/SecretsManagerProducer.java | 36 ++++++++++++++++++++++ .../dsl/SecretsManagerEndpointBuilderFactory.java | 3 +- .../ROOT/pages/aws-secrets-manager-component.adoc | 4 +-- 8 files changed, 49 insertions(+), 10 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws-secrets-manager-component.adoc b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws-secrets-manager-component.adoc index 83aff4e..1f83a35 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws-secrets-manager-component.adoc +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/aws-secrets-manager-component.adoc @@ -52,7 +52,7 @@ The AWS Secrets Manager component supports 16 options, which are listed below. | *binaryPayload* (producer) | Set if the secret is binary or not | false | boolean | *configuration* (producer) | Component configuration | | SecretsManagerConfiguration | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] -| *operation* (producer) | *Required* The operation to perform. There are 5 enums and the value can be one of: listSecrets, createSecret, getSecret, describeSecret, deleteSecret | | SecretsManagerOperations +| *operation* (producer) | *Required* The operation to perform. There are 6 enums and the value can be one of: listSecrets, createSecret, getSecret, describeSecret, deleteSecret, rotateSecret | | SecretsManagerOperations | *overrideEndpoint* (producer) | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option | false | boolean | *pojoRequest* (producer) | If we want to use a POJO request as body or not | false | boolean | *proxyHost* (producer) | To define a proxy host when instantiating the Secrets Manager client | | String @@ -98,7 +98,7 @@ with the following path and query parameters: | Name | Description | Default | Type | *binaryPayload* (producer) | Set if the secret is binary or not | false | boolean | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] -| *operation* (producer) | *Required* The operation to perform. There are 5 enums and the value can be one of: listSecrets, createSecret, getSecret, describeSecret, deleteSecret | | SecretsManagerOperations +| *operation* (producer) | *Required* The operation to perform. There are 6 enums and the value can be one of: listSecrets, createSecret, getSecret, describeSecret, deleteSecret, rotateSecret | | SecretsManagerOperations | *overrideEndpoint* (producer) | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option | false | boolean | *pojoRequest* (producer) | If we want to use a POJO request as body or not | false | boolean | *proxyHost* (producer) | To define a proxy host when instantiating the Secrets Manager client | | String diff --git a/components/camel-aws/camel-aws-secrets-manager/src/generated/resources/org/apache/camel/component/aws/secretsmanager/aws-secrets-manager.json b/components/camel-aws/camel-aws-secrets-manager/src/generated/resources/org/apache/camel/component/aws/secretsmanager/aws-secrets-manager.json index 6aae872..c3f18e0 100644 --- a/components/camel-aws/camel-aws-secrets-manager/src/generated/resources/org/apache/camel/component/aws/secretsmanager/aws-secrets-manager.json +++ b/components/camel-aws/camel-aws-secrets-manager/src/generated/resources/org/apache/camel/component/aws/secretsmanager/aws-secrets-manager.json @@ -25,7 +25,7 @@ "binaryPayload": { "kind": "property", "displayName": "Binary Payload", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.secretsmanager.SecretsManagerConfiguration", "configurationField": "configuration", "description": "Set if the secret is binary or not" }, "configuration": { "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws.secretsmanager.SecretsManagerConfiguration", "deprecated": false, "autowired": false, "secret": false, "description": "Component configuration" }, "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during star [...] - "operation": { "kind": "property", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws.secretsmanager.SecretsManagerOperations", "enum": [ "listSecrets", "createSecret", "getSecret", "describeSecret", "deleteSecret" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.secretsmanager.SecretsManagerConfiguration", [...] + "operation": { "kind": "property", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws.secretsmanager.SecretsManagerOperations", "enum": [ "listSecrets", "createSecret", "getSecret", "describeSecret", "deleteSecret", "rotateSecret" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.secretsmanager.SecretsManage [...] "overrideEndpoint": { "kind": "property", "displayName": "Override Endpoint", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.secretsmanager.SecretsManagerConfiguration", "configurationField": "configuration", "description": "Set the need for overidding the endpoint. This option needs to be used in combin [...] "pojoRequest": { "kind": "property", "displayName": "Pojo Request", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.secretsmanager.SecretsManagerConfiguration", "configurationField": "configuration", "description": "If we want to use a POJO request as body or not" }, "proxyHost": { "kind": "property", "displayName": "Proxy Host", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.secretsmanager.SecretsManagerConfiguration", "configurationField": "configuration", "description": "To define a proxy host when instantiating the Secrets Manager client" }, @@ -43,7 +43,7 @@ "label": { "kind": "path", "displayName": "Label", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.secretsmanager.SecretsManagerConfiguration", "configurationField": "configuration", "description": "Logical name" }, "binaryPayload": { "kind": "parameter", "displayName": "Binary Payload", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.secretsmanager.SecretsManagerConfiguration", "configurationField": "configuration", "description": "Set if the secret is binary or not" }, "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during sta [...] - "operation": { "kind": "parameter", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws.secretsmanager.SecretsManagerOperations", "enum": [ "listSecrets", "createSecret", "getSecret", "describeSecret", "deleteSecret" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.secretsmanager.SecretsManagerConfiguration" [...] + "operation": { "kind": "parameter", "displayName": "Operation", "group": "producer", "label": "", "required": true, "type": "object", "javaType": "org.apache.camel.component.aws.secretsmanager.SecretsManagerOperations", "enum": [ "listSecrets", "createSecret", "getSecret", "describeSecret", "deleteSecret", "rotateSecret" ], "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.secretsmanager.SecretsManag [...] "overrideEndpoint": { "kind": "parameter", "displayName": "Override Endpoint", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.secretsmanager.SecretsManagerConfiguration", "configurationField": "configuration", "description": "Set the need for overidding the endpoint. This option needs to be used in combi [...] "pojoRequest": { "kind": "parameter", "displayName": "Pojo Request", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.aws.secretsmanager.SecretsManagerConfiguration", "configurationField": "configuration", "description": "If we want to use a POJO request as body or not" }, "proxyHost": { "kind": "parameter", "displayName": "Proxy Host", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.aws.secretsmanager.SecretsManagerConfiguration", "configurationField": "configuration", "description": "To define a proxy host when instantiating the Secrets Manager client" }, diff --git a/components/camel-aws/camel-aws-secrets-manager/src/main/docs/aws-secrets-manager-component.adoc b/components/camel-aws/camel-aws-secrets-manager/src/main/docs/aws-secrets-manager-component.adoc index 83aff4e..1f83a35 100644 --- a/components/camel-aws/camel-aws-secrets-manager/src/main/docs/aws-secrets-manager-component.adoc +++ b/components/camel-aws/camel-aws-secrets-manager/src/main/docs/aws-secrets-manager-component.adoc @@ -52,7 +52,7 @@ The AWS Secrets Manager component supports 16 options, which are listed below. | *binaryPayload* (producer) | Set if the secret is binary or not | false | boolean | *configuration* (producer) | Component configuration | | SecretsManagerConfiguration | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] -| *operation* (producer) | *Required* The operation to perform. There are 5 enums and the value can be one of: listSecrets, createSecret, getSecret, describeSecret, deleteSecret | | SecretsManagerOperations +| *operation* (producer) | *Required* The operation to perform. There are 6 enums and the value can be one of: listSecrets, createSecret, getSecret, describeSecret, deleteSecret, rotateSecret | | SecretsManagerOperations | *overrideEndpoint* (producer) | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option | false | boolean | *pojoRequest* (producer) | If we want to use a POJO request as body or not | false | boolean | *proxyHost* (producer) | To define a proxy host when instantiating the Secrets Manager client | | String @@ -98,7 +98,7 @@ with the following path and query parameters: | Name | Description | Default | Type | *binaryPayload* (producer) | Set if the secret is binary or not | false | boolean | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] -| *operation* (producer) | *Required* The operation to perform. There are 5 enums and the value can be one of: listSecrets, createSecret, getSecret, describeSecret, deleteSecret | | SecretsManagerOperations +| *operation* (producer) | *Required* The operation to perform. There are 6 enums and the value can be one of: listSecrets, createSecret, getSecret, describeSecret, deleteSecret, rotateSecret | | SecretsManagerOperations | *overrideEndpoint* (producer) | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option | false | boolean | *pojoRequest* (producer) | If we want to use a POJO request as body or not | false | boolean | *proxyHost* (producer) | To define a proxy host when instantiating the Secrets Manager client | | String diff --git a/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerConstants.java b/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerConstants.java index 36efd72..4a96073 100644 --- a/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerConstants.java +++ b/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerConstants.java @@ -25,4 +25,5 @@ public interface SecretsManagerConstants { String SECRET_NAME = "CamelAwsSecretsManagerSecretName"; String SECRET_DESCRIPTION = "CamelAwsSecretsManagerSecretDescription"; String SECRET_ID = "CamelAwsSecretsManagerSecretId"; + String LAMBDA_ROTATION_FUNCTION_ARN = "CamelAwsSecretsManagerLambdaRotationFunctionArn"; } diff --git a/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerOperations.java b/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerOperations.java index 28eeac7..7621497 100644 --- a/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerOperations.java +++ b/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerOperations.java @@ -22,5 +22,6 @@ public enum SecretsManagerOperations { createSecret, getSecret, describeSecret, - deleteSecret + deleteSecret, + rotateSecret } diff --git a/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerProducer.java b/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerProducer.java index 00aa929..5e6e60b 100644 --- a/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerProducer.java +++ b/components/camel-aws/camel-aws-secrets-manager/src/main/java/org/apache/camel/component/aws/secretsmanager/SecretsManagerProducer.java @@ -41,6 +41,9 @@ import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRespon import software.amazon.awssdk.services.secretsmanager.model.ListSecretsRequest; import software.amazon.awssdk.services.secretsmanager.model.ListSecretsRequest.Builder; import software.amazon.awssdk.services.secretsmanager.model.ListSecretsResponse; +import software.amazon.awssdk.services.secretsmanager.model.RotateSecretRequest; +import software.amazon.awssdk.services.secretsmanager.model.RotateSecretResponse; +import software.amazon.awssdk.services.secretsmanager.model.RotationRulesType; /** * A Producer which sends messages to the Amazon Secrets Manager Service SDK v2 @@ -74,6 +77,9 @@ public class SecretsManagerProducer extends DefaultProducer { case deleteSecret: deleteSecret(getEndpoint().getSecretsManagerClient(), exchange); break; + case rotateSecret: + rotateSecret(getEndpoint().getSecretsManagerClient(), exchange); + break; default: throw new IllegalArgumentException("Unsupported operation"); } @@ -263,6 +269,36 @@ public class SecretsManagerProducer extends DefaultProducer { message.setBody(result); } + private void rotateSecret(SecretsManagerClient secretsManagerClient, Exchange exchange) + throws InvalidPayloadException { + RotateSecretRequest request = null; + RotateSecretResponse result; + if (getConfiguration().isPojoRequest()) { + request = exchange.getIn().getMandatoryBody(RotateSecretRequest.class); + } else { + RotateSecretRequest.Builder builder = RotateSecretRequest.builder(); + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(SecretsManagerConstants.SECRET_ID))) { + String secretId = exchange.getIn().getHeader(SecretsManagerConstants.SECRET_ID, String.class); + builder.secretId(secretId); + } else { + throw new IllegalArgumentException("Secret Id must be specified"); + } + if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(SecretsManagerConstants.LAMBDA_ROTATION_FUNCTION_ARN))) { + String lambdaRotationArn = exchange.getIn().getHeader(SecretsManagerConstants.LAMBDA_ROTATION_FUNCTION_ARN, String.class); + builder.rotationLambdaARN(lambdaRotationArn); + } + request = builder.build(); + } + try { + result = secretsManagerClient.rotateSecret(request); + } catch (AwsServiceException ase) { + LOG.trace("Rotate Secret value command returned the error code {}", ase.awsErrorDetails().errorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + public static Message getMessageForResponse(final Exchange exchange) { return exchange.getMessage(); } diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SecretsManagerEndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SecretsManagerEndpointBuilderFactory.java index fcf7128..d91a2f8 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SecretsManagerEndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/SecretsManagerEndpointBuilderFactory.java @@ -433,7 +433,8 @@ public interface SecretsManagerEndpointBuilderFactory { createSecret, getSecret, describeSecret, - deleteSecret; + deleteSecret, + rotateSecret; } /** diff --git a/docs/components/modules/ROOT/pages/aws-secrets-manager-component.adoc b/docs/components/modules/ROOT/pages/aws-secrets-manager-component.adoc index b98253d..a0068d8 100644 --- a/docs/components/modules/ROOT/pages/aws-secrets-manager-component.adoc +++ b/docs/components/modules/ROOT/pages/aws-secrets-manager-component.adoc @@ -54,7 +54,7 @@ The AWS Secrets Manager component supports 16 options, which are listed below. | *binaryPayload* (producer) | Set if the secret is binary or not | false | boolean | *configuration* (producer) | Component configuration | | SecretsManagerConfiguration | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] -| *operation* (producer) | *Required* The operation to perform. There are 5 enums and the value can be one of: listSecrets, createSecret, getSecret, describeSecret, deleteSecret | | SecretsManagerOperations +| *operation* (producer) | *Required* The operation to perform. There are 6 enums and the value can be one of: listSecrets, createSecret, getSecret, describeSecret, deleteSecret, rotateSecret | | SecretsManagerOperations | *overrideEndpoint* (producer) | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option | false | boolean | *pojoRequest* (producer) | If we want to use a POJO request as body or not | false | boolean | *proxyHost* (producer) | To define a proxy host when instantiating the Secrets Manager client | | String @@ -100,7 +100,7 @@ with the following path and query parameters: | Name | Description | Default | Type | *binaryPayload* (producer) | Set if the secret is binary or not | false | boolean | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] -| *operation* (producer) | *Required* The operation to perform. There are 5 enums and the value can be one of: listSecrets, createSecret, getSecret, describeSecret, deleteSecret | | SecretsManagerOperations +| *operation* (producer) | *Required* The operation to perform. There are 6 enums and the value can be one of: listSecrets, createSecret, getSecret, describeSecret, deleteSecret, rotateSecret | | SecretsManagerOperations | *overrideEndpoint* (producer) | Set the need for overidding the endpoint. This option needs to be used in combination with uriEndpointOverride option | false | boolean | *pojoRequest* (producer) | If we want to use a POJO request as body or not | false | boolean | *proxyHost* (producer) | To define a proxy host when instantiating the Secrets Manager client | | String
