Skip to content

Commit

Permalink
github-set-status: use secret volume for github token
Browse files Browse the repository at this point in the history
The `github-set-status` task now uses volumeMount to read github token.
The volume approach is prefered over environment variable.
  • Loading branch information
zhouhaibing089 authored and tekton-robot committed Jul 2, 2021
1 parent e88a331 commit 7462fb2
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions task/github-set-status/0.2/github-set-status.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ spec:
type: string
default: Bearer

volumes:
- name: githubtoken
secret:
secretName: $(params.GITHUB_TOKEN_SECRET_NAME)

steps:
- name: set-status
env:
- name: GITHUBTOKEN
valueFrom:
secretKeyRef:
name: $(params.GITHUB_TOKEN_SECRET_NAME)
key: $(params.GITHUB_TOKEN_SECRET_KEY)
volumeMounts:
- name: githubtoken
mountPath: /etc/github-set-status

image: registry.access.redhat.com/ubi8/python-38:1-34.1599745032
script: |
Expand All @@ -103,9 +105,10 @@ spec:
"""This script will set the CI status on GitHub PR"""
import json
import os
import http.client
github_token = open("/etc/github-set-status/$(params.GITHUB_TOKEN_SECRET_KEY)", "r").read()
status_url = "$(params.API_PATH_PREFIX)" + "/repos/$(params.REPO_FULL_NAME)/" + \
"statuses/$(params.SHA)"
Expand All @@ -118,7 +121,7 @@ spec:
print("Sending this data to GitHub: ")
print(data)
authHeader = "$(params.AUTH_TYPE) " + os.environ["GITHUBTOKEN"]
authHeader = "$(params.AUTH_TYPE) " + github_token
conn = http.client.HTTPSConnection("$(params.GITHUB_HOST_URL)")
conn.request(
Expand Down

0 comments on commit 7462fb2

Please sign in to comment.