Skip to content

Commit

Permalink
Add cron job changes for AWS exposed key checker and wiki link (#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-aldera authored Feb 24, 2025
1 parent c1eed78 commit 090d7da
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)
from exposed_key_checker import support_ticketer

WIKI_REFERENCE = os.environ["WIKI_REFERENCE"]
ZENDESK_EXPOSED_TICKET_TAG = os.environ["ZENDESK_EXPOSED_TICKET_TAG"]
ZENDESK_AUTH_SECRET_ID = os.environ["ZENDESK_AUTH_SECRET_ID"]
TOKENS_SERVERS_ALLOW_LIST = [
Expand All @@ -29,7 +30,7 @@ def lambda_handler(_event, _context):
ticket_manager = ZendeskTicketManager(*get_zendesk_auth())
key_data, ignorable_ids, failed_ids = gather_data(ticket_manager)
except Exception as e:
text = f"The key checker could not query the Zendesk API for tickets.\nThe exception was {e}."
text = f"The key checker could not query the Zendesk API for tickets.\nThe exception was {e}. See wiki for guidance: {WIKI_REFERENCE}"
support_ticketer.create_ticket(
"Exposed AWS Key Checker could not query the Zendesk API",
text,
Expand All @@ -46,7 +47,7 @@ def lambda_handler(_event, _context):
)

if failed_ids:
text = f"The key checker could not parse the following Zendesk ticket IDs: {failed_ids}"
text = f"The key checker could not parse the following Zendesk ticket IDs: {failed_ids} \n See wiki for guidance: {WIKI_REFERENCE}"
support_ticketer.create_ticket(
"Exposed AWS Key Checker could not parse Zendesk tickets",
text,
Expand All @@ -71,7 +72,7 @@ def process_data(data: "list[ExposedKeyData]", ticket_manager: "ZendeskTicketMan
try:
send_to_tokens_server(item)
except Exception as e:
text = f"The key checker could not post the exposed event to the tokens server for the following item: {item}\nThe exception was: {e}.\n\nThis post will be retried automatically on the next run of the lambda. This only needs to be investigated if the failures continue."
text = f"The key checker could not post the exposed event to the tokens server for the following item: {item}\nThe exception was: {e}.\n\nThis post will be retried automatically on the next run of the lambda. This only needs to be investigated if the failures continue: {WIKI_REFERENCE}."
support_ticketer.create_ticket(
"Exposed AWS Key Checker could not post to tokens server",
text,
Expand Down
4 changes: 3 additions & 1 deletion aws-exposed-key-checker-infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ resource "aws_lambda_function" "key_checker_lambda" {
{
TICKET_SERVICE_URL = "${var.ticket_service_url}"
TICKET_SERVICE_RECIPIENT = "${var.ticket_service_recipient}"
WIKI_REFERENCE = "${var.wiki_reference}"
ZENDESK_EXPOSED_TICKET_TAG = "${var.zendesk_exposed_ticket_tag}"
ZENDESK_CLOSED_TICKET_TAG = "${var.zendesk_closed_ticket_tag}"
ZENDESK_ASSIGNEE = "${var.zendesk_assignee}"
Expand Down Expand Up @@ -138,7 +139,8 @@ resource "aws_iam_role_policy_attachment" "console_event_dispatcher_lambda_basic
# Schedule lambda run
resource "aws_cloudwatch_event_rule" "periodic_run" {
name = "run_exposed_key_checker_periodically"
schedule_expression = "rate(4 hours)"
description = "Triggers every hour on the hour"
schedule_expression = "cron(0 * * * ? *)"
}

resource "aws_cloudwatch_event_target" "lambda_target" {
Expand Down
4 changes: 4 additions & 0 deletions aws-exposed-key-checker-infra/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ variable "ticket_service_recipient" {
type = string
}

variable "wiki_reference" {
type = string
}

variable "zendesk_exposed_ticket_tag" {
type = string
}
Expand Down

0 comments on commit 090d7da

Please sign in to comment.