Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:Bhutan-NDI/ngotag-platform into …
Browse files Browse the repository at this point in the history
…pipeline-implementation
  • Loading branch information
Sheetal-ayanworks committed Apr 25, 2024
2 parents b3362c0 + 14507b3 commit dfd9a7f
Show file tree
Hide file tree
Showing 58 changed files with 834 additions and 362 deletions.
10 changes: 2 additions & 8 deletions Dockerfiles/Dockerfile.agent-provisioning
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Stage 1: Build the application
FROM node:18-alpine as build


RUN set -eux \
&& apk --no-cache add \
openssh-client \
Expand All @@ -11,14 +12,6 @@ RUN set -eux \
&& export PATH=$PATH:/usr/lib/node_modules/pnpm/bin \
&& rm -rf /var/cache/apk/*

RUN docker --version && \
docker-compose --version

ARG ROOT_PATH
ENV ROOT_PATH ${ROOT_PATH}

RUN echo "ROOT_PATH is set to: $ROOT_PATH"

# Set the working directory
WORKDIR /app

Expand All @@ -42,6 +35,7 @@ RUN pnpm run build agent-provisioning
# Stage 2: Create the final image
FROM node:18-alpine as prod


RUN set -eux \
&& apk --no-cache add \
openssh-client \
Expand Down
4 changes: 0 additions & 4 deletions Dockerfiles/Dockerfile.agent-service
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,3 @@ COPY --from=build /app/node_modules ./node_modules

# Set the command to run the microservice
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && cd ../.. && node dist/apps/agent-service/main.js"]

# docker build -t agent-service -f Dockerfiles/Dockerfile.agent-service .
# docker run -d --env-file .env --name agent-service docker.io/library/agent-service
# docker logs -f agent-service
2 changes: 1 addition & 1 deletion Dockerfiles/Dockerfile.api-gateway
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ COPY --from=build /app/node_modules ./node_modules
# COPY --from=build /app/uploadedFiles ./uploadedFiles

# Set the command to run the microservice
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && npx prisma generate && cd ../.. && node dist/apps/api-gateway/main.js"]
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && cd ../.. && node dist/apps/api-gateway/main.js"]
4 changes: 0 additions & 4 deletions Dockerfiles/Dockerfile.connection
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,3 @@ COPY --from=build /app/node_modules ./node_modules

# Set the command to run the microservice
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && cd ../.. && node dist/apps/connection/main.js"]

# docker build -t connection -f Dockerfiles/Dockerfile.connection .
# docker run -d --env-file .env --name connection docker.io/library/connection
# docker logs -f connection
4 changes: 0 additions & 4 deletions Dockerfiles/Dockerfile.ecosystem
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,3 @@ COPY --from=build /app/node_modules ./node_modules

# Set the command to run the microservice
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && cd ../.. && node dist/apps/ecosystem/main.js"]

# docker build -t ecosystem -f Dockerfiles/Dockerfile.ecosystem .
# docker run -d --env-file .env --name ecosystem docker.io/library/ecosystem
# docker logs -f ecosystem
4 changes: 0 additions & 4 deletions Dockerfiles/Dockerfile.issuance
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,3 @@ COPY --from=build /app/node_modules ./node_modules

# Set the command to run the microservice
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && cd ../.. && node dist/apps/issuance/main.js"]

# docker build -t issuance -f Dockerfiles/Dockerfile.issuance .
# docker run -d --env-file .env --name issuance docker.io/library/issuance
# docker logs -f issuance
4 changes: 0 additions & 4 deletions Dockerfiles/Dockerfile.ledger
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,3 @@ COPY --from=build /app/node_modules ./node_modules

# Set the command to run the microservice
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && cd ../.. && node dist/apps/ledger/main.js"]

# docker build -t ledger -f Dockerfiles/Dockerfile.ledger .
# docker run -d --env-file .env --name ledger docker.io/library/ledger
# docker logs -f ledger
4 changes: 0 additions & 4 deletions Dockerfiles/Dockerfile.notification
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,3 @@ COPY --from=build /app/node_modules ./node_modules

# Set the command to run the microservice
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && cd ../.. && node dist/apps/notification/main.js"]

# docker build -t notification -f Dockerfiles/Dockerfile.notification .
# docker run -d --env-file .env --name notification docker.io/library/notification
# docker logs -f notification
4 changes: 0 additions & 4 deletions Dockerfiles/Dockerfile.organization
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,3 @@ COPY --from=build /app/node_modules ./node_modules

# Set the command to run the microservice
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && cd ../.. && node dist/apps/organization/main.js"]

# docker build -t organization -f Dockerfiles/Dockerfile.organization .
# docker run -d --env-file .env --name issuance docker.io/library/organization
# docker logs -f organization
4 changes: 0 additions & 4 deletions Dockerfiles/Dockerfile.user
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,3 @@ COPY --from=build /app/node_modules ./node_modules

# Set the command to run the microservice
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && cd ../.. && node dist/apps/user/main.js"]

# docker build -t user -f Dockerfiles/Dockerfile.user .
# docker run -d --env-file .env --name user docker.io/library/user
# docker logs -f user
30 changes: 1 addition & 29 deletions Dockerfiles/Dockerfile.utility
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@
FROM node:18-slim as build
RUN npm install -g pnpm

# We don't need the standalone Chromium
# ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true

# Install Google Chrome Stable and fonts
# Note: this installs the necessary libs to make the browser work with Puppeteer.
# RUN apt-get update && apt-get install gnupg wget -y && \
# wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
# sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
# apt-get update && \
# apt-get install google-chrome-stable -y --no-install-recommends && \
# rm -rf /var/lib/apt/lists/*

# RUN apk update && apk list --all-versions chromium
# Set the working directory
WORKDIR /app

Expand All @@ -35,17 +22,6 @@ RUN pnpm run build utility
# Stage 2: Create the final image
FROM node:18-slim

# We don't need the standalone Chromium
# ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true

# Install Google Chrome Stable and fonts
# Note: this installs the necessary libs to make the browser work with Puppeteer.
# RUN apt-get update && apt-get install gnupg wget -y && \
# wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
# sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
# apt-get update && \
# apt-get install google-chrome-stable -y --no-install-recommends && \
# rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /app
Expand All @@ -61,8 +37,4 @@ COPY --from=build /app/node_modules ./node_modules


# Set the command to run the microservice
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && cd ../.. && node dist/apps/utility/main.js"]

# docker build -t user -f Dockerfiles/Dockerfile.user .
# docker run -d --env-file .env --name user docker.io/library/user
# docker logs -f user
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && cd ../.. && node dist/apps/utility/main.js"]
6 changes: 1 addition & 5 deletions Dockerfiles/Dockerfile.verification
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,4 @@ COPY --from=build /app/libs/ ./libs/
COPY --from=build /app/node_modules ./node_modules

# Set the command to run the microservice
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && cd ../.. && node dist/apps/verification/main.js"]

# docker build -t verification -f Dockerfiles/Dockerfile.verification .
# docker run -d --env-file .env --name verification docker.io/library/verification
# docker logs -f verification
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && cd ../.. && node dist/apps/verification/main.js"]
4 changes: 0 additions & 4 deletions Dockerfiles/Dockerfile.webhook
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,3 @@ COPY --from=build /app/node_modules ./node_modules

# Set the command to run the microservice
CMD ["sh", "-c", "cd libs/prisma-service && npx prisma migrate deploy && cd ../.. && node dist/apps/webhook/main.js"]

# docker build -t webhook -f Dockerfiles/Dockerfile.webhook .
# docker run -d --env-file .env --name webhook docker.io/library/webhook
# docker logs -f webhook
37 changes: 34 additions & 3 deletions apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,9 @@ export class AgentServiceService {
* @param payload
* @returns did and didDocument
*/
async createDid(payload: IDidCreate, orgId: string, user: IUserRequestInterface): Promise<object> {
async createDid(createDidPayload: IDidCreate, orgId: string, user: IUserRequestInterface): Promise<object> {
try {
const {isPrimaryDid} = createDidPayload;
const agentDetails = await this.agentServiceRepository.getOrgAgentDetails(orgId);

const getApiKey = await this.getOrgAgentApiKey(orgId);
Expand All @@ -848,8 +849,38 @@ export class AgentServiceService {
} else if (getOrgAgentType.agent === OrgAgentType.SHARED) {
url = `${agentDetails.agentEndPoint}${CommonConstants.URL_SHAGENT_CREATE_DID}${agentDetails.tenantId}`;
}
const didDetails = await this.commonService.httpPost(url, payload, { headers: { authorization: getApiKey } });
return didDetails;

delete createDidPayload.isPrimaryDid;

const didDetails = await this.commonService.httpPost(url, createDidPayload, { headers: { authorization: getApiKey } });

if (!didDetails) {
throw new InternalServerErrorException(ResponseMessages.agent.error.createDid, {
cause: new Error(),
description: ResponseMessages.errorMessages.serverError
});
}
const createdDidDetails = {
orgId,
did: didDetails.did,
didDocument: didDetails.didDocument,
isPrimaryDid,
orgAgentId: agentDetails.id,
userId: user.id
};
const storeDidDetails = await this.agentServiceRepository.storeDidDetails(createdDidDetails);

if (!storeDidDetails) {
throw new InternalServerErrorException(ResponseMessages.agent.error.storeDid, {
cause: new Error(),
description: ResponseMessages.errorMessages.serverError
});
}
if (isPrimaryDid && storeDidDetails.did) {
await this.agentServiceRepository.setPrimaryDid(storeDidDetails.did, orgId);
}

return storeDidDetails;
} catch (error) {
this.logger.error(`error in create did : ${JSON.stringify(error)}`);

Expand Down
13 changes: 11 additions & 2 deletions apps/agent-service/src/interface/agent-service.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface IDidCreate {
did?: string;
role?: string;
endorserDid?: string;
isPrimaryDid?: boolean;
}
export interface ITenantSchema {
tenantId?: string;
Expand Down Expand Up @@ -183,6 +184,15 @@ export interface IStoreOrgAgentDetails {
agentType?: string;
}

export interface IStoreDidDetails {
orgId: string;
isPrimaryDid?: boolean;
did: string;
didDocument?: string;
userId: string;
orgAgentId: string;
}

export interface IStoreOrgAgent {
id?: string;
clientSocketId?: string;
Expand Down Expand Up @@ -504,8 +514,7 @@ interface Ledger {
poolConfig: string;
isActive: boolean;
networkString: string;
registerDIDEndpoint: string;
registerDIDPayload: string;
nymTxnEndpoint: string;
indyNamespace: string;
networkUrl: string | null;
}
Expand Down
56 changes: 54 additions & 2 deletions apps/agent-service/src/repositories/agent-service.repository.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PrismaService } from '@credebl/prisma-service';
import { Injectable, Logger } from '@nestjs/common';
// eslint-disable-next-line camelcase
import { ledgerConfig, ledgers, org_agents, org_agents_type, organisation, platform_config, user } from '@prisma/client';
import { ICreateOrgAgent, IOrgAgent, IOrgAgentsResponse, IOrgLedgers, IStoreAgent, IStoreOrgAgentDetails } from '../interface/agent-service.interface';
import { ledgerConfig, ledgers, org_agents, org_agents_type, org_dids, organisation, platform_config, user } from '@prisma/client';
import { ICreateOrgAgent, IOrgAgent, IOrgAgentsResponse, IOrgLedgers, IStoreAgent, IStoreDidDetails, IStoreOrgAgentDetails } from '../interface/agent-service.interface';
import { AgentType } from '@credebl/enum/enum';

@Injectable()
Expand Down Expand Up @@ -155,6 +155,58 @@ export class AgentServiceRepository {
}
}

/**
* Store DID details
* @param storeDidDetails
* @returns did details
*/
// eslint-disable-next-line camelcase
async storeDidDetails(storeDidDetails: IStoreDidDetails): Promise<org_dids> {
try {
const {orgId, did, didDocument, isPrimaryDid, userId, orgAgentId} = storeDidDetails;

return this.prisma.org_dids.create({
data: {
orgId,
did,
didDocument,
isPrimaryDid,
createdBy: userId,
lastChangedBy: userId,
orgAgentId
}
});
} catch (error) {
this.logger.error(`[storeDidDetails] - Store DID details: ${JSON.stringify(error)}`);
throw error;
}
}


/**
* Set primary DID
* @param did
* @returns did details
*/
// eslint-disable-next-line camelcase
async setPrimaryDid(isPrimaryDid:string, orgId:string): Promise<org_agents> {
try {
return await this.prisma.org_agents.update({
where: {
orgId
},
data: {
orgDid: isPrimaryDid
}
});

} catch (error) {
this.logger.error(`[setprimaryDid] - Update DID details: ${JSON.stringify(error)}`);
throw error;
}
}


/**
* Get agent details
* @param orgId
Expand Down
12 changes: 6 additions & 6 deletions apps/api-gateway/src/agent-service/agent-service.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import { CustomExceptionFilter } from 'apps/api-gateway/common/exception-handler
import { Roles } from '../authz/decorators/roles.decorator';
import { OrgRoles } from 'libs/org-roles/enums';
import { OrgRolesGuard } from '../authz/guards/org-roles.guard';
import { CreateDidDto } from './dto/create-did.dto';
import { validateDid } from '@credebl/common/did.validator';
import { CreateWalletDto } from './dto/create-wallet.dto';
import { CreateNewDidDto } from './dto/create-new-did.dto';

const seedLength = 32;

Expand Down Expand Up @@ -222,17 +222,17 @@ export class AgentController {
* @param orgId
* @returns did
*/
@Post('/orgs/:orgId/agents/createDid')
@Post('/orgs/:orgId/agents/did')
@ApiOperation({
summary: 'Create did',
description: 'Create did'
summary: 'Create new did',
description: 'Create new did for an organization'
})
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN)
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER)
@ApiResponse({ status: HttpStatus.CREATED, description: 'Success', type: ApiResponseDto })
async createDid(
@Param('orgId') orgId: string,
@Body() createDidDto: CreateDidDto,
@Body() createDidDto: CreateNewDidDto,
@User() user: user,
@Res() res: Response
): Promise<Response> {
Expand Down
9 changes: 9 additions & 0 deletions apps/api-gateway/src/agent-service/dto/create-new-did.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsBoolean } from 'class-validator';
import { CreateDidDto } from './create-did.dto';
export class CreateNewDidDto extends CreateDidDto {
@ApiProperty({example: false})
@ApiPropertyOptional()
@IsBoolean({ message: 'isPrimaryDid did must be true or false.' })
isPrimaryDid: boolean = false;
}
Loading

0 comments on commit dfd9a7f

Please sign in to comment.