clients: cbc_proxy client inits lambda client

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>
This commit is contained in:
Toby Lorne
2020-10-20 13:33:51 +01:00
parent efa6fb0bd9
commit 14f8e7a5ff
2 changed files with 35 additions and 3 deletions

View File

@@ -1,3 +1,5 @@
import boto3
# Noop = no operation # Noop = no operation
class CBCProxyNoopClient: class CBCProxyNoopClient:
@@ -31,9 +33,12 @@ class CBCProxyNoopClient:
class CBCProxyClient: class CBCProxyClient:
def init_app(self, app): def init_app(self, app):
self.aws_access_key_id = app.config['CBC_PROXY_AWS_ACCESS_KEY_ID'] self._lambda_client = boto3.client(
self.aws_secret_access_key = app.config['CBC_PROXY_AWS_SECRET_ACCESS_KEY'] 'lambda',
self.aws_region = 'eu-west-2' 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'],
)
def create_and_send_broadcast( def create_and_send_broadcast(
self, self,

View File

@@ -0,0 +1,27 @@
import pytest
from app.clients.cbc_proxy import CBCProxyClient
@pytest.fixture(scope='function')
def cbc_proxy(client, mocker):
client = CBCProxyClient()
current_app = mocker.Mock(config={
'CBC_PROXY_AWS_ACCESS_KEY_ID': 'cbc-proxy-aws-access-key-id',
'CBC_PROXY_AWS_SECRET_ACCESS_KEY': 'cbc-proxy-aws-secret-access-key',
})
client.init_app(current_app)
return client
def test_cbc_proxy_lambda_client_has_correct_region(cbc_proxy):
assert cbc_proxy._lambda_client._client_config.region_name == 'eu-west-2'
pass
def test_cbc_proxy_lambda_client_has_correct_keys(cbc_proxy):
key = cbc_proxy._lambda_client._request_signer._credentials.access_key
secret = cbc_proxy._lambda_client._request_signer._credentials.secret_key
assert key == 'cbc-proxy-aws-access-key-id'
assert secret == 'cbc-proxy-aws-secret-access-key'