diff --git a/conf/access.json b/conf/access.json index 889718d..a401f38 100644 --- a/conf/access.json +++ b/conf/access.json @@ -1,8 +1,8 @@ { - "RunTopic": [ + "run.topic": [ "FooBarUser" ], - "EdlaChangeTopic": [ + "edla.change.topic": [ "FooUser", "BarUser" ] diff --git a/conf/topics.json b/conf/topics.json index 361b053..f051455 100644 --- a/conf/topics.json +++ b/conf/topics.json @@ -1,5 +1,5 @@ { - "RunTopic": { + "run.topic": { "properties": { "app_id_snow": { "description": "Application ID or ServiceNow identifier", @@ -58,7 +58,7 @@ ], "type": "object" }, - "EdlaChangeTopic": { + "edla.change.topic": { "properties": { "app_id_snow": { "description": "Application ID or ServiceNow identifier", diff --git a/notebook.ipynb b/notebook.ipynb index af23507..ca762b9 100644 --- a/notebook.ipynb +++ b/notebook.ipynb @@ -31,7 +31,7 @@ "source": [ "src.event_gate_lambda.lambda_handler({\n", " \"httpMethod\": \"GET\",\n", - " \"resource\": \"/Token\"\n", + " \"resource\": \"/token\"\n", "}, {})" ] }, @@ -44,7 +44,7 @@ "source": [ "src.event_gate_lambda.lambda_handler({\n", " \"httpMethod\": \"GET\",\n", - " \"resource\": \"/Topics\"\n", + " \"resource\": \"/topics\"\n", "}, {})" ] }, @@ -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", "}, {})" ] }, @@ -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", @@ -99,7 +99,7 @@ "source": [ "src.event_gate_lambda.lambda_handler({\n", " \"httpMethod\": \"POST\",\n", - " \"resource\": \"/Terminate\"\n", + " \"resource\": \"/terminate\"\n", "}, {})" ] } diff --git a/src/event_gate_lambda.py b/src/event_gate_lambda.py index 35f4183..56b4074 100644 --- a/src/event_gate_lambda.py +++ b/src/event_gate_lambda.py @@ -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: diff --git a/terraform/api_gateway.tf b/terraform/api_gateway.tf index 1714a3e..fa5d4b5 100644 --- a/terraform/api_gateway.tf +++ b/terraform/api_gateway.tf @@ -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" { @@ -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" { @@ -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" { @@ -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 } } @@ -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 } } @@ -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" {