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 b896154  CAMEL-12261 - Camel-AWS KMS: Add a scheduleKeyDeletion 
operation
b896154 is described below

commit b896154b3159dc4de13aba13188c9a83c98cc3ba
Author: Andrea Cosentino <anco...@gmail.com>
AuthorDate: Tue Feb 13 13:01:38 2018 +0100

    CAMEL-12261 - Camel-AWS KMS: Add a scheduleKeyDeletion operation
---
 .../camel/component/aws/kms/KMSConstants.java      |  1 +
 .../camel/component/aws/kms/KMSOperations.java     |  3 ++-
 .../camel/component/aws/kms/KMSProducer.java       | 28 ++++++++++++++++++++++
 .../component/aws/kms/AmazonKMSClientMock.java     |  4 +++-
 .../component/aws/kms/KMSProducerSpringTest.java   | 19 +++++++++++++++
 .../camel/component/aws/kms/KMSProducerTest.java   | 22 +++++++++++++++++
 .../aws/kms/KMSComponentSpringTest-context.xml     |  5 ++++
 7 files changed, 80 insertions(+), 2 deletions(-)

diff --git 
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/kms/KMSConstants.java
 
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/kms/KMSConstants.java
index 2900e8c..c060e12 100644
--- 
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/kms/KMSConstants.java
+++ 
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/kms/KMSConstants.java
@@ -25,4 +25,5 @@ public interface KMSConstants {
     String LIMIT                    = "CamelAwsKMSLimit";
     String DESCRIPTION              = "CamelAwsKMSDescription";
     String KEY_ID                   = "CamelAwsKMSKeyId";
+    String PENDING_WINDOW_IN_DAYS   = "CamelAwsKMSPendingWindowInDays";
 }
diff --git 
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/kms/KMSOperations.java
 
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/kms/KMSOperations.java
index cdbef53..5fefc06 100644
--- 
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/kms/KMSOperations.java
+++ 
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/kms/KMSOperations.java
@@ -20,5 +20,6 @@ public enum KMSOperations {
 
     listKeys,
     createKey,
-    disableKey
+    disableKey,
+    scheduleKeyDeletion
 }
diff --git 
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/kms/KMSProducer.java
 
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/kms/KMSProducer.java
index f845233..47dc859 100644
--- 
a/components/camel-aws/src/main/java/org/apache/camel/component/aws/kms/KMSProducer.java
+++ 
b/components/camel-aws/src/main/java/org/apache/camel/component/aws/kms/KMSProducer.java
@@ -24,6 +24,8 @@ import com.amazonaws.services.kms.model.DisableKeyRequest;
 import com.amazonaws.services.kms.model.DisableKeyResult;
 import com.amazonaws.services.kms.model.ListKeysRequest;
 import com.amazonaws.services.kms.model.ListKeysResult;
+import com.amazonaws.services.kms.model.ScheduleKeyDeletionRequest;
+import com.amazonaws.services.kms.model.ScheduleKeyDeletionResult;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
@@ -61,6 +63,9 @@ public class KMSProducer extends DefaultProducer {
         case disableKey:
             disableKey(getEndpoint().getKmsClient(), exchange);
             break;
+        case scheduleKeyDeletion:
+            scheduleKeyDeletion(getEndpoint().getKmsClient(), exchange);
+            break;
         default:
             throw new IllegalArgumentException("Unsupported operation");
         }
@@ -143,4 +148,27 @@ public class KMSProducer extends DefaultProducer {
         Message message = getMessageForResponse(exchange);
         message.setBody(result);
     }
+    
+    private void scheduleKeyDeletion(AWSKMS kmsClient, Exchange exchange) {
+        ScheduleKeyDeletionRequest request = new ScheduleKeyDeletionRequest();
+        if 
(ObjectHelper.isNotEmpty(exchange.getIn().getHeader(KMSConstants.KEY_ID))) {
+            String keyId = exchange.getIn().getHeader(KMSConstants.KEY_ID, 
String.class);
+            request.withKeyId(keyId);
+        } else {
+            throw new IllegalArgumentException("Key Id must be specified");
+        }
+        if 
(ObjectHelper.isNotEmpty(exchange.getIn().getHeader(KMSConstants.PENDING_WINDOW_IN_DAYS)))
 {
+            int pendingWindows = 
exchange.getIn().getHeader(KMSConstants.PENDING_WINDOW_IN_DAYS, Integer.class);
+            request.withPendingWindowInDays(pendingWindows);
+        } 
+        ScheduleKeyDeletionResult result;
+        try {
+            result = kmsClient.scheduleKeyDeletion(request);
+        } catch (AmazonServiceException ase) {
+            LOG.trace("Schedule Key Deletion command returned the error code 
{}", ase.getErrorCode());
+            throw ase;
+        }
+        Message message = getMessageForResponse(exchange);
+        message.setBody(result);
+    }
 }
