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

Commit 0ebd2c0

Browse files
committed
update lambda to handle bitbuckt server
1 parent 7b36f63 commit 0ebd2c0

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

functions/source/GitPullS3/lambda_function.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ def lambda_handler(event, context):
143143
if event['params']['header']['X-Gitlab-Token'] in apikeys:
144144
secure = True
145145
if 'X-Hub-Signature' in event['params']['header'].keys():
146+
logger.info('Checking X-Hub-Signature')
146147
for k in apikeys:
147-
k1 = hmac.new(str(k), str(event['context']['raw-body']), hashlib.sha1).hexdigest()
148-
k2 = str(event['params']['header']['X-Hub-Signature'].replace('sha1=', ''))
148+
k1 = hmac.new(str(k), str(event['context']['raw-body']), hashlib.sha256).hexdigest()
149+
k2 = str(event['params']['header']['X-Hub-Signature'].replace('sha256=', ''))
149150
if k1 == k2:
150151
secure = True
151152
# TODO: Add the ability to clone TFS repo using SSH keys
@@ -156,6 +157,10 @@ def lambda_handler(event, context):
156157
full_name = event['body-json']['repository']['fullName']
157158
except KeyError:
158159
full_name = event['body-json']['repository']['path_with_namespace']
160+
try:
161+
full_name = event['body-json']['repository']['name']
162+
except KeyError: # BitBucket pull-request
163+
full_name = event['body-json']['pullRequest']['fromRef']['repository']['name']
159164
if not secure:
160165
logger.error('Source IP %s is not allowed' % event['context']['source-ip'])
161166
raise Exception('Source IP %s is not allowed' % event['context']['source-ip'])
@@ -180,6 +185,17 @@ def lambda_handler(event, context):
180185
remote_url = 'git@'+event['body-json']['repository']['links']['html']['href'].replace('https://', '').replace('/', ':', 1)+'.git'
181186
except:
182187
remote_url = event['body-json']['repository']['ssh_url']
188+
try:
189+
for i, url in enumerate(event['body-json']['repository']['links']['clone']):
190+
if url['name'] == 'ssh':
191+
ssh_index = i
192+
remote_url = event['body-json']['repository']['links']['clone'][ssh_index]['href']
193+
except: # BitBucket pull-request
194+
for i, url in enumerate(event['body-json']['pullRequest']['fromRef']['repository']['links']['clone']):
195+
if url['name'] == 'ssh':
196+
ssh_index = i
197+
198+
remote_url = event['body-json']['pullRequest']['fromRef']['repository']['links']['clone'][ssh_index]['href']
183199
repo_path = '/tmp/%s' % repo_name
184200
creds = RemoteCallbacks(credentials=get_keys(keybucket, pubkey), )
185201
try:

0 commit comments

Comments
 (0)