Skip to content

Commit

Permalink
feat: use convict for env vars (#646)
Browse files Browse the repository at this point in the history
* feat: add convict as dependency

* feat: config wip

* feat: add convict schema with defaults and validation

* feat: add config alias and update dependencies

* feat: replace process.env with config.get (wip)

* fix: use import over require

* feat: wip to use config

* feat: add cloudmersive key as env

* feat: wip to use config

* feat: update config properties

* feat: update imports and use config

* chore: update env.test and imports

* chore: standardise env

* chore: remove dotenv

* chore: format eslintrc

* fix: rename convict format and env enums

* chore: remove DOMAIN_WHITELIST from env

* chore: revert trust proxy change

* fix: cookie domain to be enums

* feat: update to use config

* fix: remove checks for env in logic

* fix: make gitGuardian optional env

* feat: add staging as option for node env

* chore(app): chagne to import syntax

* fix: remove string coercing for env key

* chore: remove check for undefine site create form key env

* chore: update package-lock

---------

Co-authored-by: seaerchin <jiachin@open.gov.sg>
  • Loading branch information
2 people authored and alexanderleegs committed Mar 30, 2023
1 parent 3db9533 commit 0ac21de
Show file tree
Hide file tree
Showing 50 changed files with 22,448 additions and 15,268 deletions.
9 changes: 7 additions & 2 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export GITHUB_BUILD_REPO_NAME="isomer-build"
export MUTEX_TABLE_NAME=""
export MAX_NUM_OTP_ATTEMPTS=5
export OTP_EXPIRY=900000
export MUTEX_TABLE_NAME="mutex-table"

# GitHub access token to create repo
export SYSTEM_GITHUB_TOKEN=""
Expand All @@ -39,7 +40,6 @@ export DB_ENABLE_LOGGING=""

export LOCAL_SITE_ACCESS_TOKEN=""
export OTP_SECRET="dummysecret"
export DOMAIN_WHITELIST=".gov.sg"

# Email
export POSTMAN_API_KEY=""
Expand All @@ -56,4 +56,9 @@ export DD_TAGS="service:isomer"
export CLOUDMERSIVE_API_KEY=""

# GitGuardian
export GITGUARDIAN_API_KEY=""
export GITGUARDIAN_API_KEY=""

# SQS Queue
export INCOMING_QUEUE_URL="incoming"
export OUTGOING_QUEUE_URL="outgoing"
export SITE_LAUNCH_QUEUE_URL="site_launch"
42 changes: 39 additions & 3 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,58 @@ export FRONTEND_URL="http://localhost:3000"
export GITHUB_ORG_NAME="isomerpages"
export GITHUB_BUILD_ORG_NAME="opengovsg"
export GITHUB_BUILD_REPO_NAME="isomer-build"
export MUTEX_TABLE_NAME="mutex-table"
export ISOMERPAGES_REPO_PAGE_COUNT=3
export MAX_NUM_OTP_ATTEMPTS=5
export OTP_EXPIRY=900000
export SESSION_SECRET=blahblah

# GitHub access token to create repo
export SYSTEM_GITHUB_TOKEN="github_token"

# FormSG keys
export SITE_CREATE_FORM_KEY="site_form_key"

# Required to connect to DynamoDB
export AWS_ACCESS_KEY_ID="abc123"
export AWS_SECRET_ACCESS_KEY="xyz123"

# Required to run end-to-end tests
export E2E_TEST_REPO="e2e-test-repo"
export E2E_TEST_SECRET="test"
export E2E_TEST_GH_TOKEN="test"

# Database
export DB_URI="postgres://isomer:password@localhost:54321/isomercms_test"
export DB_MIN_POOL="1"
export DB_MAX_POOL="10"
export DB_ENABLE_LOGGING=""
export DB_ENABLE_LOGGING="true"

export LOCAL_SITE_ACCESS_TOKEN=""
export LOCAL_SITE_ACCESS_TOKEN="dummy"
export OTP_SECRET="dummysecret"
export DOMAIN_WHITELIST=".gov.sg"

# Email
export POSTMAN_API_KEY="some api key"

# SMS
export POSTMAN_SMS_CRED_NAME="isomer"

# Amplify
export AWS_REGION="ap-southeast-1"
export AWS_ACCOUNT_NUMBER="random"

# DataDog
export DD_ENV="local"
export DD_SERVICE="isomer"
export DD_TAGS="service:isomer"

# Cloudmersive
export CLOUDMERSIVE_API_KEY="cloudmersive"

# GitGuardian
export GITGUARDIAN_API_KEY="gitguardian"

# SQS Queue
export INCOMING_QUEUE_URL="incoming"
export OUTGOING_QUEUE_URL="outgoing"
export SITE_LAUNCH_QUEUE_URL="site_launch"
239 changes: 125 additions & 114 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,118 +1,129 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true,
"jest": true,
"jest/globals": true
},
"extends": [
"airbnb-base",
"prettier",
"plugin:import/typescript"
],
"plugins": ["only-warn", "import", "jest"],
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
"no-underscore-dangle": "off",
"class-methods-use-this": "off",
"import/no-unresolved": "error",
"import/extensions": ["warn", "never"],
"import/order": [
"error",
{
"alphabetize": {
"order": "asc",
"caseInsensitive": true
},
"newlines-between": "always",
"groups": ["builtin", "external", "internal", "parent", "sibling", "index", "object"],
"pathGroups": [{
"pattern": "@logger/**",
"group": "internal",
"position": "before"
},
{
"pattern": "@errors/**",
"group": "internal",
"position": "before"
},
{
"pattern": "@middleware/**",
"group": "internal",
"position": "before"
},
{
"pattern": "@classes/**",
"group": "internal",
"position": "before"
},
{
"pattern": "@routes/**",
"group": "internal",
"position": "before"
},
{
"pattern": "@utils/**",
"group": "internal",
"position": "before"
},
{
"pattern": "@validators/**",
"group": "internal",
"position": "before"
},
{
"pattern": "@constants/**",
"group": "internal",
"position": "before"
}
]
}
"env": {
"browser": true,
"commonjs": true,
"es2021": true,
"jest": true,
"jest/globals": true
},
"extends": ["airbnb-base", "prettier", "plugin:import/typescript"],
"plugins": ["only-warn", "import", "jest"],
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
"no-underscore-dangle": "off",
"class-methods-use-this": "off",
"import/no-unresolved": "error",
"import/extensions": ["warn", "never"],
"import/order": [
"error",
{
"alphabetize": {
"order": "asc",
"caseInsensitive": true
},
"newlines-between": "always",
"groups": [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
"object"
],
"jest/no-identical-title": "error"
},
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"parser": "@typescript-eslint/parser",
"extends": ["plugin:@typescript-eslint/recommended"]
}
],
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"typescript": {
// always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
"alwaysTryTypes": true
},
"node": {
"paths": ["src"],
"extensions": [".js", ".jsx", ".ts", ".tsx"]
},
"alias": [
["@root", "."],
["@classes", "./classes"],
["@errors", "./errors"],
["@logger", "./logger"],
["@middleware", "./middleware"],
["@routes", "./routes"],
["@utils", "./utils"],
["@loaders", "./loaders"],
["@database", "./database"],
["@services", "./services"],
["@validators", "./validators"],
["@fixtures", "./fixtures"],
["@database", "./database"],
["@constants", "./constants"]
]
}
"pathGroups": [
{
"pattern": "@config/**",
"group": "internal",
"position": "before"
},
{
"pattern": "@logger/**",
"group": "internal",
"position": "before"
},
{
"pattern": "@errors/**",
"group": "internal",
"position": "before"
},
{
"pattern": "@middleware/**",
"group": "internal",
"position": "before"
},
{
"pattern": "@classes/**",
"group": "internal",
"position": "before"
},
{
"pattern": "@routes/**",
"group": "internal",
"position": "before"
},
{
"pattern": "@utils/**",
"group": "internal",
"position": "before"
},
{
"pattern": "@validators/**",
"group": "internal",
"position": "before"
},
{
"pattern": "@constants/**",
"group": "internal",
"position": "before"
}
]
}
],
"jest/no-identical-title": "error"
},
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"parser": "@typescript-eslint/parser",
"extends": ["plugin:@typescript-eslint/recommended"]
}
],
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"globals": {
"Base64": true
"import/resolver": {
"typescript": {
// always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
"alwaysTryTypes": true
},
"node": {
"paths": ["src"],
"extensions": [".js", ".jsx", ".ts", ".tsx"]
},
"alias": [
["@root", "."],
["@config", "./config"],
["@classes", "./classes"],
["@errors", "./errors"],
["@logger", "./logger"],
["@middleware", "./middleware"],
["@routes", "./routes"],
["@utils", "./utils"],
["@loaders", "./loaders"],
["@database", "./database"],
["@services", "./services"],
["@validators", "./validators"],
["@fixtures", "./fixtures"],
["@database", "./database"],
["@constants", "./constants"]
]
}
}
},
"globals": {
"Base64": true
}
}
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
"^@root/(.*)": "<rootDir>/$1",
"^@classes/(.*)": "<rootDir>/classes/$1",
"^@errors/(.*)": "<rootDir>/errors/$1",
"^@config/(.*)": "<rootDir>/config/$1",
"^@logger/(.*)": "<rootDir>/logger/$1",
"^@middleware/(.*)": "<rootDir>/middleware/$1",
"^@routes/(.*)": "<rootDir>/routes/$1",
Expand Down
Loading

0 comments on commit 0ac21de

Please sign in to comment.