Restructure govuk-alerts endpoint to be internal

In response to: https://github.com/alphagov/notifications-api/pull/3305#pullrequestreview-726672421

Previously this was added among the public /v2 endpoints, but it's
only meant for internal use. While only the govuk-alerts app would
be able to access it, the location and /v2 URL suggested otherwise.
This restructures the endpoint so it resembles other internal ones.
This commit is contained in:
Ben Thorner
2021-09-15 15:21:20 +01:00
parent d61ec50fb1
commit 6a53871455
7 changed files with 19 additions and 26 deletions

View File

@@ -133,6 +133,7 @@ def register_blueprint(application):
from app.authentication.auth import ( from app.authentication.auth import (
requires_admin_auth, requires_admin_auth,
requires_auth, requires_auth,
requires_govuk_alerts_auth,
requires_no_auth, requires_no_auth,
) )
from app.billing.rest import billing_blueprint from app.billing.rest import billing_blueprint
@@ -140,6 +141,7 @@ def register_blueprint(application):
from app.complaint.complaint_rest import complaint_blueprint from app.complaint.complaint_rest import complaint_blueprint
from app.email_branding.rest import email_branding_blueprint from app.email_branding.rest import email_branding_blueprint
from app.events.rest import events as events_blueprint from app.events.rest import events as events_blueprint
from app.govuk_alerts.rest import govuk_alerts_blueprint
from app.inbound_number.rest import inbound_number_blueprint from app.inbound_number.rest import inbound_number_blueprint
from app.inbound_sms.rest import inbound_sms as inbound_sms_blueprint from app.inbound_sms.rest import inbound_sms as inbound_sms_blueprint
from app.job.rest import job_blueprint from app.job.rest import job_blueprint
@@ -269,18 +271,15 @@ def register_blueprint(application):
broadcast_message_blueprint.before_request(requires_admin_auth) broadcast_message_blueprint.before_request(requires_admin_auth)
application.register_blueprint(broadcast_message_blueprint) application.register_blueprint(broadcast_message_blueprint)
govuk_alerts_blueprint.before_request(requires_govuk_alerts_auth)
application.register_blueprint(govuk_alerts_blueprint)
def register_v2_blueprints(application): def register_v2_blueprints(application):
from app.authentication.auth import ( from app.authentication.auth import requires_auth
requires_auth,
requires_govuk_alerts_auth,
)
from app.v2.broadcast.post_broadcast import ( from app.v2.broadcast.post_broadcast import (
v2_broadcast_blueprint as post_broadcast, v2_broadcast_blueprint as post_broadcast,
) )
from app.v2.govuk_alerts.get_broadcasts import (
v2_govuk_alerts_blueprint as get_broadcasts,
)
from app.v2.inbound_sms.get_inbound_sms import ( from app.v2.inbound_sms.get_inbound_sms import (
v2_inbound_sms_blueprint as get_inbound_sms, v2_inbound_sms_blueprint as get_inbound_sms,
) )
@@ -321,9 +320,6 @@ def register_v2_blueprints(application):
post_broadcast.before_request(requires_auth) post_broadcast.before_request(requires_auth)
application.register_blueprint(post_broadcast) application.register_blueprint(post_broadcast)
get_broadcasts.before_request(requires_govuk_alerts_auth)
application.register_blueprint(get_broadcasts)
def init_app(app): def init_app(app):

View File

@@ -1,11 +1,19 @@
from flask import jsonify from flask import Blueprint, jsonify
from app.dao.broadcast_message_dao import dao_get_all_broadcast_messages from app.dao.broadcast_message_dao import dao_get_all_broadcast_messages
from app.errors import register_errors
from app.utils import get_dt_string_or_none from app.utils import get_dt_string_or_none
from app.v2.govuk_alerts import v2_govuk_alerts_blueprint
govuk_alerts_blueprint = Blueprint(
"govuk-alerts",
__name__,
url_prefix='/govuk-alerts',
)
register_errors(govuk_alerts_blueprint)
@v2_govuk_alerts_blueprint.route('') @govuk_alerts_blueprint.route('')
def get_broadcasts(): def get_broadcasts():
broadcasts = dao_get_all_broadcast_messages() broadcasts = dao_get_all_broadcast_messages()
broadcasts_dict = {"alerts": [{ broadcasts_dict = {"alerts": [{

View File

@@ -1,11 +0,0 @@
from flask import Blueprint
from app.v2.errors import register_errors
v2_govuk_alerts_blueprint = Blueprint(
"v2_govuk-alerts_blueprint",
__name__,
url_prefix='/v2/govuk-alerts',
)
register_errors(v2_govuk_alerts_blueprint)

View File

@@ -81,7 +81,7 @@ def test_requires_admin_auth_should_allow_valid_token_for_request(client):
def test_requires_govuk_alerts_auth_should_allow_valid_token_for_request(client): def test_requires_govuk_alerts_auth_should_allow_valid_token_for_request(client):
jwt_client_id = current_app.config['GOVUK_ALERTS_CLIENT_ID'] jwt_client_id = current_app.config['GOVUK_ALERTS_CLIENT_ID']
header = create_internal_authorization_header(jwt_client_id) header = create_internal_authorization_header(jwt_client_id)
response = client.get('/v2/govuk-alerts', headers=[header]) response = client.get('/govuk-alerts', headers=[header])
assert response.status_code == 200 assert response.status_code == 200

View File

View File

@@ -25,7 +25,7 @@ def test_get_all_broadcasts_returns_list_of_broadcasts_and_200(
jwt_client_id = current_app.config['GOVUK_ALERTS_CLIENT_ID'] jwt_client_id = current_app.config['GOVUK_ALERTS_CLIENT_ID']
header = create_internal_authorization_header(jwt_client_id) header = create_internal_authorization_header(jwt_client_id)
response = client.get('/v2/govuk-alerts', headers=[header]) response = client.get('/govuk-alerts', headers=[header])
json_response = json.loads(response.get_data(as_text=True)) json_response = json.loads(response.get_data(as_text=True))