\ No newline at end of file
diff --git 
a/components/camel-aws/src/test/java/org/apache/camel/component/aws/kms/AmazonKMSClientMock.java
 
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/kms/AmazonKMSClientMock.java
index 48b2bff..7aea19d 100644
--- 
a/components/camel-aws/src/test/java/org/apache/camel/component/aws/kms/AmazonKMSClientMock.java
+++ 
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/kms/AmazonKMSClientMock.java
@@ -300,7 +300,9 @@ public class AmazonKMSClientMock implements AWSKMS {
 
     @Override
     public ScheduleKeyDeletionResult 
scheduleKeyDeletion(ScheduleKeyDeletionRequest scheduleKeyDeletionRequest) {
-        throw new UnsupportedOperationException();
+        ScheduleKeyDeletionResult result = new ScheduleKeyDeletionResult();
+        result.withKeyId("test");
+        return result;
     }
 
     @Override
diff --git 
a/components/camel-aws/src/test/java/org/apache/camel/component/aws/kms/KMSProducerSpringTest.java
 
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/kms/KMSProducerSpringTest.java
index 2dbb3f5..740e6dc 100644
--- 
a/components/camel-aws/src/test/java/org/apache/camel/component/aws/kms/KMSProducerSpringTest.java
+++ 
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/kms/KMSProducerSpringTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.aws.kms;
 
 import com.amazonaws.services.kms.model.CreateKeyResult;
 import com.amazonaws.services.kms.model.ListKeysResult;
+import com.amazonaws.services.kms.model.ScheduleKeyDeletionResult;
 
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Exchange;
@@ -83,6 +84,24 @@ public class KMSProducerSpringTest extends 
CamelSpringTestSupport {
         assertMockEndpointsSatisfied();
         
     }
+    
+    @Test
+    public void kmsScheduleKeyDeletionTest() throws Exception {
+
+        mock.expectedMessageCount(1);
+        Exchange exchange = template.request("direct:scheduleDelete", new 
Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(KMSConstants.OPERATION, 
KMSOperations.scheduleKeyDeletion);
+                exchange.getIn().setHeader(KMSConstants.KEY_ID, "test");
+            }
+        });
+
+        assertMockEndpointsSatisfied();
+        
+        ScheduleKeyDeletionResult resultGet = (ScheduleKeyDeletionResult) 
exchange.getIn().getBody();
+        assertEquals("test", resultGet.getKeyId());
+    }
 
     @Override
     protected ClassPathXmlApplicationContext createApplicationContext() {
diff --git 
a/components/camel-aws/src/test/java/org/apache/camel/component/aws/kms/KMSProducerTest.java
 
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/kms/KMSProducerTest.java
index f478c2b..df8b0b9 100644
--- 
a/components/camel-aws/src/test/java/org/apache/camel/component/aws/kms/KMSProducerTest.java
+++ 
b/components/camel-aws/src/test/java/org/apache/camel/component/aws/kms/KMSProducerTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.aws.kms;
 
 import com.amazonaws.services.kms.model.CreateKeyResult;
 import com.amazonaws.services.kms.model.ListKeysResult;
+import com.amazonaws.services.kms.model.ScheduleKeyDeletionResult;
 
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Exchange;
@@ -85,6 +86,24 @@ public class KMSProducerTest extends CamelTestSupport {
         
     }
     
+    @Test
+    public void kmsScheduleKeyDeletionTest() throws Exception {
+
+        mock.expectedMessageCount(1);
+        Exchange exchange = template.request("direct:scheduleDelete", new 
Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(KMSConstants.OPERATION, 
KMSOperations.scheduleKeyDeletion);
+                exchange.getIn().setHeader(KMSConstants.KEY_ID, "test");
+            }
+        });
+
+        assertMockEndpointsSatisfied();
+        
+        ScheduleKeyDeletionResult resultGet = (ScheduleKeyDeletionResult) 
exchange.getIn().getBody();
+        assertEquals("test", resultGet.getKeyId());
+    }
+    
     @Override
     protected JndiRegistry createRegistry() throws Exception {
         JndiRegistry registry = super.createRegistry();
@@ -110,6 +129,9 @@ public class KMSProducerTest extends CamelTestSupport {
                 from("direct:disableKey")
                     
.to("aws-kms://test?kmsClient=#amazonKmsClient&operation=disableKey")
                     .to("mock:result");
+                from("direct:scheduleDelete")
+                    
.to("aws-kms://test?kmsClient=#amazonKmsClient&operation=scheduleKeyDeletion")
+                    .to("mock:result");
             }
         };
     }
diff --git 
a/components/camel-aws/src/test/resources/org/apache/camel/component/aws/kms/KMSComponentSpringTest-context.xml
 
b/components/camel-aws/src/test/resources/org/apache/camel/component/aws/kms/KMSComponentSpringTest-context.xml
index a901da2..9e99fe0 100644
--- 
a/components/camel-aws/src/test/resources/org/apache/camel/component/aws/kms/KMSComponentSpringTest-context.xml
+++ 
b/components/camel-aws/src/test/resources/org/apache/camel/component/aws/kms/KMSComponentSpringTest-context.xml
@@ -39,6 +39,11 @@
             <to 
uri="aws-kms://Test?kmsClient=#amazonKmsClient&amp;operation=disableKey"/>
             <to uri="mock:result"/>
         </route>
+        <route>
+            <from uri="direct:scheduleDelete"/>
+            <to 
uri="aws-kms://Test?kmsClient=#amazonKmsClient&amp;operation=scheduleKeyDeletion"/>
+            <to uri="mock:result"/>
+        </route>
     </camelContext>
 
     <bean id="amazonKmsClient" 
class="org.apache.camel.component.aws.kms.AmazonKMSClientMock"/>

-- 
To stop receiving notification emails like this one, please contact
acosent...@apache.org.

Reply via email to