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

Shell script modifications for agent spinup #191

Merged
merged 15 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 7 additions & 6 deletions apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class AgentServiceService {

agentSpinupDto.agentType = agentSpinupDto.agentType ? agentSpinupDto.agentType : 1;
agentSpinupDto.tenant = agentSpinupDto.tenant ? agentSpinupDto.tenant : false;
agentSpinupDto.ledgerId = !agentSpinupDto.ledgerId || 0 === agentSpinupDto.ledgerId.length ? [1] : agentSpinupDto.ledgerId;
agentSpinupDto.ledgerId = !agentSpinupDto.ledgerId || 0 === agentSpinupDto.ledgerId.length ? [3] : agentSpinupDto.ledgerId;


const platformConfig: platform_config = await this.agentServiceRepository.getPlatformConfigDetails();
Expand Down Expand Up @@ -338,10 +338,11 @@ export class AgentServiceService {


const agentDidWriteUrl = `${payload.agentEndPoint}${CommonConstants.URL_AGENT_WRITE_DID}`;
const { seed } = payload;
const { seed, ledgerId } = payload;
const { apiKey } = payload;
const writeDid = 'write-did';
const agentDid = await this._retryAgentSpinup(agentDidWriteUrl, apiKey, writeDid, seed);
const ledgerDetails: ledgers[] = await this.agentServiceRepository.getGenesisUrl(ledgerId);
const agentDid = await this._retryAgentSpinup(agentDidWriteUrl, apiKey, writeDid, seed, ledgerDetails[0].indyNamespace);
if (agentDid) {

const getDidMethodUrl = `${payload.agentEndPoint}${CommonConstants.URL_AGENT_GET_DIDS}`;
Expand Down Expand Up @@ -388,14 +389,14 @@ export class AgentServiceService {
}
}

async _retryAgentSpinup(agentUrl: string, apiKey: string, agentApiState: string, seed?: string): Promise<object> {
async _retryAgentSpinup(agentUrl: string, apiKey: string, agentApiState: string, seed?: string, indyNamespace?: string): Promise<object> {
return retry(
async () => {

if ('write-did' === agentApiState) {

const agentDid = await this.commonService
.httpPost(agentUrl, { seed }, { headers: { 'x-api-key': apiKey } })
.httpPost(agentUrl, { seed, method: indyNamespace }, { headers: { 'x-api-key': apiKey } })
.then(async response => response);
return agentDid;
} else if ('get-did-doc' === agentApiState) {
Expand Down Expand Up @@ -486,7 +487,7 @@ export class AgentServiceService {
async _createTenant(payload: ITenantDto, user: IUserRequestInterface): Promise<void> {
try {

payload.ledgerId = !payload.ledgerId || 0 === payload.ledgerId.length ? [1] : payload.ledgerId;
payload.ledgerId = !payload.ledgerId || 0 === payload.ledgerId.length ? [3] : payload.ledgerId;

const ledgerDetails: ledgers[] = await this.agentServiceRepository.getGenesisUrl(payload.ledgerId);
const sharedAgentSpinUpResponse = new Promise(async (resolve, _reject) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/agent-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function bootstrap(): Promise<void> {
seed: process.env.PLATFORM_SEED,
orgId: parseInt(process.env.PLATFORM_ID),
tenant: true,
ledgerId: [1, 2]
ledgerId: [1, 2, 3, 4]
};

const agentService = app.get(AgentServiceService);
Expand Down
13 changes: 13 additions & 0 deletions apps/api-gateway/src/organization/organization.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ export class OrganizationController {
private readonly commonService: CommonService
) { }

@Get('/profile/:orgId')
@ApiOperation({ summary: 'Organization Profile', description: 'Update an organization' })
@ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto })
async getOgPofile(@Param('orgId') orgId: number, @Res() res: Response): Promise<Response> {
const orgProfile = await this.organizationService.getOgPofile(orgId);

const base64Data = orgProfile.response["logoUrl"].replace(/^data:image\/\w+;base64,/, '');

const imageBuffer = Buffer.from(base64Data, 'base64');
res.setHeader('Content-Type', 'image/png');
return res.send(imageBuffer);
}

/**
*
* @param user
Expand Down
8 changes: 8 additions & 0 deletions apps/api-gateway/src/organization/organization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,12 @@ export class OrganizationService extends BaseService {

return this.sendNats(this.serviceProxy, 'fetch-organization-user', payload);
}

async getOgPofile(
orgId: number
): Promise<{ response: object }> {
const payload = { orgId };

return this.sendNats(this.serviceProxy, 'fetch-organization-profile', payload);
}
}
23 changes: 21 additions & 2 deletions apps/connection/src/connection.repository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable, InternalServerErrorException, Logger } from '@nestjs/common';
import { PrismaService } from '@credebl/prisma-service';
// eslint-disable-next-line camelcase
import { agent_invitations, connections, org_agents, platform_config, shortening_url } from '@prisma/client';
import { agent_invitations, connections, organisation, platform_config, shortening_url } from '@prisma/client';
@Injectable()
export class ConnectionRepository {

Expand All @@ -16,12 +16,31 @@ export class ConnectionRepository {
* @returns Get getAgentEndPoint details
*/
// eslint-disable-next-line camelcase
async getAgentEndPoint(orgId: number): Promise<org_agents> {
async getAgentEndPoint(orgId: number): Promise<{
organisation: organisation;
} & {
id: number;
createDateTime: Date;
createdBy: number;
lastChangedDateTime: Date;
lastChangedBy: number;
orgDid: string;
verkey: string;
agentEndPoint: string;
agentId: number;
isDidPublic: boolean;
ledgerId: number;
orgAgentTypeId: number;
tenantId: string;
}> {
try {

const agentDetails = await this.prisma.org_agents.findFirst({
where: {
orgId
},
include: {
organisation: true
}
});
return agentDetails;
Expand Down
10 changes: 8 additions & 2 deletions apps/connection/src/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,23 @@ export class ConnectionService {
try {
const agentDetails = await this.connectionRepository.getAgentEndPoint(orgId);
const platformConfig: platform_config = await this.connectionRepository.getPlatformConfigDetails();
const { agentEndPoint, id } = agentDetails;
const { agentEndPoint, id, organisation } = agentDetails;
const agentId = id;
if (!agentDetails) {
throw new NotFoundException(ResponseMessages.connection.error.agentEndPointNotFound);
}

let logoImageUrl;
if (organisation.logoUrl) {
logoImageUrl = `${process.env.API_GATEWAY_PROTOCOL}://${process.env.API_ENDPOINT}/orgs/profile/${organisation.id}`;
}

this.logger.log(`logoImageUrl ::: ${logoImageUrl}`);
const connectionPayload = {
multiUseInvitation: multiUseInvitation || true,
autoAcceptConnection: autoAcceptConnection || true,
alias: alias || undefined,
imageUrl: imageUrl || undefined,
imageUrl: logoImageUrl ? logoImageUrl : undefined,
label: label || undefined
};

Expand Down
14 changes: 14 additions & 0 deletions apps/organization/repositories/organization.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,18 @@ export class OrganizationRepository {
throw new InternalServerErrorException(error);
}
}

async getOrgProfile(id: number): Promise<organisation> {
try {
return this.prisma.organisation.findUnique({
where: {
id
}
});
} catch (error) {
this.logger.error(`error: ${JSON.stringify(error)}`);
throw error;
}
}

}
5 changes: 5 additions & 0 deletions apps/organization/src/organization.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,9 @@ export class OrganizationController {
async getOrgDashboard(payload: { orgId: number; userId: number }): Promise<object> {
return this.organizationService.getOrgDashboard(payload.orgId);
}

@MessagePattern({ cmd: 'fetch-organization-profile' })
async getOgPofile(payload: { orgId: number }): Promise<object> {
return this.organizationService.getOgPofile(payload.orgId);
}
}
13 changes: 13 additions & 0 deletions apps/organization/src/organization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,17 @@ export class OrganizationService {
throw new RpcException(error.response ? error.response : error);
}
}

async getOgPofile(orgId: number): Promise<organisation> {
try {
const orgProfile = await this.organizationRepository.getOrgProfile(orgId);
if (!orgProfile.logoUrl || '' === orgProfile.logoUrl) {
throw new NotFoundException(ResponseMessages.organisation.error.orgProfile);
}
return orgProfile;
} catch (error) {
this.logger.error(`get organization profile : ${JSON.stringify(error)}`);
throw new RpcException(error.response ? error.response : error);
}
}
}
1 change: 1 addition & 0 deletions libs/common/src/response-messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const ResponseMessages = {
exists: 'An organization name is already exist',
profileNotFound: 'Organization public profile not found',
rolesNotExist: 'Provided roles not exists in the platform',
orgProfile: 'Organization profile not found',
userNotFound: 'User not found for the given organization',
updateUserRoles: 'Unable to update user roles'
}
Expand Down
20 changes: 20 additions & 0 deletions libs/prisma-service/prisma/data/credebl-master-table.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,26 @@
"registerDIDEndpoint": "https://selfserve.indiciotech.io/nym",
"registerDIDPayload": "",
"indyNamespace": "indicio:testnet"
},
{
"name": "Indicio Demonet",
"networkType": "demonet",
"poolConfig": "https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_demonet_genesis",
"isActive": true,
"networkString": "demonet",
"registerDIDEndpoint": "https://selfserve.indiciotech.io/nym",
"registerDIDPayload": "",
"indyNamespace": "indicio:demonet"
},
{
"name": "Indicio Mainnet",
"networkType": "mainnet",
"poolConfig": "https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_mainnet_genesis",
"isActive": true,
"networkString": "mainnet",
"registerDIDEndpoint": "https://selfserve.indiciotech.io/nym",
"registerDIDPayload": "",
"indyNamespace": "indicio:mainnet"
}
],
"endorseData": [
Expand Down