diff --git a/apps/agent-provisioning/AFJ/scripts/start_agent.sh b/apps/agent-provisioning/AFJ/scripts/start_agent.sh index eceeeb2d1..5d1135a9a 100755 --- a/apps/agent-provisioning/AFJ/scripts/start_agent.sh +++ b/apps/agent-provisioning/AFJ/scripts/start_agent.sh @@ -23,6 +23,7 @@ INBOUND_PORT_FILE="$PWD/apps/agent-provisioning/AFJ/port-file/last-inbound-port. ADMIN_PORT=8001 INBOUND_PORT=9001 + increment_port() { local port="$1" local lower_limit="$2" @@ -96,7 +97,7 @@ if [ -f "$CONFIG_FILE" ]; then rm "$CONFIG_FILE" fi -cat <>${CONFIG_FILE} +cat <${CONFIG_FILE} { "label": "${AGENCY}_${CONTAINER_NAME}", "walletId": "$WALLET_NAME", @@ -140,7 +141,7 @@ if [ -f "$DOCKER_COMPOSE" ]; then # If it exists, remove the file rm "$DOCKER_COMPOSE" fi -cat <>${DOCKER_COMPOSE} +cat <${DOCKER_COMPOSE} version: '3' services: @@ -216,13 +217,13 @@ if [ $? -eq 0 ]; then # If it exists, remove the file rm "$ENDPOINT" fi - cat <>${ENDPOINT} + cat <${ENDPOINT} { "CONTROLLER_ENDPOINT":"${EXTERNAL_IP}:${ADMIN_PORT}" } EOF - cat <>${PWD}/token/${AGENCY}_${CONTAINER_NAME}.json + cat <${PWD}/token/${AGENCY}_${CONTAINER_NAME}.json { "token" : "$token" } diff --git a/apps/agent-provisioning/src/agent-provisioning.service.ts b/apps/agent-provisioning/src/agent-provisioning.service.ts index 465e4087d..9fd6477f4 100644 --- a/apps/agent-provisioning/src/agent-provisioning.service.ts +++ b/apps/agent-provisioning/src/agent-provisioning.service.ts @@ -25,7 +25,7 @@ export class AgentProvisioningService { const { containerName, externalIp, orgId, seed, walletName, walletPassword, walletStorageHost, walletStoragePassword, walletStoragePort, walletStorageUser, webhookEndpoint, agentType, protocol, afjVersion, tenant, indyLedger } = payload; if (agentType === AgentType.AFJ) { // The wallet provision command is used to invoke a shell script - const walletProvision = `${process.cwd() + process.env.AFJ_AGENT_SPIN_UP} ${orgId} "${externalIp}" "${walletName}" "${walletPassword}" ${seed} ${webhookEndpoint} ${walletStorageHost} ${walletStoragePort} ${walletStorageUser} ${walletStoragePassword} ${containerName} ${protocol} ${tenant} ${afjVersion} ${indyLedger} ${process.env.AGENT_HOST} ${process.env.AWS_ACCOUNT_ID} ${process.env.S3_BUCKET_ARN} ${process.env.CLUSTER_NAME} ${process.env.TESKDEFINITION_FAMILY}`; + const walletProvision = `${process.cwd() + process.env.AFJ_AGENT_SPIN_UP} ${orgId} "${externalIp}" "${walletName}" "${walletPassword}" ${seed} ${webhookEndpoint} ${walletStorageHost} ${walletStoragePort} ${walletStorageUser} ${walletStoragePassword} ${containerName} ${protocol} ${tenant} ${afjVersion} "${indyLedger}" ${process.env.AGENT_HOST} ${process.env.AWS_ACCOUNT_ID} ${process.env.S3_BUCKET_ARN} ${process.env.CLUSTER_NAME} ${process.env.TESKDEFINITION_FAMILY}`; const spinUpResponse: object = new Promise(async (resolve) => { await exec(walletProvision, async (err, stdout, stderr) => { diff --git a/apps/connection/src/connection.service.ts b/apps/connection/src/connection.service.ts index d97990f10..cc50ef4ee 100644 --- a/apps/connection/src/connection.service.ts +++ b/apps/connection/src/connection.service.ts @@ -36,7 +36,7 @@ export class ConnectionService { */ async createLegacyConnectionInvitation(payload: IConnection): Promise { - const {orgId, multiUseInvitation, autoAcceptConnection, alias, label} = payload; + const { orgId, multiUseInvitation, autoAcceptConnection, alias, label } = payload; try { const connectionInvitationExist = await this.connectionRepository.getConnectionInvitationByOrgId(orgId); if (connectionInvitationExist) { @@ -68,14 +68,11 @@ export class ConnectionService { const orgAgentType = await this.connectionRepository.getOrgAgentType(agentDetails?.orgAgentTypeId); const url = await this.getAgentUrl(orgAgentType, agentEndPoint, agentDetails?.tenantId); - // const apiKey = platformConfig?.sgApiKey; - - const apiKey = await this._getOrgAgentApiKey(orgId); - // let apiKey:string = await this.cacheService.get(CommonConstants.CACHE_APIKEY_KEY); - // this.logger.log(`cachedApiKey----getConnections,${apiKey}`); - //if(!apiKey || apiKey === null || apiKey === undefined) { - // apiKey = await this._getOrgAgentApiKey(orgId); - // } + let apiKey: string = await this.cacheService.get(CommonConstants.CACHE_APIKEY_KEY); + this.logger.log(`cachedApiKey----getConnections,${apiKey}`); + if (!apiKey || null === apiKey || undefined === apiKey) { + apiKey = await this._getOrgAgentApiKey(orgId); + } const createConnectionInvitation = await this._createConnectionInvitation(connectionPayload, url, apiKey); const invitationObject = createConnectionInvitation?.message?.invitation['@id']; let shortenedUrl; @@ -205,45 +202,15 @@ export class ConnectionService { theirDid, theirLabel }; - - let url; - if (orgAgentType === OrgAgentType.DEDICATED) { - - url = `${agentEndPoint}${CommonConstants.URL_CONN_GET_CONNECTIONS}`; - - } else if (orgAgentType === OrgAgentType.SHARED) { - - url = `${agentEndPoint}${CommonConstants.URL_SHAGENT_GET_CREATEED_INVITATIONS}`.replace('#', agentDetails.tenantId); - } else { - - throw new NotFoundException(ResponseMessages.connection.error.agentUrlNotFound); - } - - Object.keys(params).forEach((element: string) => { - const appendParams: string = url.includes('?') ? '&' : '?'; - - if (params[element] !== undefined) { - url = `${url + appendParams + element}=${params[element]}`; - } - }); - - - // const apiKey = await this._getOrgAgentApiKey(orgId); - let apiKey:string = await this.cacheService.get(CommonConstants.CACHE_APIKEY_KEY); - this.logger.log(`cachedApiKey----getConnections,${apiKey}`); - if (!apiKey || null === apiKey || undefined === apiKey) { - apiKey = await this._getOrgAgentApiKey(orgId); - } - const connectionsDetails = await this._getAllConnections(url, apiKey); - return connectionsDetails?.response; + return connectionResponse; } catch (error) { this.logger.error( `[getConnections] [NATS call]- error in fetch connections details : ${JSON.stringify(error)}` ); - throw new RpcException(error.response ? error.response : error); - } + throw new RpcException(error.response ? error.response : error); + } } async _getAllConnections( @@ -305,19 +272,19 @@ export class ConnectionService { // const apiKey = await this._getOrgAgentApiKey(orgId); - let apiKey:string = await this.cacheService.get(CommonConstants.CACHE_APIKEY_KEY); + let apiKey: string = await this.cacheService.get(CommonConstants.CACHE_APIKEY_KEY); this.logger.log(`cachedApiKey----getConnectionsById,${apiKey}`); - if (!apiKey || null === apiKey || undefined === apiKey) { - apiKey = await this._getOrgAgentApiKey(orgId); + if (!apiKey || null === apiKey || undefined === apiKey) { + apiKey = await this._getOrgAgentApiKey(orgId); } const createConnectionInvitation = await this._getConnectionsByConnectionId(url, apiKey); - return createConnectionInvitation?.response; - } catch (error) { + return createConnectionInvitation; + } catch (error) { this.logger.error(`[getConnectionsById] - error in get connections : ${JSON.stringify(error)}`); - if (error?.response?.error?.reason) { + if (error?.response?.error?.reason) { throw new RpcException({ message: ResponseMessages.connection.error.connectionNotFound, statusCode: error?.response?.status, @@ -334,25 +301,25 @@ export class ConnectionService { apiKey: string ): Promise { - //nats call in agent service for fetch connection details - const pattern = { cmd: 'agent-get-connection-details-by-connectionId' }; - const payload = { url, apiKey }; - return this.connectionServiceProxy - .send(pattern, payload) - .toPromise() - .catch(error => { - this.logger.error( - `[_getConnectionsByConnectionId] [NATS call]- error in fetch connections : ${JSON.stringify(error)}` - ); - throw new HttpException( - { - status: error.statusCode, - error: error.error?.message?.error ? error.error?.message?.error : error.error, - message: error.message - }, error.error); - }); + //nats call in agent service for fetch connection details + const pattern = { cmd: 'agent-get-connection-details-by-connectionId' }; + const payload = { url, apiKey }; + return this.connectionServiceProxy + .send(pattern, payload) + .toPromise() + .catch(error => { + this.logger.error( + `[_getConnectionsByConnectionId] [NATS call]- error in fetch connections : ${JSON.stringify(error)}` + ); + throw new HttpException( + { + status: error.statusCode, + error: error.error?.message?.error ? error.error?.message?.error : error.error, + message: error.message + }, error.error); + }); } - + /** * Description: Fetch agent url * @param referenceId