summaryrefslogtreecommitdiffstats
path: root/gitautodeploy/httpserver.py
diff options
context:
space:
mode:
authorOliver Poignant <oliver@poignant.se>2017-01-01 13:21:08 +0100
committerOliver Poignant <oliver@poignant.se>2017-01-01 13:21:08 +0100
commitbebe5fb16550ee46d165eb46de2e7aaa9cfd5406 (patch)
tree842d55dc48a069d103bcce8f8d7b5476367297e7 /gitautodeploy/httpserver.py
parent01995b6b301763c92f40d6453d19eeb81c85e15c (diff)
downloadGit-Auto-Deploy-bebe5fb16550ee46d165eb46de2e7aaa9cfd5406.zip
Git-Auto-Deploy-bebe5fb16550ee46d165eb46de2e7aaa9cfd5406.tar.gz
Git-Auto-Deploy-bebe5fb16550ee46d165eb46de2e7aaa9cfd5406.tar.bz2
API for event status (disabled by default). Enhanced event logging.
Diffstat (limited to 'gitautodeploy/httpserver.py')
-rw-r--r--gitautodeploy/httpserver.py53
1 files changed, 38 insertions, 15 deletions
diff --git a/gitautodeploy/httpserver.py b/gitautodeploy/httpserver.py
index 67e9744..38f28ff 100644
--- a/gitautodeploy/httpserver.py
+++ b/gitautodeploy/httpserver.py
@@ -255,8 +255,9 @@ class WebhookRequestFilter(object):
def WebhookRequestHandlerFactory(config, event_store):
"""Factory method for webhook request handler class"""
+ from SimpleHTTPServer import SimpleHTTPRequestHandler
- class WebhookRequestHandler(BaseHTTPRequestHandler, object):
+ class WebhookRequestHandler(SimpleHTTPRequestHandler, object):
"""Extends the BaseHTTPRequestHandler class and handles the incoming
HTTP requests."""
@@ -265,20 +266,36 @@ def WebhookRequestHandlerFactory(config, event_store):
self.event_store = event_store
super(WebhookRequestHandler, self).__init__(*args, **kwargs)
+ def end_headers (self):
+ self.send_header('Access-Control-Allow-Origin', '*')
+ SimpleHTTPRequestHandler.end_headers(self)
+
+ def do_HEAD(self):
+ import json
+
+ if not self._config['web-ui']['enabled'] or not self.client_address[0] in self._config['web-ui']['remote-whitelist']:
+ self.send_error(403)
+ return
+
+ return SimpleHTTPRequestHandler.do_HEAD(self)
+
def do_GET(self):
import json
- if not self.client_address[0] in self._config['remote-whitelist']:
+ if not self._config['web-ui']['enabled'] or not self.client_address[0] in self._config['web-ui']['remote-whitelist']:
self.send_error(403)
return
- data = self.event_store.dict_repr()
+ if self.path == "/api/status":
+ data = self.event_store.dict_repr()
+ self.send_response(200, 'OK')
+ self.send_header('Content-type', 'application/json')
+ self.end_headers()
+ self.wfile.write(json.dumps(data))
+ self.wfile.close()
+ return
- self.send_response(200, 'OK')
- self.send_header('Content-type', 'application/json')
- self.end_headers()
- self.wfile.write(json.dumps(data))
- self.wfile.close()
+ return SimpleHTTPRequestHandler.do_GET(self)
def do_POST(self):
"""Invoked on incoming POST requests"""
@@ -296,7 +313,8 @@ def WebhookRequestHandlerFactory(config, event_store):
request_headers = dict(self.headers)
request_headers = dict((k.lower(), v) for k, v in request_headers.iteritems())
- action = WebhookAction(self.client_address, request_body, request_headers)
+ action = WebhookAction(self.client_address, request_headers, request_body)
+ action.set_waiting(True)
event_store.register_action(action)
action.log_info('Incoming request from %s:%s' % (self.client_address[0], self.client_address[1]))
@@ -361,7 +379,7 @@ def WebhookRequestHandlerFactory(config, event_store):
action.log_info("Filter does not match")
return
- action.log_info("Deploying")
+ action.log_info("Executing deploy commands")
# Schedule the execution of the webhook (git pull and trigger deploy etc)
request_processor.execute_webhook(repo_configs, request_headers, request_body, action)
@@ -374,12 +392,16 @@ def WebhookRequestHandlerFactory(config, event_store):
'deploy': 'echo test!'
}
- action.log_info("Done")
+ action.log_info("Deploy commands were executed")
+ action.set_success(True)
+ action.update()
except ValueError, e:
self.send_error(400, 'Unprocessable request')
action.log_warning('Unable to process incoming request from %s:%s' % (self.client_address[0], self.client_address[1]))
test_case['expected']['status'] = 400
+ action.set_success(False)
+ action.update()
return
except Exception, e:
@@ -389,6 +411,8 @@ def WebhookRequestHandlerFactory(config, event_store):
test_case['expected']['status'] = 500
action.log_warning("Unable to process request")
+ action.set_success(False)
+ action.update()
raise e
@@ -398,6 +422,9 @@ def WebhookRequestHandlerFactory(config, event_store):
if 'log-test-case' in self._config and self._config['log-test-case']:
self.save_test_case(test_case)
+ action.set_waiting(False)
+ action.update()
+
def log_message(self, format, *args):
"""Overloads the default message logging method to allow messages to
go through our custom logger instead."""
@@ -428,7 +455,3 @@ def WebhookRequestHandlerFactory(config, event_store):
return WebhookRequestHandler
-class WebhookRequestHandler(BaseHTTPRequestHandler):
- """Extends the BaseHTTPRequestHandler class and handles the incoming
- HTTP requests."""
-