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: Add Identity service #218

Merged
merged 43 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
cad6210
Feat: Add Credential, Credential Schema and Identity services from Sa…
techsavvyash Apr 17, 2023
6265de0
Feat: Add identity service
techsavvyash Apr 18, 2023
d5a8b69
Feat: add sample env
techsavvyash Apr 18, 2023
af2000b
feat: Add targets for identity-service
tushar5526 Jun 20, 2023
6ae6a53
feat: Add containerized tests
tushar5526 Jun 20, 2023
de7798b
feat: Update makefile
tushar5526 Jun 20, 2023
7cd8731
Merge pull request #1 from tushar5526/identity
techsavvyash Jun 21, 2023
6af1cd1
fix: remove `.gitmodules`, make did method dynamic
techsavvyash Jun 21, 2023
4b1abd7
feat: Fix dockerfile and add vault config
tushar5526 Jun 26, 2023
4ca48af
feat: Automate vault
tushar5526 Jun 26, 2023
5ed5da8
fix: fix makefile to tag release
tushar5526 Jun 27, 2023
472c7ca
fix: Fix setup_vault.sh
tushar5526 Jun 27, 2023
38ddc7a
fix: fixes part 1
techsavvyash Jun 27, 2023
feab152
fix: remove ulp specific jenkins file
techsavvyash Jun 27, 2023
7b08768
feat: Dockerized tests
tushar5526 Jun 27, 2023
a21b2fa
delete gitpod.yml
tushar5526 Jun 27, 2023
6bf139c
fix: remove test containers before starting tests
tushar5526 Jun 27, 2023
3d8cf31
fix: add compose-init target and readme update
tushar5526 Jun 27, 2023
bc7c9a2
fix: update env vars in compose
tushar5526 Jun 27, 2023
4f5f5a5
Merge pull request #4 from tushar5526/identity-dockerfile
techsavvyash Jun 27, 2023
d01d3ef
Update setup_vault.sh
tushar5526 Jun 27, 2023
97a2eee
Merge pull request #5 from tushar5526/patch-1
techsavvyash Jun 27, 2023
428123c
feat: add verify endpoint
techsavvyash Jun 27, 2023
193bf06
Merge branch 'identity' of github.com:techsavvyash/sunbird-rc-core in…
techsavvyash Jun 27, 2023
2de0ddf
fix and enable auth guard
techsavvyash Jun 27, 2023
a6e2e4e
fix: error handling logging and touchups
techsavvyash Jun 27, 2023
b399774
feat: tests
techsavvyash Jun 27, 2023
f1bcc31
Update setup_vault.sh
tushar5526 Jun 28, 2023
9a366f7
Merge pull request #7 from tushar5526/patch-2
techsavvyash Jun 28, 2023
b994fde
fix: Fix tests, docker-compose-test, and setup_vault.sh
tushar5526 Jun 28, 2023
3421b72
Merge pull request #8 from tushar5526/test-fix
techsavvyash Jun 28, 2023
7dd2719
feat: add health checks for DB container
tushar5526 Jun 28, 2023
b99a439
fix: make tests working
techsavvyash Jun 28, 2023
580a640
Merge pull request #9 from tushar5526/compose-fix
techsavvyash Jun 28, 2023
8e5a1b3
update tests
techsavvyash Jun 28, 2023
8811c86
Update .env
tejash-jl Jul 1, 2023
c9ead04
feat: add health check
techsavvyash Jul 3, 2023
31bd2fa
fix: vault health check
techsavvyash Jul 3, 2023
6195bcd
fix
techsavvyash Jul 3, 2023
884f9d1
feat: add health checks to vault and use test network for test contai…
tushar5526 Jul 3, 2023
97da68c
Merge branch 'main' into identity
tushar5526 Jul 3, 2023
ce6ac5e
fix: improvements
techsavvyash Jul 4, 2023
f2d1bfd
Merge branch 'identity' of https://github.com/techsavvyash/sunbird-rc…
techsavvyash Jul 4, 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
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule "services/Credential-MS"]
path = services/Credential-MS
url = https://github.com/Unified-Learner-Passbook/Credential-MS
[submodule "services/Cred-Schema-MS"]
path = services/Cred-Schema-MS
url = https://github.com/Unified-Learner-Passbook/Cred-Schema-MS
[submodule "services/Identity"]
path = services/Identity
url = https://github.com/Unified-Learner-Passbook/Identity
9 changes: 9 additions & 0 deletions services/identity-service/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
JWKS_URI=""
VAULT_ADDR=""
VAULT_TOKEN=""
APPLICATION_ID=""
DATABASE_URL=""
EMAIL_HOST=""
EMAIL_PASSWORD=""
EMAIL_SENDER=""
FUSION_API_KEY=""
6 changes: 6 additions & 0 deletions services/identity-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM node:16 as dependencies
WORKDIR /app
COPY . ./
RUN npm install
EXPOSE 3332
CMD ["npm", "start"]
49 changes: 49 additions & 0 deletions services/identity-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## Description

[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.

## Installation

```bash
$ npm install
```

## Running the app

```bash
# development env
$ npm run start

# watch mode
$ npm run start:dev

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

## Test

```bash
# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

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

## Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).

## Stay in touch

- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)

## License

