Skip to content

Commit

Permalink
add admin_token routine to makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Toby Bellwood committed Jun 23, 2021
1 parent d971949 commit 3a57e08
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,16 @@ kind/push-images:
&& docker push $$IMAGE_REGISTRY/$$image:$(SAFE_BRANCH_NAME); \
done

.PHONY: kind/admin-jwt
kind/admin-jwt:
export KUBECONFIG="$$(pwd)/kubeconfig.kind.$(CI_BUILD_TAG)" && \
docker run \
-e JWTSECRET="$$(./local-dev/kubectl get secret -n lagoon lagoon-core-jwtsecret -o jsonpath="{.data.JWTSECRET}" | base64 --decode)" \
-e JWTAUDIENCE=api.dev \
-e JWTUSER=localadmin \
$(CI_BUILD_TAG)/tests \
python3 /ansible/tasks/api/admin_token.py

## Use kind/retest to only perform a push of the local-dev, or test images, and run the tests
## It preserves the last build lagoon core&remote setup, reducing rebuild time
.PHONY: kind/retest
Expand Down
11 changes: 6 additions & 5 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ WORKDIR /ansible
COPY . /ansible
COPY hosts /etc/ansible/hosts

ENV ANSIBLE_FORCE_COLOR=true
ENV SSH_AUTH_SOCK=/tmp/ssh-agent
ENV KEYCLOAK_URL=http://keycloak:8080
ENV JWTSECRET=super-secret-string
ENV JWTAUDIENCE=api.dev
ENV ANSIBLE_FORCE_COLOR=true \
SSH_AUTH_SOCK=/tmp/ssh-agent \
KEYCLOAK_URL=http://keycloak:8080 \
JWTSECRET=super-secret-string \
JWTAUDIENCE=api.dev \
JWTUSER=test-suite

COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
Expand Down
6 changes: 3 additions & 3 deletions tests/tasks/api/admin_token.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python
#!/usr/bin/env python3

import os
import jwt

payload = {'role': 'admin', 'iss': 'test-suite',
'aud': os.environ['JWTAUDIENCE'], 'sub': 'test-suite'}
payload = {'role': 'admin', 'iss': os.environ['JWTUSER'],
'aud': os.environ['JWTAUDIENCE'], 'sub': os.environ['JWTUSER']}

access_token = jwt.encode(payload, os.environ['JWTSECRET'], algorithm='HS256')

Expand Down

0 comments on commit 3a57e08

Please sign in to comment.