Skip to content

Commit

Permalink
Merge pull request #299 from credebl/id-to-uuid-type
Browse files Browse the repository at this point in the history
fix: createdBy and lastChangedBy UUID updation
  • Loading branch information
nishad-ayanworks authored Nov 23, 2023
2 parents 5af4e85 + 06fb0cb commit 3ac4b29
Show file tree
Hide file tree
Showing 44 changed files with 601 additions and 225 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ dist
sonar-project.properties
.scannerwork/*
coverage
libs/prisma-service/prisma/data/credebl-master-table.json
libs/prisma-service/prisma/data/credebl-master-table.json
uploadedFles/exports
uploadedFles/import
uploadedFles/export
3 changes: 1 addition & 2 deletions Dockerfiles/Dockerfile.agnet-provisioning
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ RUN mkdir -p ./agent-provisioning/AFJ/agent-config
COPY --from=build /app/dist/apps/agent-provisioning/ ./dist/apps/agent-provisioning/
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/apps/agent-provisioning/AFJ/scripts ./agent-provisioning/AFJ/scripts


COPY --from=build /app/apps/agent-provisioning/AFJ/port-files ./agent-provisioning/AFJ/port-file

# Set permissions
RUN chmod +x /app/agent-provisioning/AFJ/scripts/start_agent.sh
Expand Down
3 changes: 1 addition & 2 deletions apps/agent-provisioning/AFJ/scripts/start_agent_ecs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ cat <<EOF >>/app/agent-provisioning/AFJ/agent-config/${AGENCY}_${CONTAINER_NAME}
"tenancy": $TENANT
}
EOF
scp ${PWD}/agent-provisioning/AFJ/agent-config/${AGENCY}_${CONTAINER_NAME}.json ${AGENT_HOST}:/home/ec2-user/config/
# scp ${PWD}/agent-provisioning/AFJ/agent-config/${AGENCY}_${CONTAINER_NAME}.json ${AGENT_HOST}:/home/ec2-user/config/

# Construct the container definitions dynamically
CONTAINER_DEFINITIONS=$(
Expand Down Expand Up @@ -239,7 +239,6 @@ if [ $? -eq 0 ]; then
"AGENT_ENDPOINT" : "${INTERNAL_IP}:${ADMIN_PORT}"
}
EOF
sudo rm -rf ${PWD}/agent-provisioning/AFJ/agent-config/${AGENCY}_${CONTAINER_NAME}.json
echo "Agent config created"
else
echo "==============="
Expand Down
29 changes: 21 additions & 8 deletions apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ export class AgentServiceService {
async walletProvision(agentSpinupDto: IAgentSpinupDto, user: IUserRequestInterface): Promise<{ agentSpinupStatus: number }> {
let agentProcess: org_agents;
try {
this.processWalletProvision(agentSpinupDto, user, agentProcess);

this.processWalletProvision(agentSpinupDto, user);
const agentStatusResponse = {
agentSpinupStatus: AgentSpinUpStatus.PROCESSED
};
Expand All @@ -142,7 +143,10 @@ export class AgentServiceService {
}
}

private async processWalletProvision(agentSpinupDto: IAgentSpinupDto, user: IUserRequestInterface, agentProcess: org_agents): Promise<void> {
private async processWalletProvision(agentSpinupDto: IAgentSpinupDto, user: IUserRequestInterface): Promise<void> {
let platformAdminUser;
let userId: string;
let agentProcess: org_agents;
try {
const [getOrgAgent, platformConfig, getAgentType, ledgerIdData, orgData] = await Promise.all([
this.agentServiceRepository.getAgentDetails(agentSpinupDto.orgId),
Expand All @@ -151,7 +155,16 @@ export class AgentServiceService {
this.agentServiceRepository.getLedgerDetails(agentSpinupDto.ledgerName ? agentSpinupDto.ledgerName : [Ledgers.Indicio_Demonet]),
this.agentServiceRepository.getOrgDetails(agentSpinupDto.orgId)
]);


if (!user?.userId && agentSpinupDto?.platformAdminEmail) {

platformAdminUser = await this.agentServiceRepository.getPlatfomAdminUser(agentSpinupDto?.platformAdminEmail);

userId = platformAdminUser?.id;
} else {
userId = user?.userId;
}

agentSpinupDto.ledgerId = agentSpinupDto.ledgerId?.length ? agentSpinupDto.ledgerId : ledgerIdData.map(ledger => ledger.id);
const ledgerDetails = await this.agentServiceRepository.getGenesisUrl(agentSpinupDto.ledgerId);

Expand Down Expand Up @@ -187,7 +200,7 @@ export class AgentServiceService {

const agentSpinUpStatus = AgentSpinUpStatus.PROCESSED;
/* eslint-disable no-param-reassign */
agentProcess = await this.createOrgAgent(agentSpinUpStatus);
agentProcess = await this.createOrgAgent(agentSpinUpStatus, userId);
this.validateAgentProcess(agentProcess);