Nest is [MIT licensed](LICENSE).
45 changes: 45 additions & 0 deletions services/identity-service/build/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
node() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be present within the repo. I think this can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the jenkins file we created to deploy the service to the internal samagra devops pipelines. Do we need to remove this entirely so can we keep this as alternate deployment strategy ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the file has been resolved as per discussion during the standup

withCredentials([string(credentialsId: 'docker_server', variable: 'docker_server')]) {
properties([
parameters([
string(name: 'docker_repo', defaultValue: 'samagragovernance/did-l3', 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/identity/', parameters: [string(name: 'tag', value: 'latest')]
}
}
}
5 changes: 5 additions & 0 deletions services/identity-service/nest-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
92 changes: 92 additions & 0 deletions services/identity-service/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"name": "did-l3-ms",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add appropriate license.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added MIT License

"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"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",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@decentralized-identity/did-common-typescript": "^0.1.19",
"@decentralized-identity/ion-sdk": "^0.6.0",
"@decentralized-identity/ion-tools": "^0.1.1",
"@nestjs-modules/mailer": "^1.8.1",
"@nestjs/axios": "^1.0.0",
"@nestjs/common": "^9.0.0",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^9.0.0",
"@nestjs/jwt": "^9.0.0",
"@nestjs/passport": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"@nestjs/swagger": "^6.1.4",
"@prisma/client": "4.7.1",
"crypto": "^1.0.1",
"did-resolver": "^4.0.1",
"encrypt-rsa": "^2.1.2",
"hashi-vault-js": "^0.4.12",
"jwks-rsa": "^3.0.0",
"nodemailer": "^6.8.0",
"passport": "^0.6.0",
"passport-http": "^0.3.0",
"passport-jwt": "^4.0.0",
"prisma": "^4.7.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.2.0",
"uuidv4": "^6.2.13"
},
"devDependencies": {
"@nestjs/cli": "^9.0.0",
"@nestjs/schematics": "^9.0.0",
"@nestjs/testing": "^9.0.0",
"@types/express": "^4.17.13",
"@types/jest": "28.1.8",
"@types/node": "^16.0.0",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "28.1.3",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "28.0.8",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "4.1.0",
"typescript": "^4.7.4"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- CreateTable
CREATE TABLE "Identity" (
"did" TEXT NOT NULL,
"privateKey" TEXT NOT NULL,

CONSTRAINT "Identity_pkey" PRIMARY KEY ("did")
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:

- Added the required column `didDoc` to the `Identity` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "Identity" ADD COLUMN "didDoc" JSONB NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
Warnings:

- The primary key for the `Identity` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `did` on the `Identity` table. All the data in the column will be lost.
- Added the required column `id` to the `Identity` table without a default value. This is not possible if the table is not empty.

*/
-- AlterTable
ALTER TABLE "Identity" DROP CONSTRAINT "Identity_pkey",
DROP COLUMN "did",
ADD COLUMN "id" TEXT NOT NULL,
ADD CONSTRAINT "Identity_pkey" PRIMARY KEY ("id");
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
Warnings:

- Changed the type of `privateKey` on the `Identity` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required.

*/
-- AlterTable
ALTER TABLE "Identity" DROP COLUMN "privateKey",
ADD COLUMN "privateKey" JSONB NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Identity" ADD COLUMN "blockchainStatus" BOOLEAN NOT NULL DEFAULT false;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:

- You are about to drop the column `privateKey` on the `Identity` table. All the data in the column will be lost.

*/
-- AlterTable
ALTER TABLE "Identity" DROP COLUMN "privateKey";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
18 changes: 18 additions & 0 deletions services/identity-service/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
}

model Identity {
id String @id
didDoc Json
blockchainStatus Boolean @default(false)
}
22 changes: 22 additions & 0 deletions services/identity-service/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';

describe('AppController', () => {
let appController: AppController;

beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();

appController = app.get<AppController>(AppController);
});

describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});
7 changes: 7 additions & 0 deletions services/identity-service/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Controller, Get, Post } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
}
27 changes: 27 additions & 0 deletions services/identity-service/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { PrismaService } from './prisma.service';
import { DidService } from './did/did.service';
import { DidController } from './did/did.controller';
import { DidModule } from './did/did.module';
import { HttpModule } from '@nestjs/axios';
import { KycModule } from './kyc/kyc.module';
import { ConfigModule } from '@nestjs/config';
import { VcModule } from './vc/vc.module';
import { VaultService } from './did/vault.service';

@Module({
imports: [
DidModule,
KycModule,
VcModule,
HttpModule,
ConfigModule.forRoot({
isGlobal: true,
}),
],
controllers: [AppController, DidController],
providers: [AppService, PrismaService, DidService, VaultService],
})
export class AppModule {}
8 changes: 8 additions & 0 deletions services/identity-service/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
}
22 changes: 22 additions & 0 deletions services/identity-service/src/did/auth-basic.strategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { BasicStrategy as Strategy } from 'passport-http';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';

@Injectable()
export class BasicStrategy extends PassportStrategy(Strategy) {
constructor() {
super({
passReqToCallback: true,
});
}

public validate = async (req, username, password): Promise<boolean> => {
if (
process.env.HTTP_BASIC_USER === username &&
process.env.HTTP_BASIC_PASS === password
) {
return true;
}
throw new UnauthorizedException();
};
}
Loading