forked from ciscops/cidrbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcidr_git_lambda_function.py
More file actions
39 lines (32 loc) · 1.04 KB
/
cidr_git_lambda_function.py
File metadata and controls
39 lines (32 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import logging
import datetime
import json
import os
import sys
from git_cidrbot.gitauth import gitauth
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
def lambda_handler(event, handle):
logger.debug('new event received: %s', str(event))
logger.debug(str(event))
logger.debug(str(handle))
start_time = datetime.datetime.now()
if 'GITHUB_BOT_NAME' in os.environ:
git_bot_name = os.getenv("GITHUB_BOT_NAME")
else:
logging.error("Environment variable GITHUB_BOT_NAME must be set")
sys.exit(1)
git = gitauth()
webhook_payload = git.webhook_request(event)
end_time = datetime.datetime.now()
logger.debug('Script complete, total runtime {%s - %s}', end_time, start_time)
if webhook_payload is not None:
return webhook_payload
return {
"statusCode": 302,
"headers": {
"Location": 'https://github.com/apps/' + git_bot_name,
"Content-Type": "application/json"
},
"body": json.dumps({"Redirect ": "successful"})
}