Skip to content
Merged
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
37 changes: 24 additions & 13 deletions src/event_gate_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,14 @@ def getTopicSchema(topicName):

def postTopicMessage(topicName, topicMessage, tokenEncoded):
print(f"Handling POST {topicName}")
token = jwt.decode(tokenEncoded, TOKEN_PUBLIC_KEY, algorithms=["RS256"])
try:
token = jwt.decode(tokenEncoded, TOKEN_PUBLIC_KEY, algorithms=["RS256"])
except Exception as e:
return {
"statusCode": 401,
"headers": {"Content-Type": "text/plain"},
"body": str(e)
}

if topicName not in TOPICS:
return { "statusCode": 404 }
Expand All @@ -126,15 +133,19 @@ def postTopicMessage(topicName, topicMessage, tokenEncoded):
return {"statusCode": kafkaWrite(topicName, topicMessage)}

def lambda_handler(event, context):
if event["resource"] == "/Token":
return getToken()
if event["resource"] == "/Topics":
return getTopics()
if event["resource"] == "/Topics/{topicName}":
if event["httpMethod"] == "GET":
return getTopicSchema(event["pathParameters"]["topicName"])
if event["httpMethod"] == "POST":
return postTopicMessage(event["pathParameters"]["topicName"], json.loads(event["body"]), event["headers"]["bearer"])
if event["resource"] == "/Terminate":
sys.exit("TERMINATING")
return {"statusCode": 404}
try:
if event["resource"] == "/Token":
return getToken()
if event["resource"] == "/Topics":
return getTopics()
if event["resource"] == "/Topics/{topicName}":
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are our resources in url capitalized?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, would you prefer them not to be?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in #12

if event["httpMethod"] == "GET":
return getTopicSchema(event["pathParameters"]["topicName"])
if event["httpMethod"] == "POST":
return postTopicMessage(event["pathParameters"]["topicName"], json.loads(event["body"]), event["headers"]["bearer"])
if event["resource"] == "/Terminate":
sys.exit("TERMINATING")
return {"statusCode": 404}
except Exception as e:
print(f"Unexpected exception: {e}")
return {"statusCode": 500}