diff --git a/lambdas/GitPullS3/.DS_Store b/lambdas/GitPullS3/.DS_Store deleted file mode 100644 index b031314..0000000 Binary files a/lambdas/GitPullS3/.DS_Store and /dev/null differ diff --git a/lambdas/GitPullS3/lambda_function.py b/lambdas/GitPullS3/lambda_function.py index df55db9..ffa5c40 100644 --- a/lambdas/GitPullS3/lambda_function.py +++ b/lambdas/GitPullS3/lambda_function.py @@ -144,6 +144,7 @@ def lambda_handler(event, context): k2 = str(event['params']['header']['X-Hub-Signature'].replace('sha1=', '')) if k1 == k2: secure = True + # TODO: Add the ability to clone TFS repo using SSH keys if not secure: logger.error('Source IP %s is not allowed' % event['context']['source-ip']) raise Exception('Source IP %s is not allowed' % event['context']['source-ip']) diff --git a/lambdas/ZipDl.zip b/lambdas/ZipDl.zip index d4c9def..60cec17 100644 Binary files a/lambdas/ZipDl.zip and b/lambdas/ZipDl.zip differ diff --git a/lambdas/ZipDl/lambda_function.py b/lambdas/ZipDl/lambda_function.py index e30738c..fbaa15d 100644 --- a/lambdas/ZipDl/lambda_function.py +++ b/lambdas/ZipDl/lambda_function.py @@ -8,6 +8,7 @@ import boto3 from botocore.vendored import requests import logging +import base64 import os import shutil from zipfile import ZipFile @@ -66,6 +67,9 @@ def lambda_handler(event, context): hostflavour = 'bitbucket' elif event['params']['header']['User-Agent'].startswith('GitHub-Hookshot'): hostflavour = 'github' + elif event['body-json']['publisherId'] == 'tfs': + hostflavour='tfs' + headers = {} branch = 'master' if hostflavour == 'githubent': @@ -100,6 +104,15 @@ def lambda_handler(event, context): logger.error('Could not get OAuth token. %s: %s' % (r.json()['error'], r.json()['error_description'])) raise Exception('Failed to get OAuth token') headers['Authorization'] = 'Bearer ' + r.json()['access_token'] + elif hostflavour == 'tfs': + archive_url = event['body-json']['resourceContainers']['account']['baseUrl'] + 'DefaultCollection/' + event['body-json']['resourceContainers']['project']['id'] + '/_apis/git/repositories/' + event['body-json']['resource']['repository']['id'] + '/items' + owner = event['body-json']['resource']['pushedBy']['displayName'] + name = event['body-json']['resource']['repository']['name'] + pat_in_base64 = base64.encodestring(':%s' % event['context']['git-token']) + headers['Authorization'] = 'Basic %s' % pat_in_base64 + headers['Authorization'] = headers['Authorization'].replace('\n','') + headers['Accept'] = 'application/zip' + s3_archive_file = "%s/%s/%s/%s.zip" % (owner, name, branch, name) # download the code archive via archive url logger.info('Downloading archive from %s' % archive_url)