this._agentSpinup(walletProvisionPayload, agentSpinupDto, platformConfig?.sgApiKey, orgData, user, socket, agentSpinupDto.ledgerId, agentProcess);
Expand Down Expand Up @@ -294,9 +307,9 @@ export class AgentServiceService {
return socket;
}

async createOrgAgent(agentSpinUpStatus: AgentSpinUpStatus): Promise<org_agents> {
async createOrgAgent(agentSpinUpStatus: AgentSpinUpStatus, userId: string): Promise<org_agents> {
try {
const agentProcess = await this.agentServiceRepository.createOrgAgent(agentSpinUpStatus);
const agentProcess = await this.agentServiceRepository.createOrgAgent(agentSpinUpStatus, userId);
this.logger.log(`Organization agent created with status: ${agentSpinUpStatus}`);
return agentProcess;
} catch (error) {
Expand Down Expand Up @@ -567,10 +580,10 @@ export class AgentServiceService {

const ledgerIdData = await this.agentServiceRepository.getLedgerDetails(Ledgers.Indicio_Demonet);
const ledgerIds = ledgerIdData.map(ledger => ledger.id);

payload.ledgerId = !payload.ledgerId || 0 === payload.ledgerId?.length ? ledgerIds : payload.ledgerId;
const agentSpinUpStatus = AgentSpinUpStatus.PROCESSED;
agentProcess = await this.agentServiceRepository.createOrgAgent(agentSpinUpStatus);
agentProcess = await this.agentServiceRepository.createOrgAgent(agentSpinUpStatus, user.id);


const platformAdminSpinnedUp = await this.getPlatformAdminAndNotify(payload.clientSocketId);
Expand Down
4 changes: 3 additions & 1 deletion apps/agent-service/src/interface/agent-service.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface IAgentSpinupDto {
clientSocketId?: string
tenant?: boolean;
ledgerName?: string[];
platformAdminEmail?: string;
}

export interface OutOfBandCredentialOffer {
Expand Down Expand Up @@ -161,7 +162,8 @@ export interface IConnectionDetails {
}

export interface IUserRequestInterface {
userId: string;
userId?: string;
id?: string;
email: string;
orgId: string;
agentEndPoint?: string;
Expand Down
1 change: 1 addition & 0 deletions apps/agent-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ async function bootstrap(): Promise<void> {
walletPassword: process.env.PLATFORM_WALLET_PASSWORD,
seed: process.env.PLATFORM_SEED,
orgName: `${CommonConstants.PLATFORM_ADMIN_ORG}`,
platformAdminEmail: process.env.PLATFORM_ADMIN_EMAIL,
tenant: true,
ledgerName: [Ledgers.Bcovrin_Testnet, Ledgers.Indicio_Demonet, Ledgers.Indicio_Mainnet, Ledgers.Indicio_Testnet]
};
Expand Down
28 changes: 21 additions & 7 deletions apps/agent-service/src/repositories/agent-service.repository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PrismaService } from '@credebl/prisma-service';
import { Injectable, Logger } from '@nestjs/common';
// eslint-disable-next-line camelcase
import { Prisma, ledgers, org_agents, organisation, platform_config } from '@prisma/client';
import { Prisma, ledgers, org_agents, organisation, platform_config, user } from '@prisma/client';
import { IStoreOrgAgentDetails } from '../interface/agent-service.interface';
import { AgentType } from '@credebl/enum/enum';

Expand Down Expand Up @@ -69,12 +69,14 @@ export class AgentServiceRepository {
}

// eslint-disable-next-line camelcase
async createOrgAgent(agentSpinUpStatus: number): Promise<org_agents> {
async createOrgAgent(agentSpinUpStatus: number, userId: string): Promise<org_agents> {
try {

return this.prisma.org_agents.create({
data: {
agentSpinUpStatus
agentSpinUpStatus,
createdBy: userId,
lastChangedBy: userId
}
});
} catch (error) {
Expand Down Expand Up @@ -185,7 +187,7 @@ export class AgentServiceRepository {
});
return oranizationAgentDetails;
} catch (error) {
this.logger.error(`[getAgentDetails] - get org agent health details: ${JSON.stringify(error)}`);
this.logger.error(`[getOrgAgentDetails] - get org agent health details: ${JSON.stringify(error)}`);
throw error;
}
}
Expand All @@ -199,17 +201,15 @@ export class AgentServiceRepository {
});
return id;
} catch (error) {
this.logger.error(`[getAgentDetails] - get org agent health details: ${JSON.stringify(error)}`);
this.logger.error(`[getAgentTypeDetails] - get org agent health details: ${JSON.stringify(error)}`);
throw error;
}
}

async getLedgerDetails(name: string[] | string): Promise<{
id: string;
createDateTime: Date;
createdBy: string;
lastChangedDateTime: Date;
lastChangedBy: string;
name: string;
networkType: string;
poolConfig: string;
Expand Down Expand Up @@ -272,6 +272,20 @@ export class AgentServiceRepository {
}
}

async getPlatfomAdminUser(platformAdminUserEmail: string): Promise<user> {
try {
const platformAdminUser = await this.prisma.user.findUnique({
where: {
email: platformAdminUserEmail
}
});
return platformAdminUser;
} catch (error) {
this.logger.error(`[getPlatfomAdminUser] - get platform admin user: ${JSON.stringify(error)}`);
throw error;
}
}

async getAgentType(id: string): Promise<string> {
try {
const { agent } = await this.prisma.agents_type.findUnique({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
Param
} from '@nestjs/common';
import { ApiTags, ApiResponse, ApiOperation, ApiUnauthorizedResponse, ApiForbiddenResponse, ApiBearerAuth } from '@nestjs/swagger';
import { GetUser } from '../authz/decorators/get-user.decorator';
import { AuthGuard } from '@nestjs/passport';
import { UnauthorizedErrorDto } from '../dtos/unauthorized-error.dto';
import { ApiResponseDto } from '../dtos/apiResponse.dto';
Expand Down Expand Up @@ -81,7 +80,7 @@ export class AgentController {
async agentSpinup(
@Body() agentSpinupDto: AgentSpinupDto,
@Param('orgId') orgId: string,
@GetUser() user: user,
@User() user: user,
@Res() res: Response
): Promise<Response<object, Record<string, object>>> {

Expand Down Expand Up @@ -121,7 +120,7 @@ export class AgentController {
async createTenant(
@Param('orgId') orgId: string,
@Body() createTenantDto: CreateTenantDto,
@GetUser() user: user,
@User() user: user,
@Res() res: Response
): Promise<object> {

Expand Down
18 changes: 9 additions & 9 deletions apps/api-gateway/src/agent/agent.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
} from '@nestjs/common';
import { AgentService } from './agent.service';
import { ApiTags, ApiResponse, ApiOperation, ApiQuery, ApiBearerAuth, ApiParam, ApiUnauthorizedResponse, ApiForbiddenResponse, ApiExcludeEndpoint } from '@nestjs/swagger';
import { GetUser } from '../authz/decorators/get-user.decorator';
import { AuthGuard } from '@nestjs/passport';
import { WalletDetailsDto } from '../dtos/wallet-details.dto';
import { UnauthorizedErrorDto } from '../dtos/unauthorized-error.dto';
Expand All @@ -28,6 +27,7 @@ import { ApiResponseDto } from '../dtos/apiResponse.dto';
import { ForbiddenErrorDto } from '../dtos/forbidden-error.dto';
import { CommonService } from '@credebl/common';
import { IUserRequestInterface } from '../interfaces/IUserRequestInterface';
import { User } from '../authz/decorators/user.decorator';

@ApiBearerAuth()
@Controller('agent')
Expand Down Expand Up @@ -57,7 +57,7 @@ export class AgentController {
@ApiUnauthorizedResponse({ status: 401, description: 'Unauthorized', type: UnauthorizedErrorDto })
@ApiForbiddenResponse({ status: 403, description: 'Forbidden', type: ForbiddenErrorDto })
getAllDid(
@GetUser() user: any,
@User() user: any,
@Query('_public') _public: boolean,
@Query('verkey') verkey: string,
@Query('did') did: string
Expand All @@ -80,7 +80,7 @@ export class AgentController {
@ApiUnauthorizedResponse({ status: 401, description: 'Unauthorized', type: UnauthorizedErrorDto })
@ApiForbiddenResponse({ status: 403, description: 'Forbidden', type: ForbiddenErrorDto })
createLocalDid(
@GetUser() user: any
@User() user: any
): Promise<object> {
this.logger.log(`**** Create Local Did...`);
return this.agentService.createLocalDid(user);
Expand All @@ -105,7 +105,7 @@ export class AgentController {
@ApiForbiddenResponse({ status: 403, description: 'Forbidden', type: ForbiddenErrorDto })
walletProvision(
@Body() walletUserDetails: WalletDetailsDto,
@GetUser() user: object
@User() user: object
): Promise<object> {
this.logger.log(`**** Spin up the agent...${JSON.stringify(walletUserDetails)}`);

Expand All @@ -131,7 +131,7 @@ export class AgentController {
@ApiUnauthorizedResponse({ status: 401, description: 'Unauthorized', type: UnauthorizedErrorDto })
@ApiForbiddenResponse({ status: 403, description: 'Forbidden', type: ForbiddenErrorDto })
getPublicDid(
@GetUser() user: any
@User() user: any
): Promise<object> {
this.logger.log(`**** Fetch public Did...`);
return this.agentService.getPublicDid(user);
Expand All @@ -151,7 +151,7 @@ export class AgentController {
@ApiForbiddenResponse({ status: 403, description: 'Forbidden', type: ForbiddenErrorDto })
assignPublicDid(
@Param('id') id: number,
@GetUser() user: any
@User() user: any
): Promise<object> {
this.logger.log(`**** Assign public DID...`);
this.logger.log(`user: ${user.orgId} == id: ${Number(id)}`);
Expand Down Expand Up @@ -182,7 +182,7 @@ export class AgentController {
@ApiForbiddenResponse({ status: 403, description: 'Forbidden', type: ForbiddenErrorDto })
registerNym(
@Param('id') id: string,
@GetUser() user: IUserRequestInterface
@User() user: IUserRequestInterface
): Promise<object> {
this.logger.log(`user: ${typeof user.orgId} == id: ${typeof Number(id)}`);

Expand Down Expand Up @@ -221,7 +221,7 @@ export class AgentController {
@ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto })
@ApiUnauthorizedResponse({ status: 401, description: 'Unauthorized', type: UnauthorizedErrorDto })
@ApiForbiddenResponse({ status: 403, description: 'Forbidden', type: ForbiddenErrorDto })
getAgentServerStatus(@GetUser() user: any): Promise<object> {
getAgentServerStatus(@User() user: any): Promise<object> {
this.logger.log(`**** getPlatformConfig called...`);
return this.agentService.getAgentServerStatus(user);
}
Expand Down Expand Up @@ -262,7 +262,7 @@ export class AgentController {
@Query('search_text') search_text: string,
@Query('sortValue') sortValue: any,
@Query('status') status: any,
@GetUser() user: any
@User() user: any
): Promise<object> {

this.logger.log(`status: ${typeof status} ${status}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ export class AcceptRejectEcosystemInvitationDto {
@IsEnum(Invitation)
status: Invitation.ACCEPTED | Invitation.REJECTED;

userId?: string;


}
3 changes: 3 additions & 0 deletions apps/api-gateway/src/ecosystem/dtos/edit-ecosystem-dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ export class EditEcosystemDto {
@IsOptional()
@IsNotEmpty({ message: 'autoEndorsement should be boolean value' })
autoEndorsement = false;

userId?: string;

}

4 changes: 4 additions & 0 deletions apps/api-gateway/src/ecosystem/dtos/request-schema.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export class RequestSchemaDto {
@IsOptional()
endorse?: boolean;

userId?: string;

}

export class SchemaDetails {
Expand Down Expand Up @@ -76,6 +78,8 @@ export class RequestCredDefDto {
@IsString({ message: 'tag must be a string.' })
tag: string;

userId?: string;

@ApiProperty()
@IsString({ message: 'schemaId must be a string.' })
schemaId: string;
Expand Down
Loading

0 comments on commit 3ac4b29

Please sign in to comment.