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: Credential Service #217

Merged
merged 67 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
1f2d16c
Feat: Add credentials-service
techsavvyash Apr 18, 2023
3169c3a
Cleanup: Remove dist folder
techsavvyash Apr 18, 2023
9cda756
Cleanup: Remove unnecessary folders
techsavvyash Apr 18, 2023
32c18e0
fix: resolve comments on table naming
techsavvyash Jun 15, 2023
e45799f
fix: update schema.mongo
techsavvyash Jun 15, 2023
9cae2c0
fix: remove comments
techsavvyash Jun 19, 2023
f19713a
fix: clean up comments
techsavvyash Jun 19, 2023
98d0a17
fix: embedded url in QRCode, add proof in search
techsavvyash Jun 19, 2023
aafc2fe
refactor
techsavvyash Jun 19, 2023
a4b7b86
fix
techsavvyash Jun 20, 2023
2809468
feat: allow for adding issuance date on the fly
techsavvyash Jun 20, 2023
71bd3c1
fix: remove migration sqls
techsavvyash Jun 20, 2023
acbdf08
feat: paginate bulk search APIs
techsavvyash Jun 20, 2023
cbe3e9a
fix: search APIs returning 404 at the end of pages
techsavvyash Jun 20, 2023
2831f8a
feat: Add targets for credentials service
tushar5526 Jun 20, 2023
6b9f7b2
feat: Add containerized tests
tushar5526 Jun 20, 2023
02f9f3a
feat: Update Makefile for tests
tushar5526 Jun 20, 2023
97681c9
Merge pull request #2 from tushar5526/credential
techsavvyash Jun 21, 2023
294dfc1
feat: club `/render` in GET `/{id}` based on headers
techsavvyash Jun 22, 2023
b566def
Merge branch 'credential' of https://github.com/techsavvyash/sunbird-…
techsavvyash Jun 22, 2023
d22dabc
feat: Fix Dockerfile and run prisma migrations automaticly
tushar5526 Jun 24, 2023
a8f5ebe
feat: fix dockerfile and test wkhtmltopdf
tushar5526 Jun 27, 2023
01fdf23
feat: Run tests through docker-compose
tushar5526 Jun 27, 2023
80b2521
fix: tag image on release
tushar5526 Jun 27, 2023
8d44c9c
fix: don't build test image
tushar5526 Jun 27, 2023
93b1efd
fix: Remove any stopped test containers before starting tests
tushar5526 Jun 27, 2023
b27793a
fix: Update readme to runt tests
tushar5526 Jun 27, 2023
3770f94
Merge pull request #3 from tushar5526/cred-dockerfile
techsavvyash Jun 27, 2023
ac94cac
Update Dockerfile.test
tushar5526 Jun 28, 2023
52970f4
Update docker-compose.yml
tushar5526 Jun 28, 2023
7e486dc
Merge pull request #6 from tushar5526/tushar5526-patch-1
techsavvyash Jun 28, 2023
c683c48
fix e2e tests
varadeth Jul 5, 2023
eb9da05
add other build commands and remove echo for test to fail
varadeth Jul 5, 2023
01d543e
Merge pull request #236 from varadeth/fix_build_issue_and_e2e_tests
srprasanna Jul 5, 2023
7f855f8
Merge branch 'main' into credential
tushar5526 Jul 6, 2023
74971a4
feat: convert utils to nest service
tushar5526 Jul 6, 2023
b3a1506
fix: Add mock services
tushar5526 Jul 6, 2023
fecee70
Merge pull request #11 from techsavvyash/mock-refactoring
tushar5526 Jul 6, 2023
0891b82
Merge branch 'release-2.0.0' into credential
tushar5526 Jul 6, 2023
f6861f8
fix: Fix indentation in Makefile
tushar5526 Jul 6, 2023
699022c
feat: Setup identity, cred-schema for testing credentials-ms
tushar5526 Jul 6, 2023
3852b80
feat add health check endpoint
techsavvyash Jul 7, 2023
420ded9
Merge branch 'credential' of https://github.com/techsavvyash/sunbird-…
techsavvyash Jul 7, 2023
efb4ac5
fix: Stop services after test
tushar5526 Jul 7, 2023
bfb0c99
Merge pull request #12 from techsavvyash/tests-refactor
tushar5526 Jul 7, 2023
dda2f79
feat: Switch from mock services to actual services and add healthcheck
tushar5526 Jul 7, 2023
1c53321
Merge pull request #13 from techsavvyash/health-check
tushar5526 Jul 7, 2023
df5462d
fix: Fix paths for credential schema
tushar5526 Jul 7, 2023
b5abd34
fix: Change port to 3000
tushar5526 Jul 7, 2023
1e5942d
Update package.json
tushar5526 Jul 7, 2023
9f5ea04
fix: undo rebase changes
tushar5526 Jul 10, 2023
36ddf96
fix: resolve rebase changes
tushar5526 Jul 10, 2023
de2d294
fix: remove commented code
tushar5526 Jul 10, 2023
32954b4
fix: remove comments
tushar5526 Jul 10, 2023
13a35cc
fixes
techsavvyash Jul 10, 2023
05722ed
Merge branch 'credential' of https://github.com/techsavvyash/sunbird-…
techsavvyash Jul 10, 2023
3a964c0
Merge branch 'release-2.0.0' into credential
tushar5526 Jul 11, 2023
bc1f252
feat: add schema version and cleanups
tushar5526 Jul 11, 2023
eee297b
fix: add tests and fix docker compose
tushar5526 Jul 11, 2023
eb68247
feat: refactor code and add logging
tushar5526 Jul 11, 2023
45add62
feat: update makefiles for tests
tushar5526 Jul 11, 2023
f7cda8b
feat: add docker compose to docker network
tushar5526 Jul 11, 2023
ef36e74
feat: Show code coverage after test runs
tushar5526 Jul 11, 2023
9fe42d0
fix: add more tests for coverage
tushar5526 Jul 17, 2023
c5bace5
fix: unset temporary vault token
tushar5526 Jul 18, 2023
95ae687
fix: Fix String test
tushar5526 Jul 18, 2023
e2cc9a0
feat: fix wkhtmltopdf version
tushar5526 Jul 18, 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
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
**/node_modules
**/build
**/build
**/dist
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ IMAGES := dockerhub/sunbird-rc-core dockerhub/sunbird-rc-nginx dockerhub/sunbird
dockerhub/sunbird-rc-public-key-service dockerhub/sunbird-rc-keycloak dockerhub/sunbird-rc-certificate-api \
dockerhub/sunbird-rc-certificate-signer dockerhub/sunbird-rc-notification-service dockerhub/sunbird-rc-claim-ms \
dockerhub/sunbird-rc-digilocker-certificate-api dockerhub/sunbird-rc-bulk-issuance dockerhub/sunbird-rc-metrics \
dockerhub/sunbird-rc-credential-schema dockerhub/sunbird-rc-identity-service

