Skip to content
This repository was archived by the owner on Oct 4, 2024. It is now read-only.

Commit 202face

Browse files
authored
Merge pull request #4 from aws-quickstart/feature/tfs
updated the ZipDl to support TFS as a source, created a new zip, adde…
2 parents 7ed09ee + 8077236 commit 202face

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

lambdas/GitPullS3/.DS_Store

-6 KB
Binary file not shown.

lambdas/GitPullS3/lambda_function.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def lambda_handler(event, context):
144144
k2 = str(event['params']['header']['X-Hub-Signature'].replace('sha1=', ''))
145145
if k1 == k2:
146146
secure = True
147+
# TODO: Add the ability to clone TFS repo using SSH keys
147148
if not secure:
148149
logger.error('Source IP %s is not allowed' % event['context']['source-ip'])
149150
raise Exception('Source IP %s is not allowed' % event['context']['source-ip'])

lambdas/ZipDl.zip

511 Bytes
Binary file not shown.

lambdas/ZipDl/lambda_function.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import boto3
99
from botocore.vendored import requests
1010
import logging
11+
import base64
1112
import os
1213
import shutil
1314
from zipfile import ZipFile
@@ -66,6 +67,9 @@ def lambda_handler(event, context):
6667
hostflavour = 'bitbucket'
6768
elif event['params']['header']['User-Agent'].startswith('GitHub-Hookshot'):
6869
hostflavour = 'github'
70+
elif event['body-json']['publisherId'] == 'tfs':
71+
hostflavour='tfs'
72+
6973
headers = {}
7074
branch = 'master'
7175
if hostflavour == 'githubent':
@@ -100,6 +104,15 @@ def lambda_handler(event, context):
100104
logger.error('Could not get OAuth token. %s: %s' % (r.json()['error'], r.json()['error_description']))
101105
raise Exception('Failed to get OAuth token')
102106
headers['Authorization'] = 'Bearer ' + r.json()['access_token']
107+
elif hostflavour == 'tfs':
108+
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'
109+
owner = event['body-json']['resource']['pushedBy']['displayName']
110+
name = event['body-json']['resource']['repository']['name']
111+
pat_in_base64 = base64.encodestring(':%s' % event['context']['git-token'])
112+
headers['Authorization'] = 'Basic %s' % pat_in_base64
113+
headers['Authorization'] = headers['Authorization'].replace('\n','')
114+
headers['Accept'] = 'application/zip'
115+
103116
s3_archive_file = "%s/%s/%s/%s.zip" % (owner, name, branch, name)
104117
# download the code archive via archive url
105118
logger.info('Downloading archive from %s' % archive_url)

0 commit comments

Comments
 (0)