2016-02-03 13:16:19 +00:00
|
|
|
import uuid
|
|
|
|
|
import boto3
|
|
|
|
|
from itsdangerous import URLSafeSerializer
|
|
|
|
|
from flask import current_app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_notification_to_queue(service_id, template_id, type_, notification):
|
|
|
|
|
q = boto3.resource(
|
|
|
|
|
'sqs', region_name=current_app.config['AWS_REGION']
|
2016-02-05 11:12:59 +00:00
|
|
|
).create_queue(QueueName="{}_{}".format(
|
|
|
|
|
current_app.config['NOTIFICATION_QUEUE_PREFIX'],
|
|
|
|
|
str(service_id)))
|
2016-02-10 11:15:41 +00:00
|
|
|
notification_id = str(uuid.uuid4())
|
2016-02-03 13:16:19 +00:00
|
|
|
serializer = URLSafeSerializer(current_app.config.get('SECRET_KEY'))
|
|
|
|
|
encrypted = serializer.dumps(notification, current_app.config.get('DANGEROUS_SALT'))
|
|
|
|
|
q.send_message(MessageBody=encrypted,
|
|
|
|
|
MessageAttributes={'type': {'StringValue': type_, 'DataType': 'String'},
|
2016-02-10 11:15:41 +00:00
|
|
|
'notification_id': {'StringValue': notification_id, 'DataType': 'String'},
|
2016-02-03 13:16:19 +00:00
|
|
|
'service_id': {'StringValue': str(service_id), 'DataType': 'String'},
|
|
|
|
|
'template_id': {'StringValue': str(template_id), 'DataType': 'String'}})
|
2016-02-10 11:15:41 +00:00
|
|
|
return notification_id
|