Skip to content

Commit eff76af

Browse files
committed
VED-812: Use Python library for TOTP code generation. Add some missing env vars.
1 parent 5c71f49 commit eff76af

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

.github/workflows/run-e2e-tests.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,35 +61,27 @@ jobs:
6161
cache: "poetry"
6262

6363
- name: Install e2e test dependencies
64-
run: poetry install --no-root
6564
working-directory: e2e
66-
67-
- name: Install oathtool
68-
run: sudo apt-get update && sudo apt-get install -y oathtool
65+
run: poetry install --no-root
6966

7067
- name: Get Apigee access token
68+
working-directory: e2e
7169
env:
7270
APIGEE_PASSWORD: ${{ secrets.APIGEE_PASSWORD }}
7371
APIGEE_BASIC_AUTH_TOKEN: ${{ secrets.APIGEE_BASIC_AUTH_TOKEN }}
7472
APIGEE_OTP_KEY: ${{ secrets.APIGEE_OTP_KEY }}
7573
run: |
76-
CODE=$(oathtool --totp -b "$APIGEE_OTP_KEY")
74+
CODE=$(poetry run python utils/compute_totp_code.py "$APIGEE_OTP_KEY")
7775
echo "::add-mask::$CODE"
76+
7877
echo "Requesting access token from Apigee..."
7978
response=$(curl -s -X POST "https://login.apigee.com/oauth/token" \
8079
-H "Content-Type: application/x-www-form-urlencoded" \
8180
-H "Accept: application/json;charset=utf-8" \
8281
-H "Authorization: Basic $APIGEE_BASIC_AUTH_TOKEN" \
8382
-d "username=$APIGEE_USERNAME&password=$APIGEE_PASSWORD&mfa_token=$CODE&grant_type=password")
8483
85-
# TODO - REMOVE
86-
echo "$response"
87-
88-
token=$(echo "$response" | jq -e -r '.access_token')
89-
if [[ -z "$token" ]]; then
90-
echo "Failed to retrieve access token"
91-
exit 1
92-
fi
84+
token=$(jq -e -r '.access_token' <<<"$response")
9385
echo "::add-mask::$token"
9486
echo "APIGEE_ACCESS_TOKEN=$token" >> $GITHUB_ENV
9587
@@ -98,4 +90,11 @@ jobs:
9890
run: |
9991
export PROXY_NAME=immunisation-fhir-api-internal-dev
10092
export SERVICE_BASE_PATH=immunisation-fhir-api/FHIR/R4
93+
94+
export IMMS_DELTA_TABLE_NAME=imms-internal-dev-delta
95+
export AWS_DOMAIN_NAME=internal-dev.imms.dev.vds.platform.nhs.uk
96+
export DYNAMODB_TABLE_NAME=imms-internal-dev-imms-events
97+
export AWS_SQS_QUEUE_NAME=imms-internal-dev-delta-dlq
98+
export AWS_SNS_TOPIC_NAME=imms-internal-dev-delta-sns
99+
101100
make run-immunization

e2e/poetry.lock

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ requests = "^2.32.5"
1717
pyjwt = "^2.10.1"
1818
cryptography = "^42.0.3"
1919
lxml = "~4.9.0"
20+
oath = "^1.4.4"
2021

2122
[build-system]
2223
requires = ["poetry-core"]

e2e/utils/compute_totp_code.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import base64
2+
import sys
3+
4+
import oath
5+
6+
7+
def compute_totp_code(key_base32: str) -> str:
8+
key_hex = base64.b32decode(key_base32).hex()
9+
return oath.totp(key_hex)
10+
11+
12+
if __name__ == "__main__":
13+
print(compute_totp_code(sys.argv[1]))

0 commit comments

Comments
 (0)