Skip to content
This repository was archived by the owner on Oct 4, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed lambdas/GitPullS3/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions lambdas/GitPullS3/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
Binary file modified lambdas/ZipDl.zip
Binary file not shown.
13 changes: 13 additions & 0 deletions lambdas/ZipDl/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import boto3
from botocore.vendored import requests
import logging
import base64
import os
import shutil
from zipfile import ZipFile
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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)
Expand Down