Commits

dgc committed 10ae74c

sns: add unsubscribe support

Comments (0)

Files changed (1)

 	return 0
 
 
+def op_unsubscribe(sess, args):
+	'''topic endpoint [...]
+	Unsubscribe endpoint[s] from a topic.
+	'''
+
+	if len(args) < 2:
+		error('not enough arguments to unsubscribe')
+		return 2
+
+	errors = 0
+
+	topic = args[0]
+	arns = topicarn(sess, topic)
+	if len(arns) == 0:
+		error('no topics found matching "%s"' % topic)
+		return 30
+	arn = arns[0]
+
+	r = sess.sns.get_all_subscriptions_by_topic(arn)
+	subs = r['ListSubscriptionsByTopicResponse']['ListSubscriptionsByTopicResult']['Subscriptions']
+	for endpoint in args[1:]:
+		success = False
+		for sub in subs:
+			if sub['Endpoint'] in (endpoint, endpoint.lstrip('+').replace('-', '')):
+				status('removing endpoint "%s" from topic "%s"' % (endpoint, topic))
+				sess.sns.unsubscribe(sub['SubscriptionArn'])
+				success = True
+				break
+		if not success:
+			status('endpoint "%s" not found in topic "%s"' % (endpoint, topic))
+			errors += 1
+
+	if errors:
+		return 40
+	return 0
+
+
 def op_publish(sess, args):
 	'''[-f|--file=file] [-s|--subject=subject] topic [message]
 	Publish a notification. If file is -, read from stdin.
 	['subscriptions', op_subscriptions, 0, None],
 	['subs', 'subscriptions'],
 	['subscribe', op_subscribe, 2, None],
+	['unsubscribe', op_unsubscribe, 2, None],
+	['unsub', 'unsubscribe'],
 	['publish', op_publish, 1, None],
 	['send', 'publish'],
 	['shell', op_shell, None, None],
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.