summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Dittberner <jandd@cacert.org>2018-04-14 20:35:46 +0200
committerJan Dittberner <jandd@cacert.org>2018-04-14 20:35:55 +0200
commit1d085ce6103c9ad64233c805c3fc0d1f01e7d505 (patch)
treeca4136f65fbde4d4601e01d65750cfbc66bcb365
parent223deb84b8cfcd26cafeded97b843dfc523e70a7 (diff)
downloadcacert-puppet-1d085ce6103c9ad64233c805c3fc0d1f01e7d505.tar.gz
cacert-puppet-1d085ce6103c9ad64233c805c3fc0d1f01e7d505.tar.xz
cacert-puppet-1d085ce6103c9ad64233c805c3fc0d1f01e7d505.zip
Unify HTTP handling in git-pull-hook
-rwxr-xr-xsitemodules/profiles/files/puppet_server/git-pull-hook19
1 files changed, 10 insertions, 9 deletions
diff --git a/sitemodules/profiles/files/puppet_server/git-pull-hook b/sitemodules/profiles/files/puppet_server/git-pull-hook
index 78f75c3..32fd1c4 100755
--- a/sitemodules/profiles/files/puppet_server/git-pull-hook
+++ b/sitemodules/profiles/files/puppet_server/git-pull-hook
@@ -42,6 +42,11 @@ class GitHookRequestHandler(BaseHTTPRequestHandler):
with a known authentication token in an "Authentication" HTTP header.
"""
+ def _send_data(self, message):
+ self.send_header("Content-Type", "text/plain; charset=utf8")
+ self.end_headers()
+ self.wfile.write(("%s\r\n" % message).encode('UTF-8'))
+
def _handle_pull(self):
try:
git_proc = Popen(
@@ -55,10 +60,9 @@ class GitHookRequestHandler(BaseHTTPRequestHandler):
except Exception as e:
self.log_error("Could not pull changes for %s: %s",
GIT_DIRECTORY, e)
+ self._send_data("Error updating the repository.")
self.send_response(HTTPStatus.OK)
- self.send_header('Content-Type', 'text/plain; charset=utf8')
- self.end_headers()
- self.wfile.write(("updated %s" % GIT_DIRECTORY).encode('UTF-8'))
+ self._send_data("updated %s" % GIT_DIRECTORY)
# noinspection PyPep8Naming
def do_GET(self):
@@ -72,16 +76,13 @@ class GitHookRequestHandler(BaseHTTPRequestHandler):
self._handle_pull()
else:
self.send_response(HTTPStatus.UNAUTHORIZED)
- self.end_headers()
+ self._send_data('You have to send a valid token in the "Authentication" header.')
elif self.path == '/health':
self.send_response(HTTPStatus.OK)
- self.send_header('Content-Type', 'text/plain; charset=utf8')
- self.end_headers()
- self.wfile.write(b"I'm healthy!")
+ self._send_data("I'm healthy!")
else:
self.send_error(HTTPStatus.BAD_REQUEST)
- self.end_headers()
- self.wfile.write(b"You requested something I do not understand")
+ self._send_data("You requested something I do not understand.")
def run(server_class=HTTPServer, handler_class=GitHookRequestHandler):