add webhook password #10

Merged
PeterSurda merged 1 commits from cis-muzahid/buildbot_multibuild:github_hook into master 2022-03-16 07:16:44 +00:00
1 changed files with 13 additions and 5 deletions

View File

@ -1,4 +1,5 @@
from os import listdir, walk import os
from os import listdir
from os.path import exists, isfile, join, islink, isdir from os.path import exists, isfile, join, islink, isdir
import requests import requests
import re import re
@ -8,10 +9,6 @@ request_data = {
"project": "testproject", "project": "testproject",
"comments": "testcomment", "comments": "testcomment",
} }
request_headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "text/plain",
}
ty = "/change_hook/base" ty = "/change_hook/base"
path =".buildbot" path =".buildbot"
@ -54,6 +51,11 @@ ENTRYPOINT /usr/local/bin/buildbot_entrypoint.sh "$BUILDMASTER" "$WORKERNAME" "$
""" """
def get_secret():
with open(path.join(os.environ['HOME'], "multibuild_parent_key.key"),'r') as f:
PeterSurda marked this conversation as resolved Outdated

filename doesn't match the filename used in StringDownload

filename doesn't match the filename used in `StringDownload`
data = f.read()
return data
def list_jobs(directory=".buildbot"): def list_jobs(directory=".buildbot"):
""" """
list jobs found in a directory list jobs found in a directory
@ -101,6 +103,11 @@ def trigger_child_hooks(buildbotUrl: str, repository, branch, directory=".buildb
request_url = buildbotUrl + ty request_url = buildbotUrl + ty
PeterSurda marked this conversation as resolved Outdated

'X-Multibuild-Trigger'

`'X-Multibuild-Trigger'`

would be better if " and ' were used consistently.

would be better if `"` and `'` were used consistently.
# List all jobs in the directory # List all jobs in the directory
jobs = list_jobs(directory) jobs = list_jobs(directory)
request_headers = {
"Content-Type": "application/x-www-form-urlencoded",
"X-Multibuild-Trigger": get_secret(),
"Accept": "text/plain",
}
# Check if build.sh or test.sh exists in each of the jobs # Check if build.sh or test.sh exists in each of the jobs
for job in jobs: for job in jobs:
@ -122,4 +129,5 @@ def trigger_child_hooks(buildbotUrl: str, repository, branch, directory=".buildb
"branch": branch, "branch": branch,
"jobname": job, "jobname": job,
} }
requests.post(request_url, headers=request_headers, data=request_data) requests.post(request_url, headers=request_headers, data=request_data)