summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Poignant <oliver@poignant.se>2016-08-26 23:07:35 +0200
committerOliver Poignant <oliver@poignant.se>2016-08-26 23:07:35 +0200
commit91a80671f91753324cfc66685586fc6a55c38e7b (patch)
treeb6ff14d04f38e6b6a35ba91ebb0dca080d5426df
parent9f08e1300d43261ca5d57d56ce657cbeef6e056f (diff)
parent8e9f5e90c9f1a7aacb4fc4f4313beb1e47e6907c (diff)
downloadGit-Auto-Deploy-91a80671f91753324cfc66685586fc6a55c38e7b.zip
Git-Auto-Deploy-91a80671f91753324cfc66685586fc6a55c38e7b.tar.gz
Git-Auto-Deploy-91a80671f91753324cfc66685586fc6a55c38e7b.tar.bz2
Merge branch 'xohozu-master' into developmentorigin/development
-rw-r--r--gitautodeploy/httpserver.py6
-rw-r--r--gitautodeploy/parsers/__init__.py3
-rw-r--r--gitautodeploy/parsers/coding.py54
3 files changed, 61 insertions, 2 deletions
diff --git a/gitautodeploy/httpserver.py b/gitautodeploy/httpserver.py
index d9310d1..ffd6092 100644
--- a/gitautodeploy/httpserver.py
+++ b/gitautodeploy/httpserver.py
@@ -128,8 +128,12 @@ class WebhookRequestHandler(BaseHTTPRequestHandler):
user_agent = 'user-agent' in request_headers and request_headers['user-agent']
content_type = 'content-type' in request_headers and request_headers['content-type']
+ # Assume Coding if the X-Coding-Event HTTP header is set
+ if 'x-coding-event' in request_headers:
+ return parsers.CodingRequestParser
+
# Assume GitLab if the X-Gitlab-Event HTTP header is set
- if 'x-gitlab-event' in request_headers:
+ elif 'x-gitlab-event' in request_headers:
# Special Case for Gitlab CI
if content_type == "application/json" and "build_status" in data:
diff --git a/gitautodeploy/parsers/__init__.py b/gitautodeploy/parsers/__init__.py
index 59d2b50..168c781 100644
--- a/gitautodeploy/parsers/__init__.py
+++ b/gitautodeploy/parsers/__init__.py
@@ -1,4 +1,5 @@
from bitbucket import BitBucketRequestParser
from github import GitHubRequestParser
from gitlab import GitLabRequestParser, GitLabCIRequestParser
-from generic import GenericRequestParser \ No newline at end of file
+from generic import GenericRequestParser
+from coding import CodingRequestParser \ No newline at end of file
diff --git a/gitautodeploy/parsers/coding.py b/gitautodeploy/parsers/coding.py
new file mode 100644
index 0000000..80ab77e
--- /dev/null
+++ b/gitautodeploy/parsers/coding.py
@@ -0,0 +1,54 @@
+from common import WebhookRequestParser
+
+class CodingRequestParser(WebhookRequestParser):
+
+ def get_repo_params_from_request(self, request_headers, request_body):
+ import json
+ import logging
+
+ logger = logging.getLogger()
+ data = json.loads(request_body)
+
+ repo_urls = []
+ ref = ""
+ action = ""
+
+ coding_event = 'x-coding-event' in request_headers and request_headers['x-coding-event']
+
+ logger.debug("Received '%s' event from Coding" % coding_event)
+
+ if 'repository' not in data:
+ logger.error("Unable to recognize data format")
+ return [], ref or "master", action
+
+ # One repository may posses multiple URLs for different protocols
+ for k in ['web_url', 'https_url', 'ssh_url']:
+ if k in data['repository']:
+ repo_urls.append(data['repository'][k])
+
+ # extract the branch
+ if 'ref' in data:
+ ref = data['ref']
+
+ # set the action
+ if 'event' in data:
+ action = data['event']
+
+ # Get a list of configured repositories that matches the incoming web hook reqeust
+ items = self.get_matching_repo_configs(repo_urls)
+
+ repo_configs = []
+ for repo_config in items:
+ # Validate secret token if present
+ if 'secret-token' in repo_config:
+ if 'token' not in data or not self.verify_token(repo_config['secret-token'], data['token']):
+ logger.warning("Request token does not match the 'secret-token' configured for repository %s." % repo_config['url'])
+ continue
+
+ repo_configs.append(repo_config)
+
+ return repo_configs, ref or "master", action, repo_urls
+
+
+ def verify_token(self, secret_token, request_token):
+ return secret_token == request_token