You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/04/22 10:20:48 UTC
[camel] 03/10: CAMEL-14868 - Camel-AWS2-*: Where possible,
give the possiblity to the end user to pass an AWS Request pojo as
body, aws2-iam operations
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 f8ce281fd40653a8657b73623e1a8c96ae1e48ac
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Apr 22 12:05:44 2020 +0200
CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-iam operations
---
.../camel/component/aws2/iam/IAM2Producer.java | 35 ++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/components/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/IAM2Producer.java b/components/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/IAM2Producer.java
index b0ccc13..0da861c 100644
--- a/components/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/IAM2Producer.java
+++ b/components/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/IAM2Producer.java
@@ -46,6 +46,7 @@ import software.amazon.awssdk.services.iam.model.GetUserResponse;
import software.amazon.awssdk.services.iam.model.ListAccessKeysRequest;
import software.amazon.awssdk.services.iam.model.ListAccessKeysResponse;
import software.amazon.awssdk.services.iam.model.ListGroupsResponse;
+import software.amazon.awssdk.services.iam.model.ListUsersRequest;
import software.amazon.awssdk.services.iam.model.ListUsersResponse;
import software.amazon.awssdk.services.iam.model.RemoveUserFromGroupRequest;
import software.amazon.awssdk.services.iam.model.RemoveUserFromGroupResponse;
@@ -267,7 +268,21 @@ public class IAM2Producer extends DefaultProducer {
}
}
- private void listUsers(IamClient iamClient, Exchange exchange) {
+ private void listUsers(IamClient iamClient, Exchange exchange) throws InvalidPayloadException {
+ if (getConfiguration().isPojoRequest()) {
+ Object payload = exchange.getIn().getMandatoryBody();
+ if (payload instanceof ListUsersRequest) {
+ ListUsersResponse result;
+ try {
+ result = iamClient.listUsers((ListUsersRequest) payload);
+ } catch (AwsServiceException ase) {
+ LOG.trace("List users command returned the error code {}", ase.awsErrorDetails().errorCode());
+ throw ase;
+ }
+ Message message = getMessageForResponse(exchange);
+ message.setBody(result);
+ }
+ } else {
ListUsersResponse result;
try {
result = iamClient.listUsers();
@@ -277,9 +292,24 @@ public class IAM2Producer extends DefaultProducer {
}
Message message = getMessageForResponse(exchange);
message.setBody(result);
+ }
}
- private void createAccessKey(IamClient iamClient, Exchange exchange) {
+ private void createAccessKey(IamClient iamClient, Exchange exchange) throws InvalidPayloadException {
+ if (getConfiguration().isPojoRequest()) {
+ Object payload = exchange.getIn().getMandatoryBody();
+ if (payload instanceof CreateAccessKeyRequest) {
+ CreateAccessKeyResponse result;
+ try {
+ result = iamClient.createAccessKey((CreateAccessKeyRequest) payload);
+ } catch (AwsServiceException ase) {
+ LOG.trace("Create Access Key command returned the error code {}", ase.awsErrorDetails().errorCode());
+ throw ase;
+ }
+ Message message = getMessageForResponse(exchange);
+ message.setBody(result);
+ }
+ } else {
CreateAccessKeyRequest.Builder builder = CreateAccessKeyRequest.builder();
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(IAM2Constants.USERNAME))) {
String userName = exchange.getIn().getHeader(IAM2Constants.USERNAME, String.class);
@@ -294,6 +324,7 @@ public class IAM2Producer extends DefaultProducer {
}
Message message = getMessageForResponse(exchange);
message.setBody(result);
+ }
}
private void deleteAccessKey(IamClient iamClient, Exchange exchange) {