diff options
author | Oliver Poignant <oliver@poignant.se> | 2016-12-09 20:36:38 +0100 |
---|---|---|
committer | Oliver Poignant <oliver@poignant.se> | 2016-12-09 20:36:38 +0100 |
commit | c98d5b22de7bed03c6345775539a405e61e58477 (patch) | |
tree | 4fff1fdca0626bad24d894192369028d1af9d44d /gitautodeploy/parsers/github.py | |
parent | 9e4aa3618ad9f5494847fb95b0958f2f1b43ccb5 (diff) | |
download | Git-Auto-Deploy-c98d5b22de7bed03c6345775539a405e61e58477.zip Git-Auto-Deploy-c98d5b22de7bed03c6345775539a405e61e58477.tar.gz Git-Auto-Deploy-c98d5b22de7bed03c6345775539a405e61e58477.tar.bz2 |
Verify secret token in GitLab requests
Diffstat (limited to 'gitautodeploy/parsers/github.py')
-rw-r--r-- | gitautodeploy/parsers/github.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/gitautodeploy/parsers/github.py b/gitautodeploy/parsers/github.py index 7077def..4d24648 100644 --- a/gitautodeploy/parsers/github.py +++ b/gitautodeploy/parsers/github.py @@ -40,20 +40,24 @@ class GitHubRequestParser(WebhookRequestParser): logger.debug("Action '%s' was fired" % action) # Get a list of configured repositories that matches the incoming web hook reqeust - items = self.get_matching_repo_configs(repo_urls) + repo_configs = self.get_matching_repo_configs(repo_urls) - repo_configs = [] - for repo_config in items: + return repo_configs, ref or "master", action, repo_urls + + def validate_request(self, request_headers, repo_configs): + import logging + + logger = logging.getLogger() + + for repo_config in repo_configs: # Validate secret token if present if 'secret-token' in repo_config and 'x-hub-signature' in request_headers: if not self.verify_signature(repo_config['secret-token'], request_body, request_headers['x-hub-signature']): - logger.warning("Request signature does not match the 'secret-token' configured for repository %s." % repo_config['url']) - continue + logger.info("Request signature does not match the 'secret-token' configured for repository %s." % repo_config['url']) + return False - repo_configs.append(repo_config) - - return repo_configs, ref or "master", action, repo_urls + return True def verify_signature(self, token, body, signature): import hashlib |