Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions conf/access.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"RunTopic": [
"run.topic": [
"FooBarUser"
],
"EdlaChangeTopic": [
"edla.change.topic": [
"FooUser",
"BarUser"
]
Expand Down
4 changes: 2 additions & 2 deletions conf/topics.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"RunTopic": {
"run.topic": {
"properties": {
"app_id_snow": {
"description": "Application ID or ServiceNow identifier",
Expand Down Expand Up @@ -58,7 +58,7 @@
],
"type": "object"
},
"EdlaChangeTopic": {
"edla.change.topic": {
"properties": {
"app_id_snow": {
"description": "Application ID or ServiceNow identifier",
Expand Down
14 changes: 7 additions & 7 deletions notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"source": [
"src.event_gate_lambda.lambda_handler({\n",
" \"httpMethod\": \"GET\",\n",
" \"resource\": \"/Token\"\n",
" \"resource\": \"/token\"\n",
"}, {})"
]
},
Expand All @@ -44,7 +44,7 @@
"source": [
"src.event_gate_lambda.lambda_handler({\n",
" \"httpMethod\": \"GET\",\n",
" \"resource\": \"/Topics\"\n",
" \"resource\": \"/topics\"\n",
"}, {})"
]
},
Expand All @@ -57,8 +57,8 @@
"source": [
"src.event_gate_lambda.lambda_handler({\n",
" \"httpMethod\": \"GET\",\n",
" \"resource\": \"/Topics/{topicName}\",\n",
" \"pathParameters\": {\"topicName\": \"RunTopic\"}\n",
" \"resource\": \"/topics/{topic_name}\",\n",
" \"pathParameters\": {\"topic_name\": \"run.topic\"}\n",
"}, {})"
]
},
Expand All @@ -72,8 +72,8 @@
"import json\n",
"src.event_gate_lambda.lambda_handler({\n",
" \"httpMethod\": \"POST\",\n",
" \"resource\": \"/Topics/{topicName}\",\n",
" \"pathParameters\": {\"topicName\": \"EdlaChangeTopic\"},\n",
" \"resource\": \"/topics/{topic_name}\",\n",
" \"pathParameters\": {\"topic_name\": \"edla.change.topic\"},\n",
" \"headers\": {\"bearer\": jwtToken},\n",
" \"body\": json.dumps({\n",
" \"app_id_snow\": \"app-1234\",\n",
Expand All @@ -99,7 +99,7 @@
"source": [
"src.event_gate_lambda.lambda_handler({\n",
" \"httpMethod\": \"POST\",\n",
" \"resource\": \"/Terminate\"\n",
" \"resource\": \"/terminate\"\n",
"}, {})"
]
}
Expand Down
12 changes: 6 additions & 6 deletions src/event_gate_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ def postTopicMessage(topicName, topicMessage, tokenEncoded):

def lambda_handler(event, context):
try:
if event["resource"] == "/Token":
if event["resource"].lower() == "/token":
return getToken()
if event["resource"] == "/Topics":
if event["resource"].lower() == "/topics":
return getTopics()
if event["resource"] == "/Topics/{topicName}":
if event["resource"].lower() == "/topics/{topic_name}":
if event["httpMethod"] == "GET":
return getTopicSchema(event["pathParameters"]["topicName"])
return getTopicSchema(event["pathParameters"]["topic_name"].lower())
if event["httpMethod"] == "POST":
return postTopicMessage(event["pathParameters"]["topicName"], json.loads(event["body"]), event["headers"]["bearer"])
if event["resource"] == "/Terminate":
return postTopicMessage(event["pathParameters"]["topic_name"].lower(), json.loads(event["body"]), event["headers"]["bearer"])
if event["resource"].lower() == "/terminate":
sys.exit("TERMINATING")
return {"statusCode": 404}
except Exception as e:
Expand Down
12 changes: 6 additions & 6 deletions terraform/api_gateway.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ resource "aws_api_gateway_rest_api" "event_gate_api" {
resource "aws_api_gateway_resource" "event_gate_api_token" {
rest_api_id = aws_api_gateway_rest_api.event_gate_api.id
parent_id = aws_api_gateway_rest_api.event_gate_api.root_resource_id
path_part = "Token"
path_part = "token"
}

resource "aws_api_gateway_method" "event_gate_api_token_get" {
Expand All @@ -43,7 +43,7 @@ resource "aws_api_gateway_integration" "event_gate_api_token_get_integration" {
resource "aws_api_gateway_resource" "event_gate_api_topics" {
rest_api_id = aws_api_gateway_rest_api.event_gate_api.id
parent_id = aws_api_gateway_rest_api.event_gate_api.root_resource_id
path_part = "Topics"
path_part = "topics"
}

resource "aws_api_gateway_method" "event_gate_api_topics_get" {
Expand All @@ -65,7 +65,7 @@ resource "aws_api_gateway_integration" "event_gate_api_topics_get_integration" {
resource "aws_api_gateway_resource" "event_gate_api_topic_name" {
rest_api_id = aws_api_gateway_rest_api.event_gate_api.id
parent_id = aws_api_gateway_resource.event_gate_api_topics.id
path_part = "{topicName}"
path_part = "{topic_name}"
}

resource "aws_api_gateway_method" "event_gate_api_topic_name_get" {
Expand All @@ -74,7 +74,7 @@ resource "aws_api_gateway_method" "event_gate_api_topic_name_get" {
authorization = "NONE"
http_method = "GET"
request_parameters = {
"method.request.path.topicName" = true
"method.request.path.topic_name" = true
}
}

Expand All @@ -93,7 +93,7 @@ resource "aws_api_gateway_method" "event_gate_api_topic_name_post" {
authorization = "NONE"
http_method = "POST"
request_parameters = {
"method.request.path.topicName" = true
"method.request.path.topic_name" = true
}
}

Expand All @@ -109,7 +109,7 @@ resource "aws_api_gateway_integration" "event_gate_api_topic_name_post_integrati
resource "aws_api_gateway_resource" "event_gate_api_terminate" {
rest_api_id = aws_api_gateway_rest_api.event_gate_api.id
parent_id = aws_api_gateway_rest_api.event_gate_api.root_resource_id
path_part = "Terminate"
path_part = "terminate"
}

resource "aws_api_gateway_method" "event_gate_api_terminate_post" {
Expand Down