Skip to content

Commit

Permalink
Merge pull request #217 from techsavvyash/credential
Browse files Browse the repository at this point in the history
Feat: Credential Service
  • Loading branch information
srprasanna authored Jul 25, 2023
2 parents c41f19c + e2cc9a0 commit f404659
Show file tree
Hide file tree
Showing 61 changed files with 10,018 additions and 12 deletions.
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

0 comments on commit f404659

Please sign in to comment.