-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.py
34 lines (27 loc) · 1019 Bytes
/
auth.py
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
from smart_cdss_api.conf.conf import secret_token
def generatePolicy(principalId, effect, methodArn):
authResponse = {}
authResponse['principalId'] = principalId
if effect and methodArn:
policyDocument = {
'Version': '2012-10-17',
'Statement': [
{
'Sid': 'FirstStatement',
'Action': 'lambda:InvokeFunction',
'Effect': effect,
'Resource': methodArn
}
]
}
authResponse['policyDocument'] = policyDocument
return authResponse
def lambda_handler(event, context):
try:
#token = event['authorizationToken']
#if token == secret_token:
return generatePolicy('user', 'Allow', event['methodArn'])
return generatePolicy(None, 'Deny', event['methodArn'])
except ValueError as err:
# Deny access if the token is invalid
return generatePolicy(None, 'Deny', event['methodArn'])