diff options
author | Oliver Poignant <oliver@poignant.se> | 2016-12-12 18:35:03 +0100 |
---|---|---|
committer | Oliver Poignant <oliver@poignant.se> | 2016-12-12 18:35:03 +0100 |
commit | 8c406865ce388c1856f8dab495df4aa11f64f9cd (patch) | |
tree | d85ca148d33d9fd7e3fa37f564546e687a17c276 /gitautodeploy/parsers/coding.py | |
parent | 30b8b34af911c3b3661f57366f0eeb56bfb5e3ed (diff) | |
download | Git-Auto-Deploy-8c406865ce388c1856f8dab495df4aa11f64f9cd.zip Git-Auto-Deploy-8c406865ce388c1856f8dab495df4aa11f64f9cd.tar.gz Git-Auto-Deploy-8c406865ce388c1856f8dab495df4aa11f64f9cd.tar.bz2 |
Refactoring and preparations for JSON API
Diffstat (limited to 'gitautodeploy/parsers/coding.py')
-rw-r--r-- | gitautodeploy/parsers/coding.py | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/gitautodeploy/parsers/coding.py b/gitautodeploy/parsers/coding.py index 80ab77e..889c3ee 100644 --- a/gitautodeploy/parsers/coding.py +++ b/gitautodeploy/parsers/coding.py @@ -2,52 +2,38 @@ from common import WebhookRequestParser class CodingRequestParser(WebhookRequestParser): - def get_repo_params_from_request(self, request_headers, request_body): + def get_repo_configs(self, request_headers, request_body, action): 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 + action.log_error("Unable to recognize data format") + return [] # 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) + items = self.get_matching_repo_configs(repo_urls, action) 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']) + action.log_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 + return repo_configs def verify_token(self, secret_token, request_token): |