Skip to content

Commit

Permalink
chore(env): add back env
Browse files Browse the repository at this point in the history
  • Loading branch information
kishore03109 committed Jun 18, 2024
1 parent 60a4288 commit b282a1e
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .aws/deploy/backend-task-definition.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"valueFrom": "PROD_INCOMING_QUEUE_URL"
},
{ "name": "JWT_SECRET", "valueFrom": "PROD_JWT_SECRET" },
{ "name": "KEYCDN_API_KEY", "valueFrom": "PROD_KEYCDN_API_KEY" },
{
"name": "MAX_NUM_OTP_ATTEMPTS",
"valueFrom": "PROD_MAX_NUM_OTP_ATTEMPTS"
Expand Down Expand Up @@ -132,6 +133,11 @@
"name": "REDIRECT_URI",
"valueFrom": "PROD_REDIRECT_URI"
},
{
"name": "REDIRECTION_REPO_GITHUB_TOKEN",
"valueFrom": "PROD_REDIRECTION_REPO_GITHUB_TOKEN"
},
{ "name": "REDIS_HOST", "valueFrom": "PROD_REDIS_HOST" },
{
"name": "SESSION_SECRET",
"valueFrom": "PROD_SESSION_SECRET"
Expand Down
6 changes: 6 additions & 0 deletions .aws/deploy/backend-task-definition.staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"valueFrom": "STAGING_INCOMING_QUEUE_URL"
},
{ "name": "JWT_SECRET", "valueFrom": "STAGING_JWT_SECRET" },
{ "name": "KEYCDN_API_KEY", "valueFrom": "STAGING_KEYCDN_API_KEY" },
{
"name": "MAX_NUM_OTP_ATTEMPTS",
"valueFrom": "STAGING_MAX_NUM_OTP_ATTEMPTS"
Expand Down Expand Up @@ -141,6 +142,11 @@
"name": "REDIRECT_URI",
"valueFrom": "STAGING_REDIRECT_URI"
},
{
"name": "REDIRECTION_REPO_GITHUB_TOKEN",
"valueFrom": "STAGING_REDIRECTION_REPO_GITHUB_TOKEN"
},
{ "name": "REDIS_HOST", "valueFrom": "STAGING_REDIS_HOST" },
{
"name": "SESSION_SECRET",
"valueFrom": "STAGING_SESSION_SECRET"
Expand Down
4 changes: 4 additions & 0 deletions .aws/deploy/support-task-definition.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@
"name": "REDIRECT_URI",
"valueFrom": "PROD_REDIRECT_URI"
},
{
"name": "REDIRECTION_REPO_GITHUB_TOKEN",
"valueFrom": "PROD_REDIRECTION_REPO_GITHUB_TOKEN"
},
{ "name": "REDIS_HOST", "valueFrom": "PROD_REDIS_HOST" },
{
"name": "SESSION_SECRET",
Expand Down
4 changes: 4 additions & 0 deletions .aws/deploy/support-task-definition.staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
"name": "REDIRECT_URI",
"valueFrom": "STAGING_REDIRECT_URI"
},
{
"name": "REDIRECTION_REPO_GITHUB_TOKEN",
"valueFrom": "STAGING_REDIRECTION_REPO_GITHUB_TOKEN"
},
{ "name": "REDIS_HOST", "valueFrom": "STAGING_REDIS_HOST" },
{
"name": "SESSION_SECRET",
Expand Down
7 changes: 7 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ const config = convict({
format: "required-string",
default: "",
},
redirectionRepoGithubToken: {
doc: "Github access to read opengovsg/isomer-redirection",
env: "REDIRECTION_REPO_GITHUB_TOKEN",
sensitive: true,
format: "required-string",
default: "",
},
},
dataDog: {
env: {
Expand Down
6 changes: 4 additions & 2 deletions src/monitoring/MonitoringWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,16 @@ export default class MonitoringWorker {
* @returns List of redirection domains that are listed in the isomer-redirection repository
*/
getRedirectionDomains() {
const SYSTEM_GITHUB_TOKEN = config.get("github.systemToken")
const REDIRECTION_REPO_GITHUB_TOKEN = config.get(
"github.redirectionRepoGithubToken"
)
// seems to be a bug in typing, this is a direct
// copy paste from the octokit documentation
// https://octokit.github.io/rest.js/v20#automatic-retries
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const OctokitRetry = Octokit.plugin(retry as any)
const octokitWithRetry: Octokit = new OctokitRetry({
auth: SYSTEM_GITHUB_TOKEN,
auth: REDIRECTION_REPO_GITHUB_TOKEN,
request: { retries: 5 },
})

Expand Down
1 change: 0 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ import { mailer } from "@services/utilServices/MailClient"

import { apiLogger } from "./middleware/apiLogger"
import { NotificationOnEditHandler } from "./middleware/notificationOnEditHandler"
import MonitoringService from "./monitoring"
import getAuthenticatedSubrouter from "./routes/v2/authenticated"
import { ReviewsRouter } from "./routes/v2/authenticated/review"
import getAuthenticatedSitesSubrouter from "./routes/v2/authenticatedSites"
Expand Down
15 changes: 14 additions & 1 deletion src/utils/dns-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ export default function getDnsCheckerMessage(
intermediateRecords: string[] | null,
redirectionRecords: string[] | null
): Result<string, string> {
console.log({
domain,
cnameDomain,
redirectionDomain,
cnameRecord,
indirectionDomain,
intermediateRecords,
redirectionRecords,
})
const isKeyCdnDomain = cnameRecord?.endsWith("key.kxcdn.com")

// Domain has a CNAME pointing to one of our known suffixes
const isDomainCnameCorrect =
!!cnameRecord &&
Expand Down Expand Up @@ -171,8 +182,10 @@ export default function getDnsCheckerMessage(
}

export function dnsMonitor(domain: string): ResultAsync<string, string> {
console.log("in dns monitor", domain)
return checkCname(domain)
.andThen((cname) => {
console.log({ cname })
// Original domain does not have a CNAME record, check if the www
// version has a valid CNAME record
if (!cname && !domain.startsWith("www.")) {
Expand All @@ -182,10 +195,10 @@ export function dnsMonitor(domain: string): ResultAsync<string, string> {
checkCname(cnameDomain),
])
}

return ResultAsync.combine([okAsync(domain), okAsync(cname)])
})
.andThen(([cnameDomain, cnameRecord]) => {
console.log("indirection domain getting")
// Original and www version of the domain do not have a CNAME record,
// check if our indirection domain is still correct
if (!cnameRecord) {
Expand Down
5 changes: 4 additions & 1 deletion support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useSharedMiddleware } from "@common/middleware"
import { config } from "@root/config/config"
import logger from "@root/logger/logger"
import MonitoringService from "@root/monitoring/MonitoringService"
import MonitoringWorker from "@root/monitoring/monitoringWorker"
import MonitoringWorker from "@root/monitoring/MonitoringWorker"

import { ROUTE_VERSION } from "./constants"
import { v2Router } from "./routes"
Expand All @@ -24,6 +24,9 @@ infraService.pollMessages()
export const monitoringWorker = new MonitoringWorker({
launchesService,
})
// dnsMonitor("isomer.gov.sg").mapErr(console.log).map(console.log)
// todo: remove after testing
monitoringWorker.driver()

export const monitoringService = new MonitoringService({
monitoringWorker,
Expand Down

0 comments on commit b282a1e

Please sign in to comment.