diff --git a/.ebextensions/git.config b/.ebextensions/git.config new file mode 100644 index 0000000..3c48160 --- /dev/null +++ b/.ebextensions/git.config @@ -0,0 +1,4 @@ +# Git is needed for the route that displays the current Git SHA. +packages: + yum: + git: [] diff --git a/src/app.py b/src/app.py index efc20a3..8beca28 100644 --- a/src/app.py +++ b/src/app.py @@ -3,6 +3,9 @@ Set up API routes. """ +# Built-in libraries: +import subprocess + # Third-party dependencies: from flask import Flask @@ -12,4 +15,16 @@ @app.route("/") def hello_world(): """A cheeky hello world route.""" - return {"message": "Look on my Affiliations Service, ye Mighty, and despair!"} + return "
Look on my Affiliations Service, ye Mighty, and despair!
" + + +@app.route("/sha") +def current_git_sha(): + """Displays current Git SHA.""" + command = ["git", "rev-parse", "HEAD"] + output = subprocess.run(command, check=False, capture_output=True).stdout.decode( + "utf-8" + ) + # Strip newline character from the end of the string. + sha = output[0 : len(output) - 1] + return sha diff --git a/src/app_test.py b/src/app_test.py index ae25779..3bb4351 100644 --- a/src/app_test.py +++ b/src/app_test.py @@ -14,6 +14,14 @@ def test_root(): """Ensure our cheeky hello world route works.""" response = CLIENT.get("/") assert response.status_code == 200 - assert response.json == { - "message": "Look on my Affiliations Service, ye Mighty, and despair!" - } + assert ( + response.text + == "Look on my Affiliations Service, ye Mighty, and despair!
" + ) + + +def test_sha(): + """Ensure we can get a SHA.""" + response = CLIENT.get("/sha") + assert response.status_code == 200 + assert len(response.text) == 40 # SHA-1 is 40 characters in length.