From e8bf03c7e139d390ba31c44eb0ec90a2ab0c08a7 Mon Sep 17 00:00:00 2001 From: bandesz Date: Fri, 3 Mar 2017 11:07:29 +0000 Subject: [PATCH 1/2] Get Redis config from PaaS --- app/cloudfoundry_config.py | 7 +++++++ manifest-api-base.yml | 1 + manifest-delivery-base.yml | 1 + tests/app/test_cloudfoundry_config.py | 25 +++++++++++++++++++++++-- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/cloudfoundry_config.py b/app/cloudfoundry_config.py index ed8f7f350..c11c8a82c 100644 --- a/app/cloudfoundry_config.py +++ b/app/cloudfoundry_config.py @@ -32,6 +32,8 @@ def set_config_env_vars(vcap_services): extract_mmg_config(s) elif s['name'] == 'firetext': extract_firetext_config(s) + elif s['name'] == 'redis': + extract_redis_config(s) def extract_notify_config(notify_config): @@ -60,3 +62,8 @@ def extract_mmg_config(mmg_config): def extract_firetext_config(firetext_config): os.environ['FIRETEXT_API_KEY'] = firetext_config['credentials']['api_key'] os.environ['LOADTESTING_API_KEY'] = firetext_config['credentials']['loadtesting_api_key'] + + +def extract_redis_config(redis_config): + os.environ['REDIS_ENABLED'] = redis_config['credentials']['redis_enabled'] + os.environ['REDIS_URL'] = redis_config['credentials']['redis_url'] diff --git a/manifest-api-base.yml b/manifest-api-base.yml index 433a567f2..946a99940 100644 --- a/manifest-api-base.yml +++ b/manifest-api-base.yml @@ -9,6 +9,7 @@ services: - mmg - firetext - hosted-graphite + - redis env: NOTIFY_APP_NAME: public-api CW_APP_NAME: api diff --git a/manifest-delivery-base.yml b/manifest-delivery-base.yml index d03e37fdc..8ae95dac3 100644 --- a/manifest-delivery-base.yml +++ b/manifest-delivery-base.yml @@ -10,6 +10,7 @@ services: - mmg - firetext - hosted-graphite + - redis instances: 1 memory: 512M diff --git a/tests/app/test_cloudfoundry_config.py b/tests/app/test_cloudfoundry_config.py index 9b29d90ef..bc039b832 100644 --- a/tests/app/test_cloudfoundry_config.py +++ b/tests/app/test_cloudfoundry_config.py @@ -75,6 +75,17 @@ def postgres_config(): ] +@pytest.fixture +def redis_config(): + return { + 'name': 'redis', + 'credentials': { + 'redis_enabled': '1', + 'redis_url': 'redis url' + } + } + + @pytest.fixture def cloudfoundry_config( postgres_config, @@ -82,7 +93,8 @@ def cloudfoundry_config( aws_config, hosted_graphite_config, mmg_config, - firetext_config + firetext_config, + redis_config ): return { 'postgres': postgres_config, @@ -91,7 +103,8 @@ def cloudfoundry_config( aws_config, hosted_graphite_config, mmg_config, - firetext_config + firetext_config, + redis_config ] } @@ -165,3 +178,11 @@ def test_firetext_config(): assert os.environ['FIRETEXT_API_KEY'] == 'firetext api key' assert os.environ['LOADTESTING_API_KEY'] == 'loadtesting api key' + + +@pytest.mark.usefixtures('os_environ', 'cloudfoundry_environ') +def test_redis_config(): + extract_cloudfoundry_config() + + assert os.environ['REDIS_ENABLED'] == '1' + assert os.environ['REDIS_URL'] == 'redis url' From 271b664a7e9d1820c1e20d9030e2e383b29f12c1 Mon Sep 17 00:00:00 2001 From: bandesz Date: Fri, 3 Mar 2017 12:13:41 +0000 Subject: [PATCH 2/2] Log SNS subscription URL --- app/notifications/rest.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/notifications/rest.py b/app/notifications/rest.py index 69418a6bb..4f3282cb9 100644 --- a/app/notifications/rest.py +++ b/app/notifications/rest.py @@ -54,6 +54,10 @@ def process_ses_response(): client_name = 'SES' try: ses_request = json.loads(request.data) + + if 'Type' in ses_request and ses_request['Type'] == 'SubscriptionConfirmation': + current_app.logger.info("SNS subscription confirmation url: {}".format(ses_request['SubscribeURL'])) + errors = validate_callback_data(data=ses_request, fields=['Message'], client_name=client_name) if errors: raise InvalidRequest(errors, status_code=400)