Skip to content

Commit

Permalink
Re-implement JWT generation in auto-idler using pyjwt
Browse files Browse the repository at this point in the history
  • Loading branch information
smlx committed May 11, 2020
1 parent 46b2e76 commit d48b17f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
6 changes: 2 additions & 4 deletions services/auto-idler/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ FROM ${IMAGE_REPO:-lagoon}/oc

ENV LAGOON=auto-idler

RUN apk add --no-cache tini jq openssl bash curl nodejs nodejs-npm \
&& npm config set unsafe-perm true \
&& npm -g install jwtgen
RUN apk add --no-cache tini jq bash curl py3-jwt

COPY create_jwt.sh idle-services.sh idle-clis.sh openshift-clis.sh openshift-services.sh /
COPY create_jwt.py idle-services.sh idle-clis.sh openshift-clis.sh openshift-services.sh /

ENV JWTSECRET=super-secret-string \
JWTAUDIENCE=api.dev \
Expand Down
9 changes: 9 additions & 0 deletions services/auto-idler/create_jwt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python3

import os
import jwt

payload = {'role': 'admin', 'iss': 'auto-idler',
'aud': os.environ['JWTAUDIENCE'], 'sub': 'auto-idler'}

print(jwt.encode(payload, os.environ['JWTSECRET'], algorithm='HS256').decode())
12 changes: 0 additions & 12 deletions services/auto-idler/create_jwt.sh

This file was deleted.

4 changes: 2 additions & 2 deletions services/auto-idler/idle-clis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ prefixwith() {
}

# Create an JWT Admin Token to talk to the API
API_ADMIN_JWT_TOKEN=$(./create_jwt.sh)
API_ADMIN_JWT_TOKEN=$(./create_jwt.py)
BEARER="Authorization: bearer $API_ADMIN_JWT_TOKEN"

# Load all projects and their environments
Expand Down Expand Up @@ -45,4 +45,4 @@ do
done
sleep 5
# clean up the tmp file
rm $TMP_DATA
rm $TMP_DATA
2 changes: 1 addition & 1 deletion services/auto-idler/idle-services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ prefixwith() {
}

# Create an JWT Admin Token to talk to the API
API_ADMIN_JWT_TOKEN=$(./create_jwt.sh)
API_ADMIN_JWT_TOKEN=$(./create_jwt.py)
BEARER="Authorization: bearer $API_ADMIN_JWT_TOKEN"

# Load all projects and their environments, but only development environments
Expand Down

0 comments on commit d48b17f

Please sign in to comment.