From 509cce38f40e745faf1d6a43fc94ac8202064693 Mon Sep 17 00:00:00 2001 From: Jim Moffet Date: Thu, 30 Jun 2022 17:05:42 -0700 Subject: [PATCH 01/18] set up basicauth config to protect staging site --- app/__init__.py | 5 ++++- app/config.py | 14 +++++++++++--- app/main/views/index.py | 2 +- devcontainer-admin/.devcontainer.json | 5 +++-- devcontainer-admin/Dockerfile | 1 + .../scripts/notify-admin-entrypoint.sh | 6 +++++- manifest.yml | 2 -- requirements.in | 1 + requirements.txt | 2 ++ varsfile.sample | 2 ++ 10 files changed, 30 insertions(+), 10 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 39ea3f285..0c4dd51d2 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -19,6 +19,7 @@ from flask.globals import _lookup_req_object, _request_ctx_stack from flask_login import LoginManager, current_user from flask_wtf import CSRFProtect from flask_wtf.csrf import CSRFError +from flask_basicauth import BasicAuth from gds_metrics import GDSMetrics from govuk_frontend_jinja.flask_ext import init_govuk_frontend from itsdangerous import BadSignature @@ -134,7 +135,7 @@ from app.url_converters import ( login_manager = LoginManager() csrf = CSRFProtect() metrics = GDSMetrics() - +basic_auth = BasicAuth() # The current service attached to the request stack. def _get_current_service(): @@ -220,6 +221,8 @@ def create_app(application): login_manager.login_message_category = 'default' login_manager.session_protection = None login_manager.anonymous_user = AnonymousUser + + basic_auth = BasicAuth(application) # make sure we handle unicode correctly redis_client.redis_store.decode_responses = True diff --git a/app/config.py b/app/config.py index 33baca579..f16963582 100644 --- a/app/config.py +++ b/app/config.py @@ -10,7 +10,7 @@ if os.environ.get('VCAP_APPLICATION'): class Config(object): ADMIN_CLIENT_SECRET = os.environ.get('ADMIN_CLIENT_SECRET') - API_HOST_NAME = os.environ.get('API_HOST_NAME') + API_HOST_NAME = os.environ.get('API_HOST_NAME', 'https://notifications-api.app.cloud.gov') SECRET_KEY = os.environ.get('SECRET_KEY') DANGEROUS_SALT = os.environ.get('DANGEROUS_SALT') ZENDESK_API_KEY = os.environ.get('ZENDESK_API_KEY') @@ -62,13 +62,17 @@ class Config(object): LOGO_UPLOAD_BUCKET_NAME = 'public-logos-local' MOU_BUCKET_NAME = 'local-mou' TRANSIENT_UPLOADED_LETTERS = 'local-transient-uploaded-letters' - ROUTE_SECRET_KEY_1 = os.environ.get('ROUTE_SECRET_KEY_1', '') - ROUTE_SECRET_KEY_2 = os.environ.get('ROUTE_SECRET_KEY_2', '') + ROUTE_SECRET_KEY_1 = os.environ.get('ROUTE_SECRET_KEY_1', 'dev-route-secret-key-1') + ROUTE_SECRET_KEY_2 = os.environ.get('ROUTE_SECRET_KEY_2', 'dev-route-secret-key-2') CHECK_PROXY_HEADER = False ANTIVIRUS_ENABLED = True REDIS_URL = os.environ.get('REDIS_URL') REDIS_ENABLED = True + + BASIC_AUTH_USERNAME = os.environ.get('BASIC_AUTH_USERNAME') + BASIC_AUTH_PASSWORD = os.environ.get('BASIC_AUTH_PASSWORD') + BASIC_AUTH_FORCE = True ASSET_DOMAIN = '' ASSET_PATH = '/static/' @@ -93,6 +97,7 @@ class Config(object): class Development(Config): + BASIC_AUTH_FORCE = True NOTIFY_LOG_PATH = 'application.log' DEBUG = True SESSION_COOKIE_SECURE = False @@ -143,6 +148,7 @@ class Test(Development): class Preview(Config): + BASIC_AUTH_FORCE = True HTTP_PROTOCOL = 'https' HEADER_COLOUR = '#F499BE' # $baby-pink CSV_UPLOAD_BUCKET_NAME = 'preview-notifications-csv-upload' @@ -162,6 +168,7 @@ class Preview(Config): class Staging(Config): + BASIC_AUTH_FORCE = True HTTP_PROTOCOL = 'https' HEADER_COLOUR = '#6F72AF' # $mauve CSV_UPLOAD_BUCKET_NAME = 'staging-notifications-csv-upload' @@ -178,6 +185,7 @@ class Staging(Config): class Live(Config): + BASIC_AUTH_FORCE = True HEADER_COLOUR = '#005EA5' # $govuk-blue HTTP_PROTOCOL = 'https' CSV_UPLOAD_BUCKET_NAME = 'notifications.prototype.csv_upload' diff --git a/app/main/views/index.py b/app/main/views/index.py index b997ee232..06a6ecfc4 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -30,7 +30,7 @@ def index(): return render_template( 'views/signedout.html', sms_rate=CURRENT_SMS_RATE, - counts=status_api_client.get_count_of_live_services_and_organisations(), + counts=status_api_client.get_count_of_live_services_and_organisations() ) diff --git a/devcontainer-admin/.devcontainer.json b/devcontainer-admin/.devcontainer.json index d14e66411..814c9f2d7 100644 --- a/devcontainer-admin/.devcontainer.json +++ b/devcontainer-admin/.devcontainer.json @@ -13,7 +13,8 @@ }, "python.linting.enabled": true, "python.linting.pylintEnabled": true, - "python.pythonPath": "/usr/local/bin/python" + "python.pythonPath": "/usr/local/bin/python", + "python.linting.pylintPath": "/usr/local/share/pip-global/bin/pylint" }, "features": { "docker-from-docker": { @@ -22,7 +23,7 @@ } }, "extensions": [ - "ms-python.black-formatter", + "ms-python.python", // "ms-python.black-formatter" "donjayamanne.python-extension-pack", "ms-azuretools.vscode-docker", "ms-python.vscode-pylance", diff --git a/devcontainer-admin/Dockerfile b/devcontainer-admin/Dockerfile index 0b6616235..9c28570be 100644 --- a/devcontainer-admin/Dockerfile +++ b/devcontainer-admin/Dockerfile @@ -28,6 +28,7 @@ RUN apt-get update \ tldr \ unzip \ vim \ + apache2-utils \ && apt-get autoremove -y \ && apt-get clean -y \ && rm -rf /var/lib/apt/lists/* diff --git a/devcontainer-admin/scripts/notify-admin-entrypoint.sh b/devcontainer-admin/scripts/notify-admin-entrypoint.sh index 26a300fa0..5af89b960 100755 --- a/devcontainer-admin/scripts/notify-admin-entrypoint.sh +++ b/devcontainer-admin/scripts/notify-admin-entrypoint.sh @@ -7,6 +7,8 @@ set -ex # tools and the filesystem mount enabled should be located here. ################################################################### +echo "RUNNING ENTRYPOINT SCRIPT" + # Define aliases echo -e "\n\n# User's Aliases" >> ~/.zshrc echo -e "alias fd=fdfind" >> ~/.zshrc @@ -33,4 +35,6 @@ make generate-version-file npm run build # run flask -# make run \ No newline at end of file +# make run + +echo "FINISHED ENTRYPOINT SCRIPT" \ No newline at end of file diff --git a/manifest.yml b/manifest.yml index 7b0b9704b..2c99307a5 100644 --- a/manifest.yml +++ b/manifest.yml @@ -29,8 +29,6 @@ applications: API_HOST_NAME: notifications-api.app.cloud.gov DANGEROUS_SALT: ((DANGEROUS_SALT)) SECRET_KEY: ((SECRET_KEY)) - ROUTE_SECRET_KEY_1: ((ROUTE_SECRET_KEY_1)) - ROUTE_SECRET_KEY_2: ((ROUTE_SECRET_KEY_2)) AWS_REGION: us-west-2 AWS_ACCESS_KEY_ID: ((AWS_ACCESS_KEY_ID)) diff --git a/requirements.in b/requirements.in index dd5ab2761..b1dc387d0 100644 --- a/requirements.in +++ b/requirements.in @@ -10,6 +10,7 @@ wtforms==3.0.1 Flask-Login==0.6.1 Werkzeug==2.1.2 jinja2==3.1.2 +Flask-BasicAuth==0.2.0 blinker==1.4 pyexcel==0.7.0 diff --git a/requirements.txt b/requirements.txt index f3cb81f49..1eba90250 100644 --- a/requirements.txt +++ b/requirements.txt @@ -71,6 +71,8 @@ flask-redis==0.4.0 # via notifications-utils flask-wtf==1.0.1 # via -r requirements.in +Flask-BasicAuth==0.2.0 + # via -r requirements.in gds-metrics @ git+https://github.com/alphagov/gds_metrics_python.git@6f1840a57b6fb1ee40b7e84f2f18ec229de8aa72 # via -r requirements.in geojson==2.5.0 diff --git a/varsfile.sample b/varsfile.sample index 4045654e7..cc0fef4ee 100644 --- a/varsfile.sample +++ b/varsfile.sample @@ -5,3 +5,5 @@ ROUTE_SECRET_KEY_1: asdf ROUTE_SECRET_KEY_2: asdf AWS_ACCESS_KEY_ID: asdf AWS_SECRET_ACCESS_KEY: asdf +BASIC_AUTH_USERNAME: asdf +BASIC_AUTH_PASSWORD: asdf From 1e979ad5197f19ad35a026e2674850ad7a4e7804 Mon Sep 17 00:00:00 2001 From: Jim Moffet Date: Fri, 1 Jul 2022 07:58:58 -0700 Subject: [PATCH 02/18] fix basic auth for live environment --- .flake8 | 15 --------------- app/__init__.py | 19 ++++++++++++++++++- app/config.py | 4 ++-- app/custom_auth.py | 17 +++++++++++++++++ app/main/views/index.py | 3 ++- app/status/views/healthcheck.py | 16 +++++++++++++++- application.log.json | 18 ++++++++++++++++++ manifest.yml | 7 +++++-- varsfile.sample | 1 + 9 files changed, 78 insertions(+), 22 deletions(-) delete mode 100644 .flake8 create mode 100644 app/custom_auth.py create mode 100644 application.log.json diff --git a/.flake8 b/.flake8 deleted file mode 100644 index dc53bee7e..000000000 --- a/.flake8 +++ /dev/null @@ -1,15 +0,0 @@ -[flake8] -# Rule definitions: http://flake8.pycqa.org/en/latest/user/error-codes.html -exclude = venv*,__pycache__,node_modules,cache -max-complexity = 14 -max-line-length = 120 - -# B003 assigning to os.environ -# B306 BaseException.message has been deprecated -# W503: line break before binary operator -# W504 line break after binary operator -extend_ignore= - B003, - B306, - W503, - W504 diff --git a/app/__init__.py b/app/__init__.py index 0c4dd51d2..76bf55333 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -14,6 +14,7 @@ from flask import ( request, session, url_for, + jsonify ) from flask.globals import _lookup_req_object, _request_ctx_stack from flask_login import LoginManager, current_user @@ -222,7 +223,9 @@ def create_app(application): login_manager.session_protection = None login_manager.anonymous_user = AnonymousUser - basic_auth = BasicAuth(application) + # basic_auth = BasicAuth(application) + + setup_basic_auth(application) # make sure we handle unicode correctly redis_client.redis_store.decode_responses = True @@ -589,3 +592,17 @@ def init_jinja(application): ] jinja_loader = jinja2.FileSystemLoader(template_folders) application.jinja_loader = jinja_loader + +class CustomBasicAuth(BasicAuth): + """ + Description: + Override BasicAuth to permit anonymous healthcheck at /_status?simple=true + """ + def challenge(self): + if "/_status" in request.url: + if request.args.get('elb', None) or request.args.get('simple', None): + return jsonify(status="ok"), 200 + return super(CustomBasicAuth, self).challenge() + +def setup_basic_auth(application): + application.basic_auth = CustomBasicAuth(application) diff --git a/app/config.py b/app/config.py index f16963582..c6c0d1fc8 100644 --- a/app/config.py +++ b/app/config.py @@ -23,7 +23,7 @@ class Config(object): # Logging DEBUG = False - NOTIFY_LOG_PATH = os.getenv('NOTIFY_LOG_PATH') + NOTIFY_LOG_PATH = os.environ.get('NOTIFY_LOG_PATH', 'application.log') ADMIN_CLIENT_USER_NAME = 'notify-admin' @@ -40,7 +40,7 @@ class Config(object): HEADER_COLOUR = '#81878b' # mix(govuk-colour("dark-grey"), govuk-colour("mid-grey")) HTTP_PROTOCOL = 'http' NOTIFY_APP_NAME = 'admin' - NOTIFY_LOG_LEVEL = 'DEBUG' + NOTIFY_LOG_LEVEL = os.environ.get('NOTIFY_LOG_LEVEL', 'DEBUG') PERMANENT_SESSION_LIFETIME = 20 * 60 * 60 # 20 hours SEND_FILE_MAX_AGE_DEFAULT = 365 * 24 * 60 * 60 # 1 year SESSION_COOKIE_HTTPONLY = True diff --git a/app/custom_auth.py b/app/custom_auth.py new file mode 100644 index 000000000..3989878c3 --- /dev/null +++ b/app/custom_auth.py @@ -0,0 +1,17 @@ +from flask_basicauth import BasicAuth +from flask import jsonify, request + +class CustomBasicAuth(BasicAuth): + """ + Description: + + Usage: + + """ + + def check_credentials(self, username, password): + # here, for example, you can search user in the database by passed `username` and `password`, etc. + return username == 'user' and password == 'password' + + +custom_basic_auth = CustomBasicAuth() \ No newline at end of file diff --git a/app/main/views/index.py b/app/main/views/index.py index 06a6ecfc4..e0e6ae7e7 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -30,7 +30,8 @@ def index(): return render_template( 'views/signedout.html', sms_rate=CURRENT_SMS_RATE, - counts=status_api_client.get_count_of_live_services_and_organisations() + counts={"organisations":0,"services":1} + # counts=status_api_client.get_count_of_live_services_and_organisations() ) diff --git a/app/status/views/healthcheck.py b/app/status/views/healthcheck.py index 11b5871af..7e54469ac 100644 --- a/app/status/views/healthcheck.py +++ b/app/status/views/healthcheck.py @@ -1,9 +1,23 @@ from flask import current_app, jsonify, request from notifications_python_client.errors import HTTPError -from app import status_api_client, version +from app import status_api_client, version, basic_auth from app.status import status +from functools import wraps + + +def health_check(): + def wrapper(fn): + @wraps(fn) + def decorator(*args, **kwargs): + return jsonify(status="ok"), 200 + # if '/_status' in request.url: + # return jsonify(status="ok"), 200 + # else: + # return fn(*args, **kwargs) + return decorator + return wrapper @status.route('/_status', methods=['GET']) def show_status(): diff --git a/application.log.json b/application.log.json new file mode 100644 index 000000000..83e31fd48 --- /dev/null +++ b/application.log.json @@ -0,0 +1,18 @@ +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T04:52:54", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "ERROR", "message": "The session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret.", "pathname": "/workspace/app/__init__.py", "lineno": 493, "exc_info": "Traceback (most recent call last):\n File \"/home/vscode/.local/lib/python3.9/site-packages/flask/app.py\", line 1521, in full_dispatch_request\n rv = self.preprocess_request()\n File \"/home/vscode/.local/lib/python3.9/site-packages/flask/app.py\", line 1861, in preprocess_request\n rv = self.ensure_sync(before_func)()\n File \"/workspace/app/__init__.py\", line 306, in make_session_permanent\n session.permanent = True\n File \"/home/vscode/.local/lib/python3.9/site-packages/flask/sessions.py\", line 30, in permanent\n self[\"_permanent\"] = bool(value)\n File \"/home/vscode/.local/lib/python3.9/site-packages/flask/sessions.py\", line 97, in _fail\n raise RuntimeError(\nRuntimeError: The session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret.", "time": "2022-07-01T04:54:13", "requestId": null, "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:18:26", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:32:47", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:32:48", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:37:27", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:38:38", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:38:44", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:39:27", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:39:28", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:40:02", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:40:03", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:40:23", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:40:25", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:47:05", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:47:06", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:53:38", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:53:39", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} diff --git a/manifest.yml b/manifest.yml index 2c99307a5..179a56b92 100644 --- a/manifest.yml +++ b/manifest.yml @@ -25,13 +25,16 @@ applications: # Credentials variables ADMIN_CLIENT_SECRET: ((ADMIN_CLIENT_SECRET)) - ADMIN_BASE_URL: notifications-admin.app.cloud.gov - API_HOST_NAME: notifications-api.app.cloud.gov + ADMIN_BASE_URL: https://notifications-admin.app.cloud.gov + API_HOST_NAME: https://notifications-api.app.cloud.gov DANGEROUS_SALT: ((DANGEROUS_SALT)) SECRET_KEY: ((SECRET_KEY)) AWS_REGION: us-west-2 AWS_ACCESS_KEY_ID: ((AWS_ACCESS_KEY_ID)) AWS_SECRET_ACCESS_KEY: ((AWS_SECRET_ACCESS_KEY)) + BASIC_AUTH_USERNAME: ((BASIC_AUTH_USERNAME)) + BASIC_AUTH_PASSWORD: ((BASIC_AUTH_PASSWORD)) + NOTIFY_LOG_LEVEL: ((NOTIFY_LOG_LEVEL)) NOTIFY_BILLING_DETAILS: [] diff --git a/varsfile.sample b/varsfile.sample index cc0fef4ee..c4c7a6d54 100644 --- a/varsfile.sample +++ b/varsfile.sample @@ -7,3 +7,4 @@ AWS_ACCESS_KEY_ID: asdf AWS_SECRET_ACCESS_KEY: asdf BASIC_AUTH_USERNAME: asdf BASIC_AUTH_PASSWORD: asdf +NOTIFY_LOG_LEVEL: asdf From 1c5d432427c6403bff181a79092512fdc4edb08e Mon Sep 17 00:00:00 2001 From: Jim Moffet Date: Fri, 1 Jul 2022 11:19:58 -0700 Subject: [PATCH 03/18] clean up and turn off auth for test env --- .gitignore | 2 ++ app/config.py | 1 + app/main/views/index.py | 3 +-- app/status/views/healthcheck.py | 14 +------------- application.log.json | 9 +++++++++ .../scripts/notify-admin-entrypoint.sh | 2 +- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 449df7b66..962dff7e1 100644 --- a/.gitignore +++ b/.gitignore @@ -109,6 +109,8 @@ environment.sh .env .env* varsfile +*.log.json +logs/** # CloudFoundry .cf diff --git a/app/config.py b/app/config.py index c6c0d1fc8..5760827a9 100644 --- a/app/config.py +++ b/app/config.py @@ -126,6 +126,7 @@ class Development(Config): class Test(Development): + BASIC_AUTH_FORCE = False DEBUG = True TESTING = True WTF_CSRF_ENABLED = False diff --git a/app/main/views/index.py b/app/main/views/index.py index e0e6ae7e7..06a6ecfc4 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -30,8 +30,7 @@ def index(): return render_template( 'views/signedout.html', sms_rate=CURRENT_SMS_RATE, - counts={"organisations":0,"services":1} - # counts=status_api_client.get_count_of_live_services_and_organisations() + counts=status_api_client.get_count_of_live_services_and_organisations() ) diff --git a/app/status/views/healthcheck.py b/app/status/views/healthcheck.py index 7e54469ac..cc20b7819 100644 --- a/app/status/views/healthcheck.py +++ b/app/status/views/healthcheck.py @@ -1,24 +1,12 @@ from flask import current_app, jsonify, request from notifications_python_client.errors import HTTPError -from app import status_api_client, version, basic_auth +from app import status_api_client, version from app.status import status from functools import wraps -def health_check(): - def wrapper(fn): - @wraps(fn) - def decorator(*args, **kwargs): - return jsonify(status="ok"), 200 - # if '/_status' in request.url: - # return jsonify(status="ok"), 200 - # else: - # return fn(*args, **kwargs) - return decorator - return wrapper - @status.route('/_status', methods=['GET']) def show_status(): if request.args.get('elb', None) or request.args.get('simple', None): diff --git a/application.log.json b/application.log.json index 83e31fd48..408f3a048 100644 --- a/application.log.json +++ b/application.log.json @@ -16,3 +16,12 @@ {"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:47:06", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} {"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:53:38", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} {"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:53:39", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:04:09", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:05:26", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:06:32", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:07:00", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:07:15", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:07:16", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:07:40", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:12:24", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} +{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:19:20", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} diff --git a/devcontainer-admin/scripts/notify-admin-entrypoint.sh b/devcontainer-admin/scripts/notify-admin-entrypoint.sh index 5af89b960..4f6beec82 100755 --- a/devcontainer-admin/scripts/notify-admin-entrypoint.sh +++ b/devcontainer-admin/scripts/notify-admin-entrypoint.sh @@ -37,4 +37,4 @@ npm run build # run flask # make run -echo "FINISHED ENTRYPOINT SCRIPT" \ No newline at end of file +echo "FINISHED ENTRYPOINT SCRIPT" From 8fa0af523bb30f410be54ba1193eded727c1de0c Mon Sep 17 00:00:00 2001 From: Jim Moffet Date: Fri, 1 Jul 2022 11:24:25 -0700 Subject: [PATCH 04/18] delete local log file --- .gitignore | 1 - application.log.json | 27 --------------------------- 2 files changed, 28 deletions(-) delete mode 100644 application.log.json diff --git a/.gitignore b/.gitignore index 962dff7e1..93d1f6126 100644 --- a/.gitignore +++ b/.gitignore @@ -109,7 +109,6 @@ environment.sh .env .env* varsfile -*.log.json logs/** # CloudFoundry diff --git a/application.log.json b/application.log.json deleted file mode 100644 index 408f3a048..000000000 --- a/application.log.json +++ /dev/null @@ -1,27 +0,0 @@ -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T04:52:54", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "ERROR", "message": "The session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret.", "pathname": "/workspace/app/__init__.py", "lineno": 493, "exc_info": "Traceback (most recent call last):\n File \"/home/vscode/.local/lib/python3.9/site-packages/flask/app.py\", line 1521, in full_dispatch_request\n rv = self.preprocess_request()\n File \"/home/vscode/.local/lib/python3.9/site-packages/flask/app.py\", line 1861, in preprocess_request\n rv = self.ensure_sync(before_func)()\n File \"/workspace/app/__init__.py\", line 306, in make_session_permanent\n session.permanent = True\n File \"/home/vscode/.local/lib/python3.9/site-packages/flask/sessions.py\", line 30, in permanent\n self[\"_permanent\"] = bool(value)\n File \"/home/vscode/.local/lib/python3.9/site-packages/flask/sessions.py\", line 97, in _fail\n raise RuntimeError(\nRuntimeError: The session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret.", "time": "2022-07-01T04:54:13", "requestId": null, "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:18:26", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:32:47", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:32:48", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:37:27", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:38:38", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:38:44", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:39:27", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:39:28", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:40:02", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:40:03", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:40:23", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:40:25", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:47:05", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:47:06", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:53:38", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T05:53:39", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:04:09", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:05:26", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:06:32", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:07:00", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:07:15", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:07:16", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:07:40", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:12:24", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} -{"name": "app", "levelname": "INFO", "message": "Logging configured", "pathname": "/home/vscode/.local/lib/python3.9/site-packages/notifications_utils/logging.py", "lineno": 37, "time": "2022-07-01T18:19:20", "requestId": "no-request-id", "application": "admin", "service_id": "no-service-id", "logType": "application"} From f8f87e059676e7f9457441e298efbd6dc77f3072 Mon Sep 17 00:00:00 2001 From: Jim Moffet Date: Fri, 1 Jul 2022 11:24:51 -0700 Subject: [PATCH 05/18] ignore local log file --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 93d1f6126..962dff7e1 100644 --- a/.gitignore +++ b/.gitignore @@ -109,6 +109,7 @@ environment.sh .env .env* varsfile +*.log.json logs/** # CloudFoundry From e9a3b3d5e3087dffe57a365511cbb68b964b34a1 Mon Sep 17 00:00:00 2001 From: Jim Moffet Date: Fri, 1 Jul 2022 11:34:51 -0700 Subject: [PATCH 06/18] move CustomBasicAuth override to import --- app/__init__.py | 21 +++++++++++---------- app/custom_auth.py | 16 +++++++--------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 76bf55333..2b7748d9c 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -39,6 +39,7 @@ from werkzeug.local import LocalProxy from app import proxy_fix, webauthn_server from app.asset_fingerprinter import asset_fingerprinter from app.config import configs +from app.custom_auth import CustomBasicAuth from app.extensions import antivirus_client, redis_client, zendesk_client from app.formatters import ( convert_to_boolean, @@ -593,16 +594,16 @@ def init_jinja(application): jinja_loader = jinja2.FileSystemLoader(template_folders) application.jinja_loader = jinja_loader -class CustomBasicAuth(BasicAuth): - """ - Description: - Override BasicAuth to permit anonymous healthcheck at /_status?simple=true - """ - def challenge(self): - if "/_status" in request.url: - if request.args.get('elb', None) or request.args.get('simple', None): - return jsonify(status="ok"), 200 - return super(CustomBasicAuth, self).challenge() +# class CustomBasicAuth(BasicAuth): +# """ +# Description: +# Override BasicAuth to permit anonymous healthcheck at /_status?simple=true +# """ +# def challenge(self): +# if "/_status" in request.url: +# if request.args.get('elb', None) or request.args.get('simple', None): +# return jsonify(status="ok"), 200 +# return super(CustomBasicAuth, self).challenge() def setup_basic_auth(application): application.basic_auth = CustomBasicAuth(application) diff --git a/app/custom_auth.py b/app/custom_auth.py index 3989878c3..b8310cedb 100644 --- a/app/custom_auth.py +++ b/app/custom_auth.py @@ -3,15 +3,13 @@ from flask import jsonify, request class CustomBasicAuth(BasicAuth): """ - Description: - - Usage: - + Description: + Override BasicAuth to permit anonymous healthcheck at /_status?simple=true """ - - def check_credentials(self, username, password): - # here, for example, you can search user in the database by passed `username` and `password`, etc. - return username == 'user' and password == 'password' - + def challenge(self): + if "/_status" in request.url: + if request.args.get('elb', None) or request.args.get('simple', None): + return jsonify(status="ok"), 200 + return super(CustomBasicAuth, self).challenge() custom_basic_auth = CustomBasicAuth() \ No newline at end of file From b8d5a0b5eb060bb57bbc524e21fce8b21deeaa12 Mon Sep 17 00:00:00 2001 From: Jim Moffet Date: Fri, 1 Jul 2022 11:36:15 -0700 Subject: [PATCH 07/18] clean comments --- app/__init__.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 2b7748d9c..e5acfa7ac 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -594,16 +594,5 @@ def init_jinja(application): jinja_loader = jinja2.FileSystemLoader(template_folders) application.jinja_loader = jinja_loader -# class CustomBasicAuth(BasicAuth): -# """ -# Description: -# Override BasicAuth to permit anonymous healthcheck at /_status?simple=true -# """ -# def challenge(self): -# if "/_status" in request.url: -# if request.args.get('elb', None) or request.args.get('simple', None): -# return jsonify(status="ok"), 200 -# return super(CustomBasicAuth, self).challenge() - def setup_basic_auth(application): application.basic_auth = CustomBasicAuth(application) From 40013327414d01e879698f1e5e043b702ea89d29 Mon Sep 17 00:00:00 2001 From: Jim Moffet Date: Fri, 1 Jul 2022 11:36:47 -0700 Subject: [PATCH 08/18] clean comments --- app/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index e5acfa7ac..4168e236f 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -223,9 +223,7 @@ def create_app(application): login_manager.login_message_category = 'default' login_manager.session_protection = None login_manager.anonymous_user = AnonymousUser - - # basic_auth = BasicAuth(application) - + setup_basic_auth(application) # make sure we handle unicode correctly From b5e2b675767eb8378b1218967907cdfac9f715ed Mon Sep 17 00:00:00 2001 From: Jim Moffet Date: Fri, 1 Jul 2022 11:38:19 -0700 Subject: [PATCH 09/18] clean obsolete import --- app/status/views/healthcheck.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/status/views/healthcheck.py b/app/status/views/healthcheck.py index cc20b7819..11b5871af 100644 --- a/app/status/views/healthcheck.py +++ b/app/status/views/healthcheck.py @@ -4,8 +4,6 @@ from notifications_python_client.errors import HTTPError from app import status_api_client, version from app.status import status -from functools import wraps - @status.route('/_status', methods=['GET']) def show_status(): From 522ed32a017ada0f267debe9be558d3f38e786e5 Mon Sep 17 00:00:00 2001 From: Jim Moffet Date: Fri, 1 Jul 2022 11:47:44 -0700 Subject: [PATCH 10/18] clean obsolete import --- app/__init__.py | 3 +-- app/custom_auth.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index 4168e236f..b41b90c1c 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -20,7 +20,6 @@ from flask.globals import _lookup_req_object, _request_ctx_stack from flask_login import LoginManager, current_user from flask_wtf import CSRFProtect from flask_wtf.csrf import CSRFError -from flask_basicauth import BasicAuth from gds_metrics import GDSMetrics from govuk_frontend_jinja.flask_ext import init_govuk_frontend from itsdangerous import BadSignature @@ -137,7 +136,7 @@ from app.url_converters import ( login_manager = LoginManager() csrf = CSRFProtect() metrics = GDSMetrics() -basic_auth = BasicAuth() +basic_auth = CustomBasicAuth() # The current service attached to the request stack. def _get_current_service(): diff --git a/app/custom_auth.py b/app/custom_auth.py index b8310cedb..7959a107a 100644 --- a/app/custom_auth.py +++ b/app/custom_auth.py @@ -12,4 +12,4 @@ class CustomBasicAuth(BasicAuth): return jsonify(status="ok"), 200 return super(CustomBasicAuth, self).challenge() -custom_basic_auth = CustomBasicAuth() \ No newline at end of file +custom_basic_auth = CustomBasicAuth() From 8e9be686d2cccf57d6e77eeabc428a2c12f4fb68 Mon Sep 17 00:00:00 2001 From: Jim Moffet Date: Fri, 1 Jul 2022 11:48:17 -0700 Subject: [PATCH 11/18] clean obsolete import --- app/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index b41b90c1c..fc5c91d79 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -13,8 +13,7 @@ from flask import ( render_template, request, session, - url_for, - jsonify + url_for ) from flask.globals import _lookup_req_object, _request_ctx_stack from flask_login import LoginManager, current_user From b932294a9c213f6f7737e25944e0f6d0ef706052 Mon Sep 17 00:00:00 2001 From: Jim Moffet Date: Fri, 1 Jul 2022 11:49:31 -0700 Subject: [PATCH 12/18] formatting --- app/__init__.py | 2 +- app/main/views/index.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index fc5c91d79..adcb21406 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -13,7 +13,7 @@ from flask import ( render_template, request, session, - url_for + url_for, ) from flask.globals import _lookup_req_object, _request_ctx_stack from flask_login import LoginManager, current_user diff --git a/app/main/views/index.py b/app/main/views/index.py index 06a6ecfc4..b997ee232 100644 --- a/app/main/views/index.py +++ b/app/main/views/index.py @@ -30,7 +30,7 @@ def index(): return render_template( 'views/signedout.html', sms_rate=CURRENT_SMS_RATE, - counts=status_api_client.get_count_of_live_services_and_organisations() + counts=status_api_client.get_count_of_live_services_and_organisations(), ) From 6ad5cefe302666aebbdd133e8fa4857762c1c19c Mon Sep 17 00:00:00 2001 From: James Moffet Date: Fri, 15 Jul 2022 13:53:48 -0500 Subject: [PATCH 13/18] minor configs --- app/config.py | 2 +- devcontainer-admin/Dockerfile | 1 - varsfile.sample | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/config.py b/app/config.py index 5760827a9..84c593167 100644 --- a/app/config.py +++ b/app/config.py @@ -10,7 +10,7 @@ if os.environ.get('VCAP_APPLICATION'): class Config(object): ADMIN_CLIENT_SECRET = os.environ.get('ADMIN_CLIENT_SECRET') - API_HOST_NAME = os.environ.get('API_HOST_NAME', 'https://notifications-api.app.cloud.gov') + API_HOST_NAME = os.environ.get('API_HOST_NAME', 'localhost') SECRET_KEY = os.environ.get('SECRET_KEY') DANGEROUS_SALT = os.environ.get('DANGEROUS_SALT') ZENDESK_API_KEY = os.environ.get('ZENDESK_API_KEY') diff --git a/devcontainer-admin/Dockerfile b/devcontainer-admin/Dockerfile index 9c28570be..0b6616235 100644 --- a/devcontainer-admin/Dockerfile +++ b/devcontainer-admin/Dockerfile @@ -28,7 +28,6 @@ RUN apt-get update \ tldr \ unzip \ vim \ - apache2-utils \ && apt-get autoremove -y \ && apt-get clean -y \ && rm -rf /var/lib/apt/lists/* diff --git a/varsfile.sample b/varsfile.sample index c4c7a6d54..cc0fef4ee 100644 --- a/varsfile.sample +++ b/varsfile.sample @@ -7,4 +7,3 @@ AWS_ACCESS_KEY_ID: asdf AWS_SECRET_ACCESS_KEY: asdf BASIC_AUTH_USERNAME: asdf BASIC_AUTH_PASSWORD: asdf -NOTIFY_LOG_LEVEL: asdf From 50e660a73f8b225ce963f1feed898cff7d118eb9 Mon Sep 17 00:00:00 2001 From: James Moffet Date: Tue, 19 Jul 2022 18:23:48 -0700 Subject: [PATCH 14/18] devcontainer config --- app/config.py | 26 ++-- app/notify_client/__init__.py | 3 +- .../broadcast_message_api_client.py | 6 +- app/notify_client/email_branding_client.py | 10 +- app/notify_client/invite_api_client.py | 4 +- app/notify_client/job_api_client.py | 6 +- app/notify_client/letter_branding_client.py | 10 +- app/notify_client/organisations_api_client.py | 20 +-- .../performance_dashboard_api_client.py | 2 +- app/notify_client/service_api_client.py | 114 +++++++++--------- app/notify_client/status_api_client.py | 18 ++- .../template_folder_api_client.py | 12 +- app/notify_client/user_api_client.py | 30 ++--- app/status/views/healthcheck.py | 26 ++++ devcontainer-admin/.devcontainer.json | 3 - .../scripts/notify-admin-entrypoint.sh | 5 + manifest.yml | 4 +- varsfile.sample | 10 +- 18 files changed, 183 insertions(+), 126 deletions(-) diff --git a/app/config.py b/app/config.py index 84c593167..9b9bae42b 100644 --- a/app/config.py +++ b/app/config.py @@ -4,12 +4,15 @@ import os if os.environ.get('VCAP_APPLICATION'): # on cloudfoundry, config is a json blob in VCAP_APPLICATION - unpack it, and populate # standard environment variables from it - from app.cloudfoundry_config import extract_cloudfoundry_config - extract_cloudfoundry_config() + # from app.cloudfoundry_config import extract_cloudfoundry_config + # extract_cloudfoundry_config() + vcap_services = json.loads(os.environ['VCAP_SERVICES']) + os.environ['REDIS_URL'] = vcap_services['aws-elasticache-redis'][0]['credentials']['uri'] class Config(object): ADMIN_CLIENT_SECRET = os.environ.get('ADMIN_CLIENT_SECRET') + ADMIN_CLIENT_USER_NAME = os.environ.get('ADMIN_CLIENT_USERNAME') API_HOST_NAME = os.environ.get('API_HOST_NAME', 'localhost') SECRET_KEY = os.environ.get('SECRET_KEY') DANGEROUS_SALT = os.environ.get('DANGEROUS_SALT') @@ -25,8 +28,6 @@ class Config(object): DEBUG = False NOTIFY_LOG_PATH = os.environ.get('NOTIFY_LOG_PATH', 'application.log') - ADMIN_CLIENT_USER_NAME = 'notify-admin' - ANTIVIRUS_API_HOST = os.environ.get('ANTIVIRUS_API_HOST') ANTIVIRUS_API_KEY = os.environ.get('ANTIVIRUS_API_KEY') @@ -109,7 +110,7 @@ class Development(Config): MOU_BUCKET_NAME = 'notify.tools-mou' TRANSIENT_UPLOADED_LETTERS = 'development-transient-uploaded-letters' PRECOMPILED_ORIGINALS_BACKUP_LETTERS = 'development-letters-precompiled-originals-backup' - ADMIN_CLIENT_SECRET = 'dev-notify-secret-key' + ADMIN_CLIENT_SECRET = os.environ.get('ADMIN_CLIENT_SECRET') # check for local compose orchestration variable API_HOST_NAME = os.environ.get('DEV_API_HOST_NAME', 'http://dev:6011') DANGEROUS_SALT = 'dev-notify-salt' @@ -121,8 +122,7 @@ class Development(Config): ASSET_PATH = '/static/' REDIS_URL = os.environ.get('DEV_REDIS_URL', 'http://redis:6379') - - REDIS_ENABLED = os.environ.get('REDIS_ENABLED') == '1' + REDIS_ENABLED = True class Test(Development): @@ -200,6 +200,18 @@ class Live(Config): CHECK_PROXY_HEADER = False ASSET_DOMAIN = 'static.notifications.service.gov.uk' ASSET_PATH = 'https://static.notifications.service.gov.uk/' + + REDIS_URL = os.environ.get('REDIS_URL') + REDIS_ENABLED = True + + ADMIN_CLIENT_SECRET = os.environ.get('ADMIN_CLIENT_SECRET') + ADMIN_CLIENT_USER_NAME = os.environ.get('ADMIN_CLIENT_USERNAME') + API_HOST_NAME = os.environ.get('API_HOST_NAME') + DANGEROUS_SALT = os.environ.get('DANGEROUS_SALT') + SECRET_KEY = os.environ.get('SECRET_KEY') + ANTIVIRUS_API_HOST = 'http://localhost:6016' + ANTIVIRUS_API_KEY = 'test-key' + ANTIVIRUS_ENABLED = False class CloudFoundryConfig(Config): diff --git a/app/notify_client/__init__.py b/app/notify_client/__init__.py index 3145ebc44..04aed4852 100644 --- a/app/notify_client/__init__.py +++ b/app/notify_client/__init__.py @@ -1,4 +1,4 @@ -from flask import abort, has_request_context, request +from flask import abort, has_request_context, request, current_app from flask_login import current_user from notifications_python_client import __version__ from notifications_python_client.base import BaseAPIClient @@ -28,6 +28,7 @@ class NotifyAdminAPIClient(BaseAPIClient): self.route_secret = app.config['ROUTE_SECRET_KEY_1'] def generate_headers(self, api_token): + # current_app.logger.info("Attempting to generate headers") headers = { "Content-type": "application/json", "Authorization": "Bearer {}".format(api_token), diff --git a/app/notify_client/broadcast_message_api_client.py b/app/notify_client/broadcast_message_api_client.py index 2bf8b8d9a..6aa61e80e 100644 --- a/app/notify_client/broadcast_message_api_client.py +++ b/app/notify_client/broadcast_message_api_client.py @@ -34,18 +34,18 @@ class BroadcastMessageAPIClient(NotifyAdminAPIClient): def get_broadcast_messages(self, service_id): return self.get(f'/service/{service_id}/broadcast-message')['broadcast_messages'] - @cache.set('service-{service_id}-broadcast-message-{broadcast_message_id}') + # @cache.set('service-{service_id}-broadcast-message-{broadcast_message_id}') def get_broadcast_message(self, *, service_id, broadcast_message_id): return self.get(f'/service/{service_id}/broadcast-message/{broadcast_message_id}') - @cache.delete('service-{service_id}-broadcast-message-{broadcast_message_id}') + # @cache.delete('service-{service_id}-broadcast-message-{broadcast_message_id}') def update_broadcast_message(self, *, service_id, broadcast_message_id, data): self.post( f'/service/{service_id}/broadcast-message/{broadcast_message_id}', data=data, ) - @cache.delete('service-{service_id}-broadcast-message-{broadcast_message_id}') + # @cache.delete('service-{service_id}-broadcast-message-{broadcast_message_id}') def update_broadcast_message_status(self, status, *, service_id, broadcast_message_id): data = _attach_current_user({ 'status': status, diff --git a/app/notify_client/email_branding_client.py b/app/notify_client/email_branding_client.py index 469e6f7c5..80fd9aec1 100644 --- a/app/notify_client/email_branding_client.py +++ b/app/notify_client/email_branding_client.py @@ -3,18 +3,18 @@ from app.notify_client import NotifyAdminAPIClient, cache class EmailBrandingClient(NotifyAdminAPIClient): - @cache.set('email_branding-{branding_id}') + # @cache.set('email_branding-{branding_id}') def get_email_branding(self, branding_id): return self.get(url='/email-branding/{}'.format(branding_id)) - @cache.set('email_branding') + # @cache.set('email_branding') def get_all_email_branding(self, sort_key=None): brandings = self.get(url='/email-branding')['email_branding'] if sort_key and sort_key in brandings[0]: brandings.sort(key=lambda branding: branding[sort_key].lower()) return brandings - @cache.delete('email_branding') + # @cache.delete('email_branding') def create_email_branding(self, logo, name, text, colour, brand_type): data = { "logo": logo, @@ -25,8 +25,8 @@ class EmailBrandingClient(NotifyAdminAPIClient): } return self.post(url="/email-branding", data=data) - @cache.delete('email_branding') - @cache.delete('email_branding-{branding_id}') + # @cache.delete('email_branding') + # @cache.delete('email_branding-{branding_id}') def update_email_branding(self, branding_id, logo, name, text, colour, brand_type): data = { "logo": logo, diff --git a/app/notify_client/invite_api_client.py b/app/notify_client/invite_api_client.py index 464c3ba9c..9d70e88e7 100644 --- a/app/notify_client/invite_api_client.py +++ b/app/notify_client/invite_api_client.py @@ -64,8 +64,8 @@ class InviteApiClient(NotifyAdminAPIClient): self.post(url='/service/{0}/invite/{1}'.format(service_id, invited_user_id), data=data) - @cache.delete('service-{service_id}') - @cache.delete('user-{invited_user_id}') + # @cache.delete('service-{service_id}') + # @cache.delete('user-{invited_user_id}') def accept_invite(self, service_id, invited_user_id): data = {'status': 'accepted'} self.post(url='/service/{0}/invite/{1}'.format(service_id, invited_user_id), diff --git a/app/notify_client/job_api_client.py b/app/notify_client/job_api_client.py index ee9dc0022..60a2d295e 100644 --- a/app/notify_client/job_api_client.py +++ b/app/notify_client/job_api_client.py @@ -84,7 +84,7 @@ class JobApiClient(NotifyAdminAPIClient): url=f'/service/{service_id}/job/scheduled-job-stats' ) - @cache.set('has_jobs-{service_id}') + # @cache.set('has_jobs-{service_id}') def has_jobs(self, service_id): return bool(self.get_jobs(service_id)['data']) @@ -108,14 +108,14 @@ class JobApiClient(NotifyAdminAPIClient): return job - @cache.delete('has_jobs-{service_id}') + # @cache.delete('has_jobs-{service_id}') def cancel_job(self, service_id, job_id): return self.post( url='/service/{}/job/{}/cancel'.format(service_id, job_id), data={} ) - @cache.delete('has_jobs-{service_id}') + # @cache.delete('has_jobs-{service_id}') def cancel_letter_job(self, service_id, job_id): return self.post( url='/service/{}/job/{}/cancel-letter-job'.format(service_id, job_id), diff --git a/app/notify_client/letter_branding_client.py b/app/notify_client/letter_branding_client.py index 736d9d025..7e8ce5361 100644 --- a/app/notify_client/letter_branding_client.py +++ b/app/notify_client/letter_branding_client.py @@ -3,15 +3,15 @@ from app.notify_client import NotifyAdminAPIClient, cache class LetterBrandingClient(NotifyAdminAPIClient): - @cache.set('letter_branding-{branding_id}') + # @cache.set('letter_branding-{branding_id}') def get_letter_branding(self, branding_id): return self.get(url='/letter-branding/{}'.format(branding_id)) - @cache.set('letter_branding') + # @cache.set('letter_branding') def get_all_letter_branding(self): return self.get(url='/letter-branding') - @cache.delete('letter_branding') + # @cache.delete('letter_branding') def create_letter_branding(self, filename, name): data = { "filename": filename, @@ -19,8 +19,8 @@ class LetterBrandingClient(NotifyAdminAPIClient): } return self.post(url="/letter-branding", data=data) - @cache.delete('letter_branding') - @cache.delete('letter_branding-{branding_id}') + # @cache.delete('letter_branding') + # @cache.delete('letter_branding-{branding_id}') def update_letter_branding(self, branding_id, filename, name): data = { "filename": filename, diff --git a/app/notify_client/organisations_api_client.py b/app/notify_client/organisations_api_client.py index c073ba9b2..140fe9411 100644 --- a/app/notify_client/organisations_api_client.py +++ b/app/notify_client/organisations_api_client.py @@ -8,11 +8,11 @@ from app.notify_client import NotifyAdminAPIClient, cache class OrganisationsClient(NotifyAdminAPIClient): - @cache.set('organisations') + # @cache.set('organisations') def get_organisations(self): return self.get(url='/organisations') - @cache.set('domains') + # @cache.set('domains') def get_domains(self): return list(chain.from_iterable( organisation['domains'] @@ -22,7 +22,7 @@ class OrganisationsClient(NotifyAdminAPIClient): def get_organisation(self, org_id): return self.get(url='/organisations/{}'.format(org_id)) - @cache.set('organisation-{org_id}-name') + # @cache.set('organisation-{org_id}-name') def get_organisation_name(self, org_id): return self.get_organisation(org_id)['name'] @@ -36,7 +36,7 @@ class OrganisationsClient(NotifyAdminAPIClient): return None raise error - @cache.delete('organisations') + # @cache.delete('organisations') def create_organisation(self, name, crown, organisation_type, agreement_signed): return self.post( url="/organisations", @@ -48,8 +48,8 @@ class OrganisationsClient(NotifyAdminAPIClient): } ) - @cache.delete('domains') - @cache.delete('organisations') + # @cache.delete('domains') + # @cache.delete('organisations') def update_organisation(self, org_id, cached_service_ids=None, **kwargs): api_response = self.post(url="/organisations/{}".format(org_id), data=kwargs) @@ -61,9 +61,9 @@ class OrganisationsClient(NotifyAdminAPIClient): return api_response - @cache.delete('service-{service_id}') - @cache.delete('live-service-and-organisation-counts') - @cache.delete('organisations') + # @cache.delete('service-{service_id}') + # @cache.delete('live-service-and-organisation-counts') + # @cache.delete('organisations') def update_service_organisation(self, service_id, org_id): data = { 'service_id': service_id @@ -76,7 +76,7 @@ class OrganisationsClient(NotifyAdminAPIClient): def get_organisation_services(self, org_id): return self.get(url="/organisations/{}/services".format(org_id)) - @cache.delete('user-{user_id}') + # @cache.delete('user-{user_id}') def remove_user_from_organisation(self, org_id, user_id): return self.delete(f'/organisations/{org_id}/users/{user_id}') diff --git a/app/notify_client/performance_dashboard_api_client.py b/app/notify_client/performance_dashboard_api_client.py index e8800b321..14e7af78a 100644 --- a/app/notify_client/performance_dashboard_api_client.py +++ b/app/notify_client/performance_dashboard_api_client.py @@ -3,7 +3,7 @@ from app.notify_client import NotifyAdminAPIClient, cache class PerformanceDashboardAPIClient(NotifyAdminAPIClient): - @cache.set('performance-stats-{start_date}-to-{end_date}', ttl_in_seconds=3600) + # @cache.set('performance-stats-{start_date}-to-{end_date}', ttl_in_seconds=3600) def get_performance_dashboard_stats( self, *, diff --git a/app/notify_client/service_api_client.py b/app/notify_client/service_api_client.py index 52acd7cb1..06c9f7d73 100644 --- a/app/notify_client/service_api_client.py +++ b/app/notify_client/service_api_client.py @@ -7,7 +7,7 @@ from app.notify_client import NotifyAdminAPIClient, _attach_current_user, cache class ServiceAPIClient(NotifyAdminAPIClient): - @cache.delete('user-{user_id}') + # @cache.delete('user-{user_id}') def create_service( self, service_name, @@ -32,7 +32,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): data = _attach_current_user(data) return self.post("/service", data)['data']['id'] - @cache.set('service-{service_id}') + # @cache.set('service-{service_id}') def get_service(self, service_id): """ Retrieve a service. @@ -64,7 +64,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): params_dict['only_active'] = True return self.get_services(params_dict) - @cache.delete('service-{service_id}') + # @cache.delete('service-{service_id}') def update_service( self, service_id, @@ -114,7 +114,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): endpoint = "/service/{0}".format(service_id) return self.post(endpoint, data) - @cache.delete('live-service-and-organisation-counts') + # @cache.delete('live-service-and-organisation-counts') def update_status(self, service_id, live): return self.update_service( service_id, @@ -123,7 +123,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): go_live_at=str(datetime.utcnow()) if live else None ) - @cache.delete('live-service-and-organisation-counts') + # @cache.delete('live-service-and-organisation-counts') def update_count_as_live(self, service_id, count_as_live): return self.update_service( service_id, @@ -134,24 +134,24 @@ class ServiceAPIClient(NotifyAdminAPIClient): def update_service_with_properties(self, service_id, properties): return self.update_service(service_id, **properties) - @cache.delete('service-{service_id}') - @cache.delete('service-{service_id}-templates') - @cache.delete_by_pattern('service-{service_id}-template-*') + # @cache.delete('service-{service_id}') + # @cache.delete('service-{service_id}-templates') + # @cache.delete_by_pattern('service-{service_id}-template-*') def archive_service(self, service_id, cached_service_user_ids): if cached_service_user_ids: redis_client.delete(*map('user-{}'.format, cached_service_user_ids)) return self.post('/service/{}/archive'.format(service_id), data=None) - @cache.delete('service-{service_id}') + # @cache.delete('service-{service_id}') def suspend_service(self, service_id): return self.post('/service/{}/suspend'.format(service_id), data=None) - @cache.delete('service-{service_id}') + # @cache.delete('service-{service_id}') def resume_service(self, service_id): return self.post('/service/{}/resume'.format(service_id), data=None) - @cache.delete('service-{service_id}') - @cache.delete('user-{user_id}') + # @cache.delete('service-{service_id}') + # @cache.delete('user-{user_id}') def remove_user_from_service(self, service_id, user_id): """ Remove a user from a service @@ -162,7 +162,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): data = _attach_current_user({}) return self.delete(endpoint, data) - @cache.delete('service-{service_id}-templates') + # @cache.delete('service-{service_id}-templates') def create_service_template(self, name, type_, content, service_id, subject=None, process_type='normal', parent_folder_id=None): """ @@ -187,8 +187,8 @@ class ServiceAPIClient(NotifyAdminAPIClient): endpoint = "/service/{0}/template".format(service_id) return self.post(endpoint, data) - @cache.delete('service-{service_id}-templates') - @cache.delete_by_pattern('service-{service_id}-template-*') + # @cache.delete('service-{service_id}-templates') + # @cache.delete_by_pattern('service-{service_id}-template-*') def update_service_template( self, id_, name, type_, content, service_id, subject=None, process_type=None ): @@ -214,8 +214,8 @@ class ServiceAPIClient(NotifyAdminAPIClient): endpoint = "/service/{0}/template/{1}".format(service_id, id_) return self.post(endpoint, data) - @cache.delete('service-{service_id}-templates') - @cache.delete_by_pattern('service-{service_id}-template-*') + # @cache.delete('service-{service_id}-templates') + # @cache.delete_by_pattern('service-{service_id}-template-*') def redact_service_template(self, service_id, id_): return self.post( "/service/{}/template/{}".format(service_id, id_), @@ -224,8 +224,8 @@ class ServiceAPIClient(NotifyAdminAPIClient): ), ) - @cache.delete('service-{service_id}-templates') - @cache.delete_by_pattern('service-{service_id}-template-*') + # @cache.delete('service-{service_id}-templates') + # @cache.delete_by_pattern('service-{service_id}-template-*') def update_service_template_sender(self, service_id, template_id, reply_to): data = { 'reply_to': reply_to, @@ -236,15 +236,15 @@ class ServiceAPIClient(NotifyAdminAPIClient): data ) - @cache.delete('service-{service_id}-templates') - @cache.delete_by_pattern('service-{service_id}-template-*') + # @cache.delete('service-{service_id}-templates') + # @cache.delete_by_pattern('service-{service_id}-template-*') def update_service_template_postage(self, service_id, template_id, postage): return self.post( "/service/{0}/template/{1}".format(service_id, template_id), _attach_current_user({'postage': postage}) ) - @cache.set('service-{service_id}-template-{template_id}-version-{version}') + # @cache.set('service-{service_id}-template-{template_id}-version-{version}') def get_service_template(self, service_id, template_id, version=None): """ Retrieve a service template. @@ -256,7 +256,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): endpoint = '{base}/version/{version}'.format(base=endpoint, version=version) return self.get(endpoint) - @cache.set('service-{service_id}-template-{template_id}-versions') + # @cache.set('service-{service_id}-template-{template_id}-versions') def get_service_template_versions(self, service_id, template_id): """ Retrieve a list of versions for a template @@ -273,7 +273,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): """ return self.get('/service/{}/template/precompiled'.format(service_id)) - @cache.set('service-{service_id}-templates') + # @cache.set('service-{service_id}-templates') def get_service_templates(self, service_id): """ Retrieve all templates for service. @@ -293,8 +293,8 @@ class ServiceAPIClient(NotifyAdminAPIClient): ) ]) - @cache.delete('service-{service_id}-templates') - @cache.delete_by_pattern('service-{service_id}-template-*') + # @cache.delete('service-{service_id}-templates') + # @cache.delete_by_pattern('service-{service_id}-template-*') def delete_service_template(self, service_id, template_id): """ Set a service template's archived flag to True @@ -322,7 +322,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): def get_guest_list(self, service_id): return self.get(url='/service/{}/guest-list'.format(service_id)) - @cache.delete('service-{service_id}') + # @cache.delete('service-{service_id}') def update_guest_list(self, service_id, data): return self.put(url='/service/{}/guest-list'.format(service_id), data=data) @@ -358,7 +358,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): '/service/{}/inbound-sms/summary'.format(service_id) ) - @cache.delete('service-{service_id}') + # @cache.delete('service-{service_id}') def create_service_inbound_api(self, service_id, url, bearer_token, user_id): data = { "url": url, @@ -367,7 +367,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): } return self.post("/service/{}/inbound-api".format(service_id), data) - @cache.delete('service-{service_id}') + # @cache.delete('service-{service_id}') def update_service_inbound_api(self, service_id, url, bearer_token, user_id, inbound_api_id): data = { "url": url, @@ -384,7 +384,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): ) )['data'] - @cache.delete('service-{service_id}') + # @cache.delete('service-{service_id}') def delete_service_inbound_api(self, service_id, callback_api_id): return self.delete("/service/{}/inbound-api/{}".format( service_id, callback_api_id @@ -411,8 +411,8 @@ class ServiceAPIClient(NotifyAdminAPIClient): data={"email": email_address} ) - @cache.delete('service-{service_id}') - @cache.delete_by_pattern('service-{service_id}-template-*') + # @cache.delete('service-{service_id}') + # @cache.delete_by_pattern('service-{service_id}-template-*') def add_reply_to_email_address(self, service_id, email_address, is_default=False): return self.post( "/service/{}/email-reply-to".format(service_id), @@ -422,8 +422,8 @@ class ServiceAPIClient(NotifyAdminAPIClient): } ) - @cache.delete('service-{service_id}') - @cache.delete_by_pattern('service-{service_id}-template-*') + # @cache.delete('service-{service_id}') + # @cache.delete_by_pattern('service-{service_id}-template-*') def update_reply_to_email_address(self, service_id, reply_to_email_id, email_address, is_default=False): return self.post( "/service/{}/email-reply-to/{}".format( @@ -436,8 +436,8 @@ class ServiceAPIClient(NotifyAdminAPIClient): } ) - @cache.delete('service-{service_id}') - @cache.delete_by_pattern('service-{service_id}-template-*') + # @cache.delete('service-{service_id}') + # @cache.delete_by_pattern('service-{service_id}-template-*') def delete_reply_to_email_address(self, service_id, reply_to_email_id): return self.post( "/service/{}/email-reply-to/{}/archive".format(service_id, reply_to_email_id), @@ -450,8 +450,8 @@ class ServiceAPIClient(NotifyAdminAPIClient): def get_letter_contact(self, service_id, letter_contact_id): return self.get("/service/{}/letter-contact/{}".format(service_id, letter_contact_id)) - @cache.delete('service-{service_id}') - @cache.delete_by_pattern('service-{service_id}-template-*') + # @cache.delete('service-{service_id}') + # @cache.delete_by_pattern('service-{service_id}-template-*') def add_letter_contact(self, service_id, contact_block, is_default=False): return self.post( "/service/{}/letter-contact".format(service_id), @@ -461,8 +461,8 @@ class ServiceAPIClient(NotifyAdminAPIClient): } ) - @cache.delete('service-{service_id}') - @cache.delete_by_pattern('service-{service_id}-template-*') + # @cache.delete('service-{service_id}') + # @cache.delete_by_pattern('service-{service_id}-template-*') def update_letter_contact(self, service_id, letter_contact_id, contact_block, is_default=False): return self.post( "/service/{}/letter-contact/{}".format( @@ -475,8 +475,8 @@ class ServiceAPIClient(NotifyAdminAPIClient): } ) - @cache.delete('service-{service_id}') - @cache.delete_by_pattern('service-{service_id}-template-*') + # @cache.delete('service-{service_id}') + # @cache.delete_by_pattern('service-{service_id}-template-*') def delete_letter_contact(self, service_id, letter_contact_id): return self.post( "/service/{}/letter-contact/{}/archive".format(service_id, letter_contact_id), @@ -493,8 +493,8 @@ class ServiceAPIClient(NotifyAdminAPIClient): "/service/{}/sms-sender/{}".format(service_id, sms_sender_id) ) - @cache.delete('service-{service_id}') - @cache.delete_by_pattern('service-{service_id}-template-*') + # @cache.delete('service-{service_id}') + # @cache.delete_by_pattern('service-{service_id}-template-*') def add_sms_sender(self, service_id, sms_sender, is_default=False, inbound_number_id=None): data = { "sms_sender": sms_sender, @@ -504,8 +504,8 @@ class ServiceAPIClient(NotifyAdminAPIClient): data["inbound_number_id"] = inbound_number_id return self.post("/service/{}/sms-sender".format(service_id), data=data) - @cache.delete('service-{service_id}') - @cache.delete_by_pattern('service-{service_id}-template-*') + # @cache.delete('service-{service_id}') + # @cache.delete_by_pattern('service-{service_id}-template-*') def update_sms_sender(self, service_id, sms_sender_id, sms_sender, is_default=False): return self.post( "/service/{}/sms-sender/{}".format(service_id, sms_sender_id), @@ -515,8 +515,8 @@ class ServiceAPIClient(NotifyAdminAPIClient): } ) - @cache.delete('service-{service_id}') - @cache.delete_by_pattern('service-{service_id}-template-*') + # @cache.delete('service-{service_id}') + # @cache.delete_by_pattern('service-{service_id}-template-*') def delete_sms_sender(self, service_id, sms_sender_id): return self.post( "/service/{}/sms-sender/{}/archive".format(service_id, sms_sender_id), @@ -530,7 +530,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): ) )['data'] - @cache.delete('service-{service_id}') + # @cache.delete('service-{service_id}') def update_service_callback_api(self, service_id, url, bearer_token, user_id, callback_api_id): data = { "url": url, @@ -540,13 +540,13 @@ class ServiceAPIClient(NotifyAdminAPIClient): data['bearer_token'] = bearer_token return self.post("/service/{}/delivery-receipt-api/{}".format(service_id, callback_api_id), data) - @cache.delete('service-{service_id}') + # @cache.delete('service-{service_id}') def delete_service_callback_api(self, service_id, callback_api_id): return self.delete("/service/{}/delivery-receipt-api/{}".format( service_id, callback_api_id )) - @cache.delete('service-{service_id}') + # @cache.delete('service-{service_id}') def create_service_callback_api(self, service_id, url, bearer_token, user_id): data = { "url": url, @@ -555,7 +555,7 @@ class ServiceAPIClient(NotifyAdminAPIClient): } return self.post("/service/{}/delivery-receipt-api".format(service_id), data) - @cache.delete('service-{service_id}-data-retention') + # @cache.delete('service-{service_id}-data-retention') def create_service_data_retention(self, service_id, notification_type, days_of_retention): data = { "notification_type": notification_type, @@ -564,29 +564,29 @@ class ServiceAPIClient(NotifyAdminAPIClient): return self.post("/service/{}/data-retention".format(service_id), data) - @cache.delete('service-{service_id}-data-retention') + # @cache.delete('service-{service_id}-data-retention') def update_service_data_retention(self, service_id, data_retention_id, days_of_retention): data = { "days_of_retention": days_of_retention } return self.post("/service/{}/data-retention/{}".format(service_id, data_retention_id), data) - @cache.set('service-{service_id}-data-retention') + # @cache.set('service-{service_id}-data-retention') def get_service_data_retention(self, service_id): return self.get("/service/{}/data-retention".format(service_id)) - @cache.set('service-{service_id}-returned-letters-statistics') + # @cache.set('service-{service_id}-returned-letters-statistics') def get_returned_letter_statistics(self, service_id): return self.get("service/{}/returned-letter-statistics".format(service_id)) - @cache.set('service-{service_id}-returned-letters-summary') + # @cache.set('service-{service_id}-returned-letters-summary') def get_returned_letter_summary(self, service_id): return self.get("service/{}/returned-letter-summary".format(service_id)) def get_returned_letters(self, service_id, reported_at): return self.get("service/{}/returned-letters?reported_at={}".format(service_id, reported_at)) - @cache.delete('service-{service_id}') + # @cache.delete('service-{service_id}') def set_service_broadcast_settings( self, service_id, service_mode, broadcast_channel, provider_restriction, cached_service_user_ids ): diff --git a/app/notify_client/status_api_client.py b/app/notify_client/status_api_client.py index f3224b41d..4f883ec4d 100644 --- a/app/notify_client/status_api_client.py +++ b/app/notify_client/status_api_client.py @@ -1,14 +1,28 @@ +import os from app.notify_client import NotifyAdminAPIClient, cache - +from flask import current_app class StatusApiClient(NotifyAdminAPIClient): def get_status(self, *params): return self.get(url='/_status', *params) - @cache.set('live-service-and-organisation-counts', ttl_in_seconds=3600) + # @cache.set('live-service-and-organisation-counts', ttl_in_seconds=3600) def get_count_of_live_services_and_organisations(self): + current_app.logger.info("Getting count of live services and organisations") + current_app.logger.info("Redis url from config is: {}".format(current_app.config['REDIS_URL'])) + current_app.logger.info("Redis url from env is: {}".format( os.environ.get('REDIS_URL') )) + current_app.logger.info("Redis enabled from config is: {}".format(current_app.config['REDIS_ENABLED'])) + current_app.logger.info("Redis enabled from env is: {}".format( os.environ.get('REDIS_ENABLED') )) return self.get(url='/_status/live-service-and-organisation-counts') + def get_services(self): + current_app.logger.info("Getting count of live services and organisations") + current_app.logger.info("Redis url from config is: {}".format(current_app.config['REDIS_URL'])) + current_app.logger.info("Redis url from env is: {}".format( os.environ.get('REDIS_URL') )) + current_app.logger.info("Redis enabled from config is: {}".format(current_app.config['REDIS_ENABLED'])) + current_app.logger.info("Redis enabled from env is: {}".format( os.environ.get('REDIS_ENABLED') )) + return self.get(url='/service') + status_api_client = StatusApiClient() diff --git a/app/notify_client/template_folder_api_client.py b/app/notify_client/template_folder_api_client.py index 005e82898..c0646665b 100644 --- a/app/notify_client/template_folder_api_client.py +++ b/app/notify_client/template_folder_api_client.py @@ -4,7 +4,7 @@ from app.notify_client import NotifyAdminAPIClient, cache class TemplateFolderAPIClient(NotifyAdminAPIClient): - @cache.delete('service-{service_id}-template-folders') + # @cache.delete('service-{service_id}-template-folders') def create_template_folder( self, service_id, @@ -17,7 +17,7 @@ class TemplateFolderAPIClient(NotifyAdminAPIClient): } return self.post('/service/{}/template-folder'.format(service_id), data)['data']['id'] - @cache.set('service-{service_id}-template-folders') + # @cache.set('service-{service_id}-template-folders') def get_template_folders(self, service_id): return self.get('/service/{}/template-folder'.format(service_id))['template_folders'] @@ -34,8 +34,8 @@ class TemplateFolderAPIClient(NotifyAdminAPIClient): if folder['id'] == str(folder_id) ) - @cache.delete('service-{service_id}-template-folders') - @cache.delete('service-{service_id}-templates') + # @cache.delete('service-{service_id}-template-folders') + # @cache.delete('service-{service_id}-templates') def move_to_folder(self, service_id, folder_id, template_ids, folder_ids): if folder_id: @@ -51,7 +51,7 @@ class TemplateFolderAPIClient(NotifyAdminAPIClient): if template_ids: redis_client.delete(*(f'service-{service_id}-template-{id}-version-None' for id in template_ids)) - @cache.delete('service-{service_id}-template-folders') + # @cache.delete('service-{service_id}-template-folders') def update_template_folder(self, service_id, template_folder_id, name, users_with_permission=None): data = {"name": name} if users_with_permission: @@ -61,7 +61,7 @@ class TemplateFolderAPIClient(NotifyAdminAPIClient): data ) - @cache.delete('service-{service_id}-template-folders') + # @cache.delete('service-{service_id}-template-folders') def delete_template_folder(self, service_id, template_folder_id): self.delete('/service/{}/template-folder/{}'.format(service_id, template_folder_id), {}) diff --git a/app/notify_client/user_api_client.py b/app/notify_client/user_api_client.py index caed3ff97..43781895f 100644 --- a/app/notify_client/user_api_client.py +++ b/app/notify_client/user_api_client.py @@ -34,7 +34,7 @@ class UserApiClient(NotifyAdminAPIClient): def get_user(self, user_id): return self._get_user(user_id)['data'] - @cache.set('user-{user_id}') + # @cache.set('user-{user_id}') def _get_user(self, user_id): return self.get("/user/{}".format(user_id)) @@ -50,7 +50,7 @@ class UserApiClient(NotifyAdminAPIClient): return None raise e - @cache.delete('user-{user_id}') + # @cache.delete('user-{user_id}') def update_user_attribute(self, user_id, **kwargs): data = dict(kwargs) disallowed_attributes = set(data.keys()) - ALLOWED_ATTRIBUTES @@ -63,24 +63,24 @@ class UserApiClient(NotifyAdminAPIClient): user_data = self.post(url, data=data) return user_data['data'] - @cache.delete('user-{user_id}') + # @cache.delete('user-{user_id}') def archive_user(self, user_id): return self.post('/user/{}/archive'.format(user_id), data=None) - @cache.delete('user-{user_id}') + # @cache.delete('user-{user_id}') def reset_failed_login_count(self, user_id): url = "/user/{}/reset-failed-login-count".format(user_id) user_data = self.post(url, data={}) return user_data['data'] - @cache.delete('user-{user_id}') + # @cache.delete('user-{user_id}') def update_password(self, user_id, password): data = {"_password": password} url = "/user/{}/update-password".format(user_id) user_data = self.post(url, data=data) return user_data['data'] - @cache.delete('user-{user_id}') + # @cache.delete('user-{user_id}') def verify_password(self, user_id, password): try: url = "/user/{}/verify/password".format(user_id) @@ -113,7 +113,7 @@ class UserApiClient(NotifyAdminAPIClient): endpoint = '/user/{0}/email-already-registered'.format(user_id) self.post(endpoint, data=data) - @cache.delete('user-{user_id}') + # @cache.delete('user-{user_id}') def check_verify_code(self, user_id, code, code_type): data = {'code_type': code_type, 'code': code} endpoint = '/user/{}/verify/code'.format(user_id) @@ -125,7 +125,7 @@ class UserApiClient(NotifyAdminAPIClient): return False, e.message raise e - @cache.delete('user-{user_id}') + # @cache.delete('user-{user_id}') def complete_webauthn_login_attempt(self, user_id, is_successful): data = {'successful': is_successful} endpoint = f'/user/{user_id}/complete/webauthn-login' @@ -145,9 +145,9 @@ class UserApiClient(NotifyAdminAPIClient): endpoint = '/organisations/{}/users'.format(org_id) return self.get(endpoint)['data'] - @cache.delete('service-{service_id}') - @cache.delete('service-{service_id}-template-folders') - @cache.delete('user-{user_id}') + # @cache.delete('service-{service_id}') + # @cache.delete('service-{service_id}-template-folders') + # @cache.delete('user-{user_id}') def add_user_to_service(self, service_id, user_id, permissions, folder_permissions): # permissions passed in are the combined UI permissions, not DB permissions endpoint = '/service/{}/users/{}'.format(service_id, user_id) @@ -158,13 +158,13 @@ class UserApiClient(NotifyAdminAPIClient): self.post(endpoint, data=data) - @cache.delete('user-{user_id}') + # @cache.delete('user-{user_id}') def add_user_to_organisation(self, org_id, user_id): resp = self.post('/organisations/{}/users/{}'.format(org_id, user_id), data={}) return resp['data'] - @cache.delete('service-{service_id}-template-folders') - @cache.delete('user-{user_id}') + # @cache.delete('service-{service_id}-template-folders') + # @cache.delete('user-{user_id}') def set_user_permissions(self, user_id, service_id, permissions, folder_permissions=None): # permissions passed in are the combined UI permissions, not DB permissions data = { @@ -193,7 +193,7 @@ class UserApiClient(NotifyAdminAPIClient): users = self.post(endpoint, data=data) return users - @cache.delete('user-{user_id}') + # @cache.delete('user-{user_id}') def activate_user(self, user_id): return self.post("/user/{}/activate".format(user_id), data=None) diff --git a/app/status/views/healthcheck.py b/app/status/views/healthcheck.py index 11b5871af..69c36c5aa 100644 --- a/app/status/views/healthcheck.py +++ b/app/status/views/healthcheck.py @@ -20,3 +20,29 @@ def show_status(): api=api_status, git_commit=version.__git_commit__, build_time=version.__time__), 200 + +@status.route('/_status/servicecounts', methods=['GET']) +def get_counts(): + try: + orgs_status = status_api_client.get_count_of_live_services_and_organisations() + except HTTPError as e: + current_app.logger.exception("API failed to respond") + return jsonify(status="error", message=str(e.message)), 500 + return jsonify( + status="ok", + api=orgs_status, + git_commit=version.__git_commit__, + build_time=version.__time__), 200 + +@status.route('/_status/services', methods=['GET']) +def get_services(): + try: + services = status_api_client.get_services() + except HTTPError as e: + current_app.logger.exception("API failed to respond") + return jsonify(status="error", message=str(e.message)), 500 + return jsonify( + status="ok", + api=services, + git_commit=version.__git_commit__, + build_time=version.__time__), 200 diff --git a/devcontainer-admin/.devcontainer.json b/devcontainer-admin/.devcontainer.json index 814c9f2d7..6a1f065eb 100644 --- a/devcontainer-admin/.devcontainer.json +++ b/devcontainer-admin/.devcontainer.json @@ -23,16 +23,13 @@ } }, "extensions": [ - "ms-python.python", // "ms-python.black-formatter" "donjayamanne.python-extension-pack", - "ms-azuretools.vscode-docker", "ms-python.vscode-pylance", "eamodio.gitlens", "wholroyd.jinja", "pmbenjamin.vscode-snyk", "visualstudioexptteam.vscodeintellicode", "yzhang.markdown-all-in-one", - "ms-ossdata.vscode-postgresql", "GitHub.copilot" ], "forwardPorts": [ diff --git a/devcontainer-admin/scripts/notify-admin-entrypoint.sh b/devcontainer-admin/scripts/notify-admin-entrypoint.sh index 4f6beec82..a80abe668 100755 --- a/devcontainer-admin/scripts/notify-admin-entrypoint.sh +++ b/devcontainer-admin/scripts/notify-admin-entrypoint.sh @@ -31,6 +31,11 @@ pip3 install -r requirements_for_test.txt make generate-version-file # make babel +# npm ci install +if [ ! -d "/node_modules" ]; then + npm ci install +fi + # npm ci install npm run build diff --git a/manifest.yml b/manifest.yml index 179a56b92..68080ef65 100644 --- a/manifest.yml +++ b/manifest.yml @@ -18,13 +18,16 @@ applications: env: NOTIFY_APP_NAME: admin NOTIFY_LOG_PATH: /home/vcap/logs/app.log + NOTIFY_LOG_LEVEL: DEBUG FLASK_APP: application.py FLASK_ENV: production + REDIS_ENABLED: ((REDIS_ENABLED)) NOTIFY_ENVIRONMENT: live # Credentials variables ADMIN_CLIENT_SECRET: ((ADMIN_CLIENT_SECRET)) + ADMIN_CLIENT_USERNAME: ((ADMIN_CLIENT_USERNAME)) ADMIN_BASE_URL: https://notifications-admin.app.cloud.gov API_HOST_NAME: https://notifications-api.app.cloud.gov DANGEROUS_SALT: ((DANGEROUS_SALT)) @@ -35,6 +38,5 @@ applications: AWS_SECRET_ACCESS_KEY: ((AWS_SECRET_ACCESS_KEY)) BASIC_AUTH_USERNAME: ((BASIC_AUTH_USERNAME)) BASIC_AUTH_PASSWORD: ((BASIC_AUTH_PASSWORD)) - NOTIFY_LOG_LEVEL: ((NOTIFY_LOG_LEVEL)) NOTIFY_BILLING_DETAILS: [] diff --git a/varsfile.sample b/varsfile.sample index cc0fef4ee..e12601de8 100644 --- a/varsfile.sample +++ b/varsfile.sample @@ -1,8 +1,8 @@ -ADMIN_CLIENT_SECRET: asdf -DANGEROUS_SALT: asdf -SECRET_KEY: asdf -ROUTE_SECRET_KEY_1: asdf -ROUTE_SECRET_KEY_2: asdf +ADMIN_CLIENT_SECRET: notify-admin +DANGEROUS_SALT: dev-notify-salt +SECRET_KEY: dev-notify-secret-key +ROUTE_SECRET_KEY_1: dev-route-secret-key-1 +ROUTE_SECRET_KEY_2: dev-route-secret-key-2 AWS_ACCESS_KEY_ID: asdf AWS_SECRET_ACCESS_KEY: asdf BASIC_AUTH_USERNAME: asdf From 6c60183a1082bd407a1d532e9476bd1624a14b92 Mon Sep 17 00:00:00 2001 From: James Moffet Date: Tue, 19 Jul 2022 18:49:05 -0700 Subject: [PATCH 15/18] delete log --- app/notify_client/status_api_client.py | 10 ---------- application.log.json | 12 ------------ 2 files changed, 22 deletions(-) delete mode 100644 application.log.json diff --git a/app/notify_client/status_api_client.py b/app/notify_client/status_api_client.py index 4f883ec4d..ef4923517 100644 --- a/app/notify_client/status_api_client.py +++ b/app/notify_client/status_api_client.py @@ -9,19 +9,9 @@ class StatusApiClient(NotifyAdminAPIClient): # @cache.set('live-service-and-organisation-counts', ttl_in_seconds=3600) def get_count_of_live_services_and_organisations(self): - current_app.logger.info("Getting count of live services and organisations") - current_app.logger.info("Redis url from config is: {}".format(current_app.config['REDIS_URL'])) - current_app.logger.info("Redis url from env is: {}".format( os.environ.get('REDIS_URL') )) - current_app.logger.info("Redis enabled from config is: {}".format(current_app.config['REDIS_ENABLED'])) - current_app.logger.info("Redis enabled from env is: {}".format( os.environ.get('REDIS_ENABLED') )) return self.get(url='/_status/live-service-and-organisation-counts') def get_services(self): - current_app.logger.info("Getting count of live services and organisations") - current_app.logger.info("Redis url from config is: {}".format(current_app.config['REDIS_URL'])) - current_app.logger.info("Redis url from env is: {}".format( os.environ.get('REDIS_URL') )) - current_app.logger.info("Redis enabled from config is: {}".format(current_app.config['REDIS_ENABLED'])) - current_app.logger.info("Redis enabled from env is: {}".format( os.environ.get('REDIS_ENABLED') )) return self.get(url='/service') diff --git a/application.log.json b/application.log.json deleted file mode 100644 index 4ed2ff25e..000000000 --- a/application.log.json +++ /dev/null @@ -1,12 +0,0 @@ -Logging configured -Logging configured -Logging configured -Logging configured again -Logging configured -Logging configured again -Logging configured -Logging configured again -Logging configured -Logging configured again -Logging configured -Logging configured again From e9302552ee48387dfa825fb68af01a039b7672c7 Mon Sep 17 00:00:00 2001 From: James Moffet Date: Tue, 19 Jul 2022 18:58:38 -0700 Subject: [PATCH 16/18] clean up --- app/notify_client/status_api_client.py | 4 ---- app/status/views/healthcheck.py | 26 -------------------------- 2 files changed, 30 deletions(-) diff --git a/app/notify_client/status_api_client.py b/app/notify_client/status_api_client.py index ef4923517..92de16bef 100644 --- a/app/notify_client/status_api_client.py +++ b/app/notify_client/status_api_client.py @@ -1,6 +1,5 @@ import os from app.notify_client import NotifyAdminAPIClient, cache -from flask import current_app class StatusApiClient(NotifyAdminAPIClient): @@ -11,8 +10,5 @@ class StatusApiClient(NotifyAdminAPIClient): def get_count_of_live_services_and_organisations(self): return self.get(url='/_status/live-service-and-organisation-counts') - def get_services(self): - return self.get(url='/service') - status_api_client = StatusApiClient() diff --git a/app/status/views/healthcheck.py b/app/status/views/healthcheck.py index 69c36c5aa..11b5871af 100644 --- a/app/status/views/healthcheck.py +++ b/app/status/views/healthcheck.py @@ -20,29 +20,3 @@ def show_status(): api=api_status, git_commit=version.__git_commit__, build_time=version.__time__), 200 - -@status.route('/_status/servicecounts', methods=['GET']) -def get_counts(): - try: - orgs_status = status_api_client.get_count_of_live_services_and_organisations() - except HTTPError as e: - current_app.logger.exception("API failed to respond") - return jsonify(status="error", message=str(e.message)), 500 - return jsonify( - status="ok", - api=orgs_status, - git_commit=version.__git_commit__, - build_time=version.__time__), 200 - -@status.route('/_status/services', methods=['GET']) -def get_services(): - try: - services = status_api_client.get_services() - except HTTPError as e: - current_app.logger.exception("API failed to respond") - return jsonify(status="error", message=str(e.message)), 500 - return jsonify( - status="ok", - api=services, - git_commit=version.__git_commit__, - build_time=version.__time__), 200 From ec86fe8d2300f8ef955bd264dd97338cdecf3085 Mon Sep 17 00:00:00 2001 From: James Moffet Date: Tue, 19 Jul 2022 18:59:48 -0700 Subject: [PATCH 17/18] clean up --- app/notify_client/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/notify_client/__init__.py b/app/notify_client/__init__.py index 04aed4852..3145ebc44 100644 --- a/app/notify_client/__init__.py +++ b/app/notify_client/__init__.py @@ -1,4 +1,4 @@ -from flask import abort, has_request_context, request, current_app +from flask import abort, has_request_context, request from flask_login import current_user from notifications_python_client import __version__ from notifications_python_client.base import BaseAPIClient @@ -28,7 +28,6 @@ class NotifyAdminAPIClient(BaseAPIClient): self.route_secret = app.config['ROUTE_SECRET_KEY_1'] def generate_headers(self, api_token): - # current_app.logger.info("Attempting to generate headers") headers = { "Content-type": "application/json", "Authorization": "Bearer {}".format(api_token), From c1cf7be10467e2282690fd8b1d8dfbad3ed63e10 Mon Sep 17 00:00:00 2001 From: James Moffet Date: Tue, 19 Jul 2022 19:01:18 -0700 Subject: [PATCH 18/18] clean up --- varsfile.sample | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/varsfile.sample b/varsfile.sample index e12601de8..cc0fef4ee 100644 --- a/varsfile.sample +++ b/varsfile.sample @@ -1,8 +1,8 @@ -ADMIN_CLIENT_SECRET: notify-admin -DANGEROUS_SALT: dev-notify-salt -SECRET_KEY: dev-notify-secret-key -ROUTE_SECRET_KEY_1: dev-route-secret-key-1 -ROUTE_SECRET_KEY_2: dev-route-secret-key-2 +ADMIN_CLIENT_SECRET: asdf +DANGEROUS_SALT: asdf +SECRET_KEY: asdf +ROUTE_SECRET_KEY_1: asdf +ROUTE_SECRET_KEY_2: asdf AWS_ACCESS_KEY_ID: asdf AWS_SECRET_ACCESS_KEY: asdf BASIC_AUTH_USERNAME: asdf