From 19ad84414a110224c15f20a1ddd3442d82297f1c Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 14 Feb 2019 20:14:27 +0000 Subject: [PATCH] Add basic auth to healthcheck endpoint --- Pipfile | 1 + Pipfile.lock | 9 ++++++++- actioner/scheduler/__init__.py | 3 ++- actioner/settings.py | 2 ++ actioner/web/__init__.py | 8 +++++++- actioner/web/healthcheck.py | 1 + setup.cfg | 2 ++ 7 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 setup.cfg diff --git a/Pipfile b/Pipfile index e5ab9ac..713bd5b 100644 --- a/Pipfile +++ b/Pipfile @@ -24,3 +24,4 @@ aiohttp = "*" apscheduler = "*" pygithub = "*" python-dotenv = "*" +aiohttp-basicauth = "*" diff --git a/Pipfile.lock b/Pipfile.lock index b317ef6..b6c8d13 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "b0d2de2b0b35e9c52f6fd20d157bb51571a1c3a243d372f2a15dd7944ff2fb90" + "sha256": "655537d96ce2a47a7ef792ca2e0142c6ac9171fe41bffceea65fef4ca070f473" }, "pipfile-spec": 6, "requires": { @@ -44,6 +44,13 @@ "index": "pypi", "version": "==4.0.0a0" }, + "aiohttp-basicauth": { + "hashes": [ + "sha256:277d071c29256e10b4650f1bffee7c2007d914da0c2036e2ab621eb7b2096b2d" + ], + "index": "pypi", + "version": "==0.1.2" + }, "apscheduler": { "hashes": [ "sha256:6599bc78901ee7e9be85cbd073d9cc155c42d2bc867c5cde4d4d1cc339ebfbeb", diff --git a/actioner/scheduler/__init__.py b/actioner/scheduler/__init__.py index eba6f95..9ca99dd 100644 --- a/actioner/scheduler/__init__.py +++ b/actioner/scheduler/__init__.py @@ -1,6 +1,7 @@ -from apscheduler.schedulers.blocking import BlockingScheduler import asyncio +from apscheduler.schedulers.blocking import BlockingScheduler + def create_scheduler(): scheduler = BlockingScheduler() diff --git a/actioner/settings.py b/actioner/settings.py index 9afeb17..8315cdd 100644 --- a/actioner/settings.py +++ b/actioner/settings.py @@ -8,3 +8,5 @@ load_dotenv() GITHUB_TOKEN = os.environ['GITHUB_TOKEN'] LOGGING_LEVEL = _nameToLevel[os.environ.get('LOGGING_LEVEL', 'INFO')] + +BASIC_AUTH = os.environ['BASIC_AUTH'].split(":") diff --git a/actioner/web/__init__.py b/actioner/web/__init__.py index b8c8e2a..9be00db 100644 --- a/actioner/web/__init__.py +++ b/actioner/web/__init__.py @@ -1,7 +1,13 @@ from aiohttp import web +from aiohttp_basicauth import BasicAuthMiddleware + +from actioner.settings import BASIC_AUTH + from .healthcheck import healthcheck + def get_server(): + auth = BasicAuthMiddleware(username=BASIC_AUTH[0], password=BASIC_AUTH[1], force=False) app = web.Application() - app.router.add_get("/healthcheck", healthcheck) + app.router.add_get("/healthcheck", auth.required(healthcheck)) return app diff --git a/actioner/web/healthcheck.py b/actioner/web/healthcheck.py index 6bb4af8..bfdda55 100644 --- a/actioner/web/healthcheck.py +++ b/actioner/web/healthcheck.py @@ -1,4 +1,5 @@ from aiohttp import web + from actioner.clients import github diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..7ea6612 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[isort] +not_skip = __init__.py