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(vapt): merge back into tracking branch #590

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ab1f0a3
Feat/login flow (#477)
alexanderleegs Sep 29, 2022
398d70f
feat: collaborators (#510)
prestonlimlianjie Oct 4, 2022
ec83a78
ref(services): migrate SitesService to TypeScript (#512)
dcshzj Oct 12, 2022
c84c64c
feat(rr): db migrations (#515)
seaerchin Oct 14, 2022
7c6c4fa
feat: introduce a new site info API endpoint (#513)
dcshzj Oct 14, 2022
8518296
feat: add collaborators statistics API endpoint (#520)
dcshzj Oct 14, 2022
2196e93
refactor: remove all usages of TokenStore and tests (#533)
dcshzj Oct 18, 2022
177891e
feat(rr): add database models (#518)
seaerchin Oct 20, 2022
90eb48e
feat: add new siteUrl API endpoint to get the production URL of site …
dcshzj Oct 20, 2022
a78d7e4
Feat/notifications (#508)
alexanderleegs Oct 21, 2022
cf7be42
feat(rr): services + routes (#519)
seaerchin Oct 21, 2022
9162104
feat: add model and migration for review_request_views table (#521)
dcshzj Oct 21, 2022
097dd7b
feat: add review request views API endpoint and functions (#532)
dcshzj Oct 21, 2022
54c279e
fix(server): removed extra db assoc
seaerchin Oct 21, 2022
efc12f0
fix(formsgsitecreation): removed extra prop
seaerchin Oct 21, 2022
4cbd525
Fix: reviewRequestId instead of reviewId
alexanderleegs Oct 21, 2022
d2cbb11
fix(server.js): add reviewrequestview init
seaerchin Oct 21, 2022
07f4c90
feat: add endpoint to mark a review request as viewed (#550)
dcshzj Oct 31, 2022
5f06df3
Feat/comments (#534)
alexanderleegs Nov 2, 2022
07e1947
feat(rr): adds be for unapproval of rr (#540)
seaerchin Nov 2, 2022
25c7922
fix: use review request requestor email for production commit email (…
dcshzj Nov 2, 2022
3d7354f
fix: include full model in order by due to presence of alias (#554)
dcshzj Nov 3, 2022
a4b68c3
fix(server): swap order for auth to avoid nemspace conflicts
seaerchin Nov 3, 2022
9bd282e
fix(review): allow rr creation by users of the site (#556)
seaerchin Nov 7, 2022
46bd344
Create vapt.yml
alexanderleegs Oct 26, 2022
579ecde
feat(ut): generic notifs (#565)
seaerchin Nov 7, 2022
fa65f44
fix(notificationonedithandler): add check for email user
seaerchin Nov 7, 2022
dd59ef8
fix(mutex-utils): remove mutex for vapt
seaerchin Nov 7, 2022
0325e2e
fix(review.ts): update routes access control (#589)
seaerchin Dec 15, 2022
f93c057
fix: prevent caching of backend API resp (#616)
prestonlimlianjie Jan 19, 2023
b0f4a49
fix: sanitize file content (#591)
prestonlimlianjie Jan 30, 2023
c4e3e4c
fix: hide contactNumber (#584)
prestonlimlianjie Jan 30, 2023
bd95543
chore(env vars): exclude .env.* in git commits
kishore03109 Feb 17, 2023
4bdf9b2
Fix: query for site through repo (#630)
alexanderleegs Feb 22, 2023
ce41bab
Fix/make login response indistinguishable (#624)
alexanderleegs Feb 22, 2023
94a9daf
feat: Added virus scan functionality for file upload (VAPT finding) (…
QiluXie Feb 24, 2023
7578a8e
Feat/swap jwt to session (#619)
alexanderleegs Feb 24, 2023
645f73f
Feat/otp mechanism (#636)
harishv7 Feb 24, 2023
2b23c45
Feat/throttling (#641)
alexanderleegs Mar 1, 2023
938d866
feat: add gitguardian hook and update readme (#642)
harishv7 Mar 2, 2023
24fe7b7
fix: wrong constant name used in test (#645)
harishv7 Mar 6, 2023
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
11 changes: 10 additions & 1 deletion .env-example
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
export CLIENT_ID=""
export CLIENT_SECRET=""
export REDIRECT_URI="http://localhost:8081/auth"
export REDIRECT_URI="http://localhost:8081/v1/auth"
export NODE_ENV="LOCAL_DEV"
export COOKIE_DOMAIN="localhost"
export AUTH_TOKEN_EXPIRY_DURATION_IN_MILLISECONDS=3600000
export SESSION_SECRET=mysessionsecretblah
export JWT_SECRET=mysecretblah
export ENCRYPTION_SECRET=anothersecretblah
export FRONTEND_URL='http://localhost:8081'
export GITHUB_ORG_NAME="isomerpages"
export GITHUB_BUILD_ORG_NAME="opengovsg"
export GITHUB_BUILD_REPO_NAME="isomer-build"
export MUTEX_TABLE_NAME=""
export MAX_NUM_OTP_ATTEMPTS=5
export OTP_EXPIRY=900000

# GitHub access token to create repo
export SYSTEM_GITHUB_TOKEN=""
Expand Down Expand Up @@ -50,3 +53,9 @@ AWS_REGION="ap-southeast-1"
export DD_ENV="local"
export DD_SERVICE="isomer"
export DD_TAGS="service:isomer"

# Cloudmersive
export CLOUDMERSIVE_API_KEY=""

# GitGuardian
export GITGUARDIAN_API_KEY=""
2 changes: 2 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export GITHUB_ORG_NAME="isomerpages"
export GITHUB_BUILD_ORG_NAME="opengovsg"
export GITHUB_BUILD_REPO_NAME="isomer-build"
export ISOMERPAGES_REPO_PAGE_COUNT=3
export MAX_NUM_OTP_ATTEMPTS=5
export OTP_EXPIRY=900000

# Database
export DB_URI="postgres://isomer:password@localhost:54321/isomercms_test"
Expand Down
165 changes: 165 additions & 0 deletions .github/workflows/vapt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
name: vapt

on:
push:
pull_request:
types: [opened, reopened]

env:
VAPT_BRANCH: refs/heads/vapt
EB_APP: cms-backend-vapt-application-alb
EB_ENV_VAPT: cms-backend-vapt-application-alb
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}

jobs:
install:
# NOTE: Netlify uses ubuntu 16.08 but Github Actions does not offer it by default.
# Hence, we default to the latest version.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: "14.x"
- name: Cache Node.js modules
uses: actions/cache@v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- run: npm ci

lint:
needs: install
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: "14.x"
- name: Load Node.js modules
uses: actions/cache@v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
- run: npm ci
- run: npm run lint-fix
- run: npm run format-fix

test:
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: "14.x"
- name: Load Node.js modules
uses: actions/cache@v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
- run: npm ci
- run: npm run dev:services
- run: . .env.test && npx jest
- run: docker compose down

gatekeep:
name: Determine if Build & Deploy is needed
outputs:
proceed: ${{ steps.determine_proceed.outputs.proceed }}
runs-on: ubuntu-18.04
if: github.event_name == 'push'
steps:
- shell: python
id: determine_proceed
run: |
import os
ref = os.environ['GITHUB_REF']
vapt = os.environ['VAPT_BRANCH']
if ref == vapt:
print('::set-output name=proceed::true')
else:
print('::set-output name=proceed::false')

deploy:
name: Build and deploy to EB
runs-on: ubuntu-18.04
needs: [gatekeep]
if: needs.gatekeep.outputs.proceed == 'true'
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: Cache Node.js modules
uses: actions/cache@v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Inject DataDog API key
env:
DD_API_KEY: ${{ secrets.DD_API_KEY }}
run: sed -i -e "s#@DD_API_KEY#$DD_API_KEY#g" .ebextensions/99datadog.config
- name: Install NPM
run: npm ci
- name: Build application
run: npm run build
- name: Zip application
run: zip -r "deploy.zip" * .platform .ebextensions -x .env-example .gitignore package-lock.json
- name: Get timestamp
shell: bash
run: echo "##[set-output name=timestamp;]$(env TZ=Asia/Singapore date '+%Y%m%d%H%M%S')"
id: get_timestamp
- name: Get Elastic Beanstalk label
shell: bash
run: echo "##[set-output name=label;]$(echo github-${GITHUB_SHA}-${TIMESTAMP})"
id: get_label
env:
TIMESTAMP: ${{ steps.get_timestamp.outputs.timestamp }}
- name: Get truncated version_description
id: get_desc
shell: python
run: |
import os
commit_message = os.environ['COMMIT_MESSAGE']
description = commit_message[0:100].replace('(', '').replace(')', '').replace('\'', '')
print('::set-output name=desc::' + description)
- name: Select Elastic Beanstalk variables
shell: python
run: |
import os
branch = os.environ['GITHUB_REF']
vapt = os.environ['VAPT_BRANCH']
eb_app = os.environ['EB_APP']
eb_env_vapt = os.environ['EB_ENV_VAPT']
if branch == vapt:
print('::set-output name=eb_app::' + eb_app)
print('::set-output name=eb_env::' + eb_env_vapt)
id: select_eb_vars
- name: Deploy to EB
uses: opengovsg/beanstalk-deploy@v11
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID_FOR_CICD }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY_FOR_CICD }}
application_name: ${{ steps.select_eb_vars.outputs.eb_app }}
environment_name: ${{ steps.select_eb_vars.outputs.eb_env }}
version_description: ${{ steps.get_desc.output.desc }}
version_label: ${{ steps.get_label.outputs.label }}
region: ap-southeast-1
deployment_package: deploy.zip
wait_for_deployment: true
wait_for_environment_recovery: true
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ node_modules/
build/
*.pem
.env*
.env.*
.idea/
.DS_Store
.DS_Store
.cache_ggshield
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
source .env && ggshield secret scan pre-commit
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
## Setup

1. Ensure pre-commit hooks are setup for safe commits. See below section on "Setting up Git Guardian"
2. Ensure node 14 is installed. Install and use nvm to manage multiple node versions.
3. Run `npm i` to install required packages
4. Ensure [Docker](https://www.docker.com/products/docker-desktop/) is installed
5. Run `npm run dev:services` to bring up the docker containers
6. Run `npm run dev` to start the server

## Setting Up Git Guardian

1. Install GitGuardian

```
brew install gitguardian/tap/ggshield
```

2. Add the API Key to your `.env` file

```
# Service API key from GitGuardian account
export GITGUARDIAN_API_KEY=abc123
```

Notes:

Only if necessary,

- To skip all pre-commit hooks, use `$ git commit -m "commit message" -n`
- To skip only GitGuardian’s hook, use `$ SKIP=ggshield git commit -m "commit message"`

## E2E Tests

To run the E2E tests successfully, you will need to define the following environment variables:
Expand Down
Loading