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

Feature/milestone 6 #20

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions .github/workflows/azure-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Deploy azure functions

on:
push:
branches:
- main
- feature/milestone-6

jobs:
deploy-dev:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Az CLI
run: curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
- name: Install Serverless Framework
run: npm install -g serverless
- name: Create env file
run: | # cp sample.env.yml env.yml
cat > env.yml << EOF
${{ secrets.ENV }}
EOF
- name: Install NPM dependencies
run: yarn install --frozen-lockfile && SLS_DEBUG=*
- name: Generate prisma
run: yarn gen
- name: Deploy zip to azure
run: |
export AZURE_SUBSCRIPTION_ID=${{secrets.AZURE_SUBSCRIPTION_ID}}
export AZURE_TENANT_ID=${{secrets.AZURE_TENANT_ID}}
export AZURE_CLIENT_ID=${{secrets.AZURE_CLIENT_ID}}
export AZURE_CLIENT_SECRET=${{secrets.AZURE_CLIENT_SECRET}}
yarn run azure
1 change: 1 addition & 0 deletions .github/workflows/lambda-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- feature/milestone-6

jobs:
deploy-dev:
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/manual-azure-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Manually deploy azure function dispatch

on:
workflow_dispatch:
inputs:
environment:
description: 'Define env name'
required: false
default: 'prod'

jobs:
deploy:
name: manual deploy
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout@v1
with:
ref: ${{ github.ref }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Az CLI
run: curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
- name: Install Serverless Framework
run: npm install -g serverless
- name: Create env file
run: | # cp sample.env.yml env.yml
cat > env.yml << EOF
${{ secrets.ENV_AZURE }}
EOF
- name: Install NPM dependencies
run: yarn install --frozen-lockfile && SLS_DEBUG=*
- name: Generate prisma
run: yarn gen
- name: Deploy zip to azure
run: |
export AZURE_SUBSCRIPTION_ID=${{secrets.AZURE_SUBSCRIPTION_ID}}
export AZURE_TENANT_ID=${{secrets.AZURE_TENANT_ID}}
export AZURE_CLIENT_ID=${{secrets.AZURE_CLIENT_ID}}
export AZURE_CLIENT_SECRET=${{secrets.AZURE_CLIENT_SECRET}}
yarn run azure
4 changes: 0 additions & 4 deletions .github/workflows/manual-lambda-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ jobs:
cat > env.yml << EOF
${{ secrets.ENV }}
EOF
- name: Install NPM dependencies
run: yarn install --frozen-lockfile && SLS_DEBUG=*
- name: Test coverage
run: yarn test
- name: Generate prisma
run: yarn gen
- name: Deploy Lambda functions
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Pull request checker

on:
pull_request:
branches: [main, dev]
branches: [master]

jobs:
checker:
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/test-ci-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: run integration testing

on:
pull_request:
branches: [main, dev]

jobs:
integration-test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
services:
postgres:
image: postgres:12-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 1234567890
POSTGRES_DB: serverless_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: yarn install --frozen-lockfile
- name: Unit testing
run: yarn test
- name: Integration testing
run: |
yarn prisma db push
yarn test:integration
env:
DATABASE_URL: postgresql://postgres:1234567890@localhost:5432/serverless_test
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@

lib-cov
azure-config.json
azure-config-deploy.json
local.settings.json
.middleware
env.yml
env.test.yml
env.local.yml
env.prod.yml
envprod.yml
.serverless
*.seed
*.log
Expand Down Expand Up @@ -43,4 +50,5 @@ dist/**/*

# ignore yarn.lock
yarn.lock
.build
.build
.webpack
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"cSpell.words": [
"api-secret",
"JWKS"
"JWKS",
"SENDGRID",
"venv"
]
}
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,36 @@ Following are the technologies used to build this project. Few of them will get
- TypeScript
- AWS Lambda
- Azure
- Native Postgres Database
- Azure BloB
- Heroku Databases
- Postgres
- Prisma
- AWS S3
- auth0
- JWT
- Amazon S3
- Prisma
- PostgresQL
- Send Gird


## Architecture
This project is using a hexagonal architecture which will have database and network interfaces.
The core logic is isolated with the interfaces.
Version-one architecture workflow diagram is as follow
![Serverless Azure and AWS](https://user-images.githubusercontent.com/24205953/136236029-0a608b1b-dbc1-4f4c-b6f0-39d174d8eaae.png)
<!-- ![Serverless Azure and AWS](https://user-images.githubusercontent.com/24205953/136236029-0a608b1b-dbc1-4f4c-b6f0-39d174d8eaae.png) -->
![Serverless Azure and AWS](documentation/images/serverlessWithLambdaAndAzure.png)

## Database Diagram
*This will be added sooner once the database setup has been done*
![Database Design](documentation/images/databaseDesign.png)

```
Enum statusEnum {
new
inProgress
done
rejected
}
```



## Security
To ensure security for the application, we have used auth0 service and apparently with JWT. Following will be process of the authentication
Expand Down
48 changes: 48 additions & 0 deletions api/azure/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"use strict";

import { decode } from "jsonwebtoken";

import response from "../../util/response";
import {
getSigningKey,
getToken,
verifyJwt,
verifyToken,
} from "../../lib/authentication";
import logger from "../../logger";
import { createUnAuthorizedError } from "../../lib/breakers";

const { TOKEN_ISSUER, AUDIENCE } = process.env;

export const auth0 = async (context, event) => {
return new Promise(async (resolve, reject) => {
try {
const token = getToken(event, 'authorization');
const verifiedData = await verifyToken(
token,
decode,
getSigningKey,
verifyJwt,
TOKEN_ISSUER,
AUDIENCE
);
const authResponse = {
principalId: verifiedData.sub,
policyDocument: {
Version: "2012-10-17",
Statement: [
{
Action: "execute-api:Invoke",
Effect: "Allow",
Resource: event.methodArn,
},
],
},
};
resolve(authResponse);
} catch (error) {
logger.error(error);
reject(createUnAuthorizedError());
}
});
};
Loading