2020-10-20 14:00:53 +01:00
|
|
|
import json
|
|
|
|
|
|
2020-10-20 13:33:51 +01:00
|
|
|
import boto3
|
|
|
|
|
|
2020-10-20 15:18:24 +01:00
|
|
|
|
2020-10-20 11:18:46 +01:00
|
|
|
# Noop = no operation
|
|
|
|
|
class CBCProxyNoopClient:
|
|
|
|
|
|
|
|
|
|
def init_app(self, app):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def create_and_send_broadcast(
|
|
|
|
|
self,
|
|
|
|
|
identifier, headline, description,
|
|
|
|
|
):
|
|
|
|
|
# identifier=broadcast_message.identifier,
|
|
|
|
|
# headline="GOV.UK Notify Broadcast",
|
|
|
|
|
# description=broadcast_message.description,
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
# We have not implementated updating a broadcast
|
|
|
|
|
def update_and_send_broadcast(
|
|
|
|
|
self,
|
|
|
|
|
identifier, references, headline, description,
|
|
|
|
|
):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
# We have not implemented cancelling a broadcast
|
|
|
|
|
def cancel_broadcast(
|
|
|
|
|
self,
|
|
|
|
|
identifier, references, headline, description,
|
|
|
|
|
):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CBCProxyClient:
|
|
|
|
|
|
|
|
|
|
def init_app(self, app):
|
2020-10-20 13:59:52 +01:00
|
|
|
self._ld_client = boto3.client(
|
2020-10-20 13:33:51 +01:00
|
|
|
'lambda',
|
|
|
|
|
region_name='eu-west-2',
|
|
|
|
|
aws_access_key_id=app.config['CBC_PROXY_AWS_ACCESS_KEY_ID'],
|
|
|
|
|
aws_secret_access_key=app.config['CBC_PROXY_AWS_SECRET_ACCESS_KEY'],
|
|
|
|
|
)
|
2020-10-20 11:18:46 +01:00
|
|
|
|
|
|
|
|
def create_and_send_broadcast(
|
|
|
|
|
self,
|
|
|
|
|
identifier, headline, description,
|
|
|
|
|
):
|
2020-10-20 14:00:53 +01:00
|
|
|
payload_bytes = bytes(json.dumps({
|
|
|
|
|
'identifier': identifier,
|
|
|
|
|
'headline': headline,
|
|
|
|
|
'description': description,
|
|
|
|
|
}), encoding='utf8')
|
|
|
|
|
|
2020-10-20 15:18:11 +01:00
|
|
|
result = self._ld_client.invoke(
|
2020-10-20 14:00:53 +01:00
|
|
|
FunctionName='bt-ee-1-proxy',
|
|
|
|
|
InvocationType='RequestResponse',
|
|
|
|
|
Payload=payload_bytes,
|
|
|
|
|
)
|
2020-10-20 15:18:11 +01:00
|
|
|
|
|
|
|
|
if result['StatusCode'] > 299:
|
|
|
|
|
raise Exception('Could not invoke lambda')
|
|
|
|
|
|
|
|
|
|
if 'FunctionError' in result:
|
|
|
|
|
raise Exception('Function exited with unhandled exception')
|
2020-10-20 11:18:46 +01:00
|
|
|
|
|
|
|
|
# We have not implementated updating a broadcast
|
|
|
|
|
def update_and_send_broadcast(
|
|
|
|
|
self,
|
|
|
|
|
identifier, references, headline, description,
|
|
|
|
|
):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
# We have not implemented cancelling a broadcast
|
|
|
|
|
def cancel_broadcast(
|
|
|
|
|
self,
|
|
|
|
|
identifier, references, headline, description,
|
|
|
|
|
):
|
|
|
|
|
pass
|