Non-production environments invoke CBC Proxy during broadcast event creation - #3003
Conversation
We are going to invoke a lambda to send a message to the CBC We need a CBC Proxy Client to do this The Client will be able to send/update/cancel broadcasts in the CBC Unless we have configured the app with AWS credentials for the CBCProxyClient, we just want to use a client that does nothing: the noop client The AWS access keys are separate for the CBC Proxy vs other Notify AWS things because the CBC Proxy lives in another AWS account Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk> Co-authored-by: Pea <pea.tyczynska@digital.cabinet-office.gov.uk> Co-authored-by: Katie <katie.smith@digital.cabinet-office.gov.uk>
When we create a broadcast message, we should invoke the cbc proxy to send a cap message Either a function will be invoked within AWS, or a noop function call is made, depending on the environment We have only implemented CB message creation in the CBC Proxy, without polygons, therefore we: * only invoke the CBC Proxy during message creation * only send description, identifier, and hard-coded headline Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk> Co-authored-by: Pea <pea.tyczynska@digital.cabinet-office.gov.uk> Co-authored-by: Katie <katie.smith@digital.cabinet-office.gov.uk>
it is global rather than local but python cannot infer this and we get UnboundLocalError Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
Using correct: * key id * secret key * region Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk> Co-authored-by: Pea <pea.tyczynska@digital.cabinet-office.gov.uk> Co-authored-by: Katie <katie.smith@digital.cabinet-office.gov.uk>
_ld is better than _lambda because it causes primitive python syntax highlighting to not get confused _lambda is better than _ld because it is less jargon Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk> Co-authored-by: Pea <pea.tyczynska@digital.cabinet-office.gov.uk> Co-authored-by: Katie <katie.smith@digital.cabinet-office.gov.uk>
right now we are doing an end-to-end journey with a CBC from Notify (the CBE) and we would like to approve a broadcast in notify and have it appear on our test handset in order to do this, we: * hook up the lambda that we made in the correct VPC to cbc_proxy client * test that it is called correctly Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk> Co-authored-by: Pea <pea.tyczynska@digital.cabinet-office.gov.uk> Co-authored-by: Katie <katie.smith@digital.cabinet-office.gov.uk>
Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
b79d704 to
62951fa
Compare
Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
23b4642 to
a3293d3
Compare
Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk> Co-authored-by: Katie <katie.smith@digital.cabinet-office.gov.uk>
idavidmcdonald
left a comment
There was a problem hiding this comment.
Nice. Generally looks pretty good and clear.
I think I've spotted two small things that do need changing please, the rest are more optional comments about structure and variable naming that you can implement as you see fit.
|
|
||
|
|
||
| # Noop = no operation | ||
| class CBCProxyNoopClient: |
There was a problem hiding this comment.
Optional but definitely worth considering: I don't know how complex these two classes are going to get but I think I'd suggest creating an abstract class to use as a base for both the CBCProxyClient and the CBCProxyNoopClient that will ensure they have the same methods always
There was a problem hiding this comment.
Given we have no type checker, I am not sure what an abstract class would achieve. Additionally I cannot find any references in the codebase to abstract classes, with the exception of models and celery where __abstract__ and abstract respectively have specific meanings
| # identifier=broadcast_message.identifier, | ||
| # headline="GOV.UK Notify Broadcast", | ||
| # description=broadcast_message.description, | ||
| pass |
There was a problem hiding this comment.
Optional: I wonder if we should put info level logging on the noop methods so that if you ever call say create_and_send_broadcast we get a log like 'CBC no op client mthod create_and_send_broadcast was called with x, y z' for useful debugging
| # identifier=broadcast_message.identifier, | ||
| # headline="GOV.UK Notify Broadcast", | ||
| # description=broadcast_message.description, |
There was a problem hiding this comment.
Optional: Do we want to keep these? Personally, I'm not really that much clearer as someone who hasn't spent much time with the spec what an identifier, headline or description is to be honest by your examples.
There was a problem hiding this comment.
In fact, is 'identifier' semantically different to an 'id'? I don't see an identifier property on the BroadcastMessageEvent class either? Should this argument be an broadcastMessageEvent ID? If so, I might suggest using a param name event_id rather than identifier.
There was a problem hiding this comment.
The comments, as they were, are not useful. I have, in adc2ce8, moved them to the top of the file and attempted to explain why the variable names are why they are: ie they represent specific named fields within CAP
There was a problem hiding this comment.
Cheers, that makes sense. I would wonder if we should abstract the CAP fields to inside the CBCProxy class such that someone calling the methods doesn't need to know what these things are. You don't need to necessarily understand what a CAP identifier is if you only need to know that you always need to provide a broadcast event ID every time you wish to send a broadcast event to a locality. I'll leave for you though, this is much better with the comments you've added, thank you.
| def init_app(self, app): | ||
| self._ld_client = boto3.client( | ||
| 'lambda', | ||
| region_name='eu-west-2', |
There was a problem hiding this comment.
Optional: eu-west-2 could live in config rather than being hard coded
| pass | ||
|
|
||
| # We have not implementated updating a broadcast | ||
| def update_and_send_broadcast( |
There was a problem hiding this comment.
Optional:
I'm not too sure on the method names chosen: create_and_send_broadcast, update_and_send_broadcast and cancel_broadcast.
Each one of them ends up doing the same thing which is sending a broadcast event to the CBC proxy I believe? If so it would be more consistent to have create_and_send_broadcast_event, update_and_send_broadcast_event, cancel_and_send_broadcast_event but in that case I'd be tempted to keep it simpler as create_broadcast, update_broadcast, cancel_broadcast.
I'm not too sure on my suggestions though as my mental is still quite immature on the whole broadcast process so have a read and feel free to make a decision based on what you see fit :)
There was a problem hiding this comment.
We started off with create_broadcast, update_broadcast, and cancel_broadcast
However I did not like create_broadcast and update_broadcast because it seems a bit like an object constructor rather than a thing-doer which is why the _and_send_ infix is present
Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
for code clarity Signed-off-by: Toby Lorne <toby.lornewelch-richards@digital.cabinet-office.gov.uk>
idavidmcdonald
left a comment
There was a problem hiding this comment.
Nice work, cheers for the edits too
What
When a broadcast is approved, and a new Broadcast Event is despatched with status
ALERTwe want to invoke the CBC Proxy which will generate a CAP XML message and send it to the CBCChecklist
Pair
@klssmith @CrystalPea