dockerhub/sunbird-rc-identity-service dockerhub/sunbird-rc-credential-schema dockerhub/sunbird-rc-credentials-service
build: java/registry/target/registry.jar
echo ${SOURCES}
rm -rf java/claim/target/*.jar
Expand All @@ -23,8 +23,9 @@ build: java/registry/target/registry.jar
make -C services/digilocker-certificate-api docker
make -C services/bulk_issuance docker
docker build -t dockerhub/sunbird-rc-nginx .
make -C services/identity-service/ docker
make -C services/credential-schema docker
make -C services/identity-service docker
make -C services/credentials-service/ docker


java/registry/target/registry.jar: $(SOURCES)
Expand Down Expand Up @@ -71,13 +72,15 @@ test: build
make -C services/certificate-signer test
make -C services/public-key-service test
make -C services/context-proxy-service test
make -C services/credential-schema test
make -C services/bulk_issuance test
make -C services/identity-service test
make -C services/credential-schema test
make -C services/credentials-service test

clean:
@rm -rf target || true
@rm java/registry/target/registry.jar || true

release: test
for image in $(IMAGES); \
do \
Expand Down
7 changes: 6 additions & 1 deletion services/credential-schema/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ test:
@docker-compose -f docker-compose-test.yml down
@docker-compose -f docker-compose-test.yml up --build --abort-on-container-exit
make -C ../identity-service stop
make -C ../identity-service vault-reset
make -C ../identity-service vault-reset

compose-init:
@docker-compose up -d --build
stop:
@docker-compose stop
2 changes: 1 addition & 1 deletion services/credential-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"start:migrate:prod": "npx prisma migrate deploy && node dist/src/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest --coverage && jest --config ./test/jest-e2e.json",
"test:migrate": "npx prisma migrate deploy && jest --coverage",
"test:migrate": "npx prisma migrate deploy && jest --coverage && jest --config ./test/jest-e2e.json",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
Expand Down
14 changes: 14 additions & 0 deletions services/credentials-service/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
DATABASE_URL=""
SCHEMA_BASE_URL=""

# Auth related vars
JWKS_URI=""
ENABLE_AUTH=false

# Core Service Vars
IDENTITY_BASE_URL= # URL of the identity service to facilitate DID creation

# Service VARS
SCHEMA_BASE_URL=

CREDENTIAL_SERVICE_BASE_URL=""
3 changes: 3 additions & 0 deletions services/credentials-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
node_modules
dist
3 changes: 3 additions & 0 deletions services/credentials-service/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
26 changes: 26 additions & 0 deletions services/credentials-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM node:16 AS install
RUN apt-get update \
&& apt-get install -y wkhtmltopdf
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn

FROM node:16 as build
WORKDIR /app
COPY prisma ./prisma/
COPY --from=install /app/node_modules ./node_modules
RUN npx prisma generate
COPY . .
RUN yarn build

FROM node:16
RUN apt-get update \
&& apt-get install -y wkhtmltopdf=0.12.5-1

WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=build /app/package*.json ./
COPY --from=build /app/prisma ./prisma
COPY --from=build /app/node_modules ./node_modules
EXPOSE 3000
CMD [ "npm", "run", "start:migrate:prod" ]
16 changes: 16 additions & 0 deletions services/credentials-service/Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:16 AS install
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn

FROM node:16 as build
RUN apt-get update \
&& apt-get install -y wkhtmltopdf=0.12.5-1
WORKDIR /app
COPY prisma ./prisma/
COPY --from=install /app/node_modules ./node_modules
RUN npx prisma generate
COPY . .
EXPOSE 3333
CMD [ "yarn", "test:migrate"]

25 changes: 25 additions & 0 deletions services/credentials-service/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
IMAGE:=dockerhub/sunbird-rc-credentials-service

.PHONY: docker publish test

docker:
@docker build -t $(IMAGE) .
publish:
@docker push $(IMAGE)
test:
# Resetting vault of identity-service before running the tests
make -C ../identity-service stop
make -C ../credential-schema stop
make -C ../identity-service vault-reset
# Creating an external docker network to connnect services in different compose
@docker network create rcw-test || echo ""
# Starting dependent services
make -C ../identity-service compose-init
make -C ../credential-schema compose-init
@docker-compose -f docker-compose-test.yml down
@docker-compose -f docker-compose-test.yml up --build --abort-on-container-exit

# Stopping all dependent services
make -C ../identity-service stop
make -C ../identity-service vault-reset
make -C ../credential-schema stop
89 changes: 89 additions & 0 deletions services/credentials-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Credential Microservice

## Description

[Nest](https://github.com/nestjs/nest) based CRUD APIs to, claim, sign and generate shareable verifiable credentials. This repository is intended to be used with the [Unified Learner's Passbook](http://github.com/Unified-Learners-Passbook) project in the state of Uttar Pradesh, India.

## Installation

```bash
$ npm install
```
OR
```bash
$ npx yarn
```

## Running the app

```bash
# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod
```

OR

```bash
# development
$ npx yarn run start

# watch mode
$ npx yarn run start:dev

# production mode
$ npx yarn run start:prod
```


## Test

```bash
# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov
```

OR

```bash
# unit tests
$ npx yarn run test

# e2e tests
$ npx yarn run test:e2e

# test coverage
$ npx yarn run test:cov
```

OR

```
# Run tests in container from services/credential-service folder
$ make test

# Run tests in container from base folder
$ make -C services/credentials-service test
```
## Stay in touch

- Author - [Yash Mittal](https://github.com/techsavvyash) and [Radhay Anand](https://github.com/radhay-1199)

## License

Nest is [MIT licensed](LICENSE).

## Links

- [W3C VC API](https://w3c-ccg.github.io/vc-api/)
3 changes: 3 additions & 0 deletions services/credentials-service/benchmark/*.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wrk.method = "POST"
wrk.body = "{\n \"credential\": {\n \"@context\": [\n \"https://www.w3.org/2018/credentials/v1\",\n \"https://www.w3.org/2018/credentials/examples/v1\"\n ],\n \"type\": [\n \"VerifiableCredential\",\n \"UniversityDegreeCredential\"\n ],\n \"issuer\": \"did:ulp:2010a34d-4292-4c1c-83ae-e7559a90931c\",\n \"issuanceDate\": \"2023-02-06T11:56:27.259Z\",\n \"expirationDate\": \"2023-02-08T11:56:27.259Z\",\n \"credentialSubject\": {\n \"id\": \"did:ulp:977ba77a-a549-4f3f-8d8c-eef01fe616a2\",\n \"grade\": \"6.23\",\n \"programme\": \"BCA\",\n \"certifyingInstitute\": \"IIIT Sonepat\",\n \"evaluatingInstitute\": \"NIT Kurukshetra\"\n },\n \"options\": {\n \"created\": \"2020-04-02T18:48:36Z\",\n \"credentialStatus\": {\n \"type\": \"RevocationList2020Status\"\n }\n }\n },\n \"credentialSchema\": {\n \"id\": \"did:ulpschema:c9cc0f03-4f94-4f44-9bcd-b24a86596fa2\",\n \"type\": \"https://w3c-ccg.github.io/vc-json-schemas/\",\n \"version\": \"1.0\",\n \"name\": \"Proof of Academic Evaluation Credential\",\n \"author\": \"did:example:c276e12ec21ebfeb1f712ebc6f1\",\n \"authored\": \"2022-12-19T09:22:23.064Z\",\n \"schema\": {\n \"$id\": \"Proof-of-Academic-Evaluation-Credential-1.0\",\n \"type\": \"object\",\n \"$schema\": \"https://json-schema.org/draft/2019-09/schema\",\n \"required\": [\n \"grade\",\n \"programme\",\n \"certifyingInstitute\",\n \"evaluatingInstitute\"\n ],\n \"properties\": {\n \"grade\": {\n \"type\": \"string\",\n \"description\": \"Grade (%age, GPA, etc.) secured by the holder.\"\n },\n \"programme\": {\n \"type\": \"string\",\n \"description\": \"Name of the programme pursed by the holder.\"\n },\n \"certifyingInstitute\": {\n \"type\": \"string\",\n \"description\": \"Name of the instute which certified the said grade in the said skill\"\n },\n \"evaluatingInstitute\": {\n \"type\": \"string\",\n \"description\": \"Name of the institute which ran the programme and evaluated the holder.\"\n }\n },\n \"description\": \"The holder has secured the <PERCENTAGE/GRADE> in <PROGRAMME> from <ABC_Institute>.\",\n \"additionalProperties\": false\n }\n }\n}"
wrk.headers["Content-Type"] = "application/json"
44 changes: 44 additions & 0 deletions services/credentials-service/build/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
node() {
withCredentials([string(credentialsId: 'docker_server', variable: 'docker_server')]) {
properties([
parameters([
string(name: 'docker_repo', defaultValue: 'samagragovernance/credential-ms', description: 'Docker Image Name'),
string(name: 'docker_server', defaultValue: "$docker_server", description: 'Docker Registry URL'),
])
])
}
stage('Checkout') {
cleanWs()
checkout scm
env.commit_id = env.BRANCH_NAME
echo "${env.commit_id}"
}

stage('docker-build') {
sh '''
docker build -f Dockerfile -t $docker_server/$docker_repo:$commit_id .
'''
if (env.BRANCH_NAME == 'main' || env.BRANCH_NAME == 'master') {
sh '''
docker build -f Dockerfile -t $docker_server/$docker_repo:latest .
'''
}
}

stage('docker-push') {
sh '''
docker push $docker_server/$docker_repo:$commit_id
'''
if (env.BRANCH_NAME == 'main' || env.BRANCH_NAME == 'master') {
sh '''
docker push $docker_server/$docker_repo:latest
'''
}
}

stage('Start deploy job with latest tag') {
if (env.BRANCH_NAME == 'main' || env.BRANCH_NAME == 'master') {
build job: 'ULP/deploy-staging/credential-ms/', parameters: [string(name: 'tag', value: 'latest')]
}
}
}
35 changes: 35 additions & 0 deletions services/credentials-service/docker-compose-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3'

services:
db-test:
image: postgres:12
environment:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 10s
timeout: 5s
retries: 5
credentials-service-test:
build:
context: .
dockerfile: Dockerfile.test
depends_on:
db-test:
condition: service_healthy
environment:
DATABASE_URL: postgres://postgres:postgres@db-test:5432/postgres
IDENTITY_BASE_URL: "http://identity-service:3332"
SCHEMA_BASE_URL: "http://credential-schema:3333"
ENABLE_AUTH: "false"
JWKS_URI: ""
SIGNING_ALGORITHM: "RS256"
networks:
rcw-test:
default:

networks:
rcw-test:
external: true

46 changes: 46 additions & 0 deletions services/credentials-service/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
version: '3'

services:
db:
image: postgres:12
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
volumes:
- data:/var/lib/postgresql/data
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 10s
timeout: 5s
retries: 5
credentials-service:
image: cred
build: .
depends_on:
db:
condition: service_healthy
ports:
- '3000:3000'
environment:
DATABASE_URL: postgres://postgres:postgres@db:5432/postgres
IDENTITY_BASE_URL:
SCHEMA_BASE_URL:
ENABLE_AUTH: "false"
JWKS_URI: ""
SIGNING_ALGORITHM: "RS256"
healthcheck:
test:
[ "CMD-SHELL", "curl -f http://localhost:3000/health || exit 1" ]
interval: 10s
timeout: 5s
retries: 5
networks:
rcw-test:
default:

networks:
rcw-test:
external: true

volumes:
data:
Loading