Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move DNS checker slackbot from lambda #1367

Merged
merged 6 commits into from
Jun 4, 2024
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
2 changes: 2 additions & 0 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

import { config } from "@config/config"

export enum JobStatus {

Check warning on line 5 in src/constants/constants.ts

View workflow job for this annotation

GitHub Actions / lint

'JobStatus' is already declared in the upper scope on line 5 column 13
Ready = "READY", // Ready to run jobs
Running = "RUNNING", // A job is running
Failed = "FAILED", // A job has failed and recovery is needed
}

export enum SiteStatus {

Check warning on line 11 in src/constants/constants.ts

View workflow job for this annotation

GitHub Actions / lint

'SiteStatus' is already declared in the upper scope on line 11 column 13
Empty = "EMPTY", // A site record site is being initialized
Initialized = "INITIALIZED",
Launched = "LAUNCHED",
}

export enum RedirectionTypes {

Check warning on line 17 in src/constants/constants.ts

View workflow job for this annotation

GitHub Actions / lint

'RedirectionTypes' is already declared in the upper scope on line 17 column 13
CNAME = "CNAME",
A = "A",
}

export enum CollaboratorRoles {

Check warning on line 22 in src/constants/constants.ts

View workflow job for this annotation

GitHub Actions / lint

'CollaboratorRoles' is already declared in the upper scope on line 22 column 13
Admin = "ADMIN",
Contributor = "CONTRIBUTOR",
IsomerAdmin = "ISOMERADMIN",
Expand All @@ -30,7 +30,7 @@
CollaboratorRoles.IsomerAdmin
>

export enum ReviewRequestStatus {

Check warning on line 33 in src/constants/constants.ts

View workflow job for this annotation

GitHub Actions / lint

'ReviewRequestStatus' is already declared in the upper scope on line 33 column 13
Approved = "APPROVED",
Open = "OPEN",
Merged = "MERGED",
Expand Down Expand Up @@ -79,6 +79,8 @@
export const ALLOWED_DNS_ERROR_CODES = ["ENOTFOUND", "ENODATA"]

export const DNS_INDIRECTION_DOMAIN = "hostedon.isomer.gov.sg"
export const DNS_KEYCDN_SUFFIX = "kxcdn.com"
export const DNS_CNAME_SUFFIXES = ["cloudfront.net", DNS_KEYCDN_SUFFIX]
export const DNS_INDIRECTION_REPO = "isomer-indirection"
export const ISOMER_ADMIN_EMAIL = "[email protected]"
export const ISOMER_SUPPORT_EMAIL = "[email protected]"
Expand Down
11 changes: 11 additions & 0 deletions src/types/dnsChecker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface DnsCheckerResponse {
// eslint-disable-next-line camelcase
response_type: "in_channel"
blocks: Array<{
type: "section"
text: {
type: "mrkdwn"
text: string
}
}>
}
20 changes: 20 additions & 0 deletions support/routes/v2/isobot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import express, { RequestHandler } from "express"
import { Whitelist } from "@database/models"
import logger from "@root/logger/logger"
import WhitelistService from "@root/services/identity/WhitelistService"
import type { DnsCheckerResponse } from "@root/types/dnsChecker"

import BotService, { SlackPayload } from "./ops/botService"

Expand Down Expand Up @@ -40,4 +41,23 @@ const handleWhitelistEmails: RequestHandler<
}
}

const handleDnsChecker: RequestHandler<
Copy link
Contributor

Choose a reason for hiding this comment

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

trouble you to remove the console.log in line 22 please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in 15d5512!

never,
DnsCheckerResponse | { message: string },
SlackPayload,
unknown,
never
> = async (req, res) => {
const validatedDomain = botService.getValidatedDomain(req.body)
if (!validatedDomain)
return res.status(200).send({
message: `Sorry, \`${req.body.text}\` is not a valid domain name. Please try again with a valid one instead.`,
})

return botService
.dnsChecker(req.body)
.map((response) => res.status(200).send(response))
}

isobotRouter.post("/dns-checker", handleDnsChecker)
isobotRouter.post("/whitelist-emails", handleWhitelistEmails)
Loading
Loading