mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(sns): recognize attributes set during creation of a subscription (#353)
This commit is contained in:
1 parent
98a6bd5639
commit
e6266fde0f
6 files changed
+35
-39
No files matched your search
@@ -115,7 +115,8 @@ public class SnsJsonHandler {
|
||||
String topicArn = request.path("TopicArn").asText(null);
|
||||
String protocol = request.path("Protocol").asText(null);
|
||||
String endpoint = request.path("Endpoint").asText(null);
|
||||
Subscription sub = snsService.subscribe(topicArn, protocol, endpoint, region);
|
||||
Map<String, String> attributes = jsonNodeToMap(request.path("Attributes"));
|
||||
Subscription sub = snsService.subscribe(topicArn, protocol, endpoint, region, attributes);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("SubscriptionArn", sub.getSubscriptionArn());
|
||||
return Response.ok(response).build();
|
||||
|
||||
@@ -123,8 +123,9 @@ public class SnsQueryHandler {
|
||||
String topicArn = getParam(params, "TopicArn");
|
||||
String protocol = getParam(params, "Protocol");
|
||||
String endpoint = getParam(params, "Endpoint");
|
||||
Map<String, String> attributes = extractSnsAttributes(params, "Attributes");
|
||||
try {
|
||||
Subscription sub = snsService.subscribe(topicArn, protocol, endpoint, region);
|
||||
Subscription sub = snsService.subscribe(topicArn, protocol, endpoint, region, attributes);
|
||||
|
||||
String result = new XmlBuilder().elem("SubscriptionArn", sub.getSubscriptionArn()).build();
|
||||
return Response.ok(AwsQueryResponse.envelope("Subscribe", AwsNamespaces.SNS, result)).build();
|
||||
|
||||
@@ -179,7 +179,7 @@ public class SnsService {
|
||||
topicStore.put(key, topic);
|
||||
}
|
||||
|
||||
public Subscription subscribe(String topicArn, String protocol, String endpoint, String region) {
|
||||
public Subscription subscribe(String topicArn, String protocol, String endpoint, String region, Map<String, String> attributes) {
|
||||
String topicKey = topicKey(region, topicArn);
|
||||
if (topicStore.get(topicKey).isEmpty()) {
|
||||
throw new AwsException("NotFound", "Topic does not exist.", 404);
|
||||
@@ -198,6 +198,7 @@ public class SnsService {
|
||||
String subscriptionArn = topicArn + ":" + UUID.randomUUID().toString();
|
||||
Subscription subscription = new Subscription(subscriptionArn, topicArn, protocol, endpoint,
|
||||
regionResolver.getAccountId());
|
||||
if (attributes != null) subscription.getAttributes().putAll(attributes);
|
||||
|
||||
if (PENDING_CONFIRMATION_PROTOCOLS.contains(protocol)) {
|
||||
String token = UUID.randomUUID().toString().replace("-", "")
|
||||
@@ -209,7 +210,11 @@ public class SnsService {
|
||||
}
|
||||
|
||||
subscriptionStore.put(subKey(region, subscriptionArn), subscription);
|
||||
LOG.infov("Subscribed {0} ({1}) to topic {2} in {3}", endpoint, protocol, topicArn, region);
|
||||
if (attributes == null || attributes.isEmpty()) {
|
||||
LOG.infov("Subscribed {0} ({1}) to topic {2} in {3}", endpoint, protocol, topicArn, region);
|
||||
} else {
|
||||
LOG.infov("Subscribed {0} ({1}) to topic {2} in {3} with attributes: {4}", endpoint, protocol, topicArn, region, attributes);
|
||||
}
|
||||
return subscription;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user