Skip to content

Commit

Permalink
Merge pull request #300 from credebl/develop-to-main
Browse files Browse the repository at this point in the history
Develop to main branch
  • Loading branch information
nishad-ayanworks committed Nov 23, 2023
2 parents c5077e3 + 414ccad commit dd832d9
Show file tree
Hide file tree
Showing 146 changed files with 3,830 additions and 1,491 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
1 change: 1 addition & 0 deletions apps/agent-provisioning/AFJ/port-file/last-admin-port.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8000
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9000
74 changes: 54 additions & 20 deletions apps/agent-provisioning/AFJ/scripts/start_agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,60 @@ PROTOCOL=${12}
TENANT=${13}
AFJ_VERSION=${14}
INDY_LEDGER=${15}
ADMIN_PORT=$((8000 + $AGENCY))
INBOUND_PORT=$((9000 + $AGENCY))
CONTROLLER_PORT=$((3000 + $AGENCY))
POSTGRES_PORT=$((5432 + $AGENCY))
NETWORK_NAME="credebl-network"

echo "AGENT SPIN-UP STARTED"
if [ ${AGENCY} -eq 1 ]; then
echo "CREATING DOCKER NETWORK"
docker network create --driver bridge --subnet 10.20.0.0/16 --gateway 10.20.0.1 credebl-network
[ $? != 0 ] && error "Failed to create docker network !" && exit 102
echo "CREATED DOCKER NETWORK. SETTING UP INITIAL IPs"
INTERNAL_IP=10.20.0.2
POSTGRES_IP=10.20.0.3
CONTROLLER_IP=10.20.0.4
ADMIN_PORT_FILE="$PWD/apps/agent-provisioning/AFJ/port-file/last-admin-port.txt"
INBOUND_PORT_FILE="$PWD/apps/agent-provisioning/AFJ/port-file/last-inbound-port.txt"
ADMIN_PORT=8001
INBOUND_PORT=9001

increment_port() {
local port="$1"
local lower_limit="$2"

while [ "$port" -le "$lower_limit" ]; do
port=$((port + 1)) # Increment the port using arithmetic expansion
done

echo "$port"
}

# Check if admin port file exists and if not, create and initialize it
if [ ! -e "$ADMIN_PORT_FILE" ]; then
echo "$ADMIN_PORT" > "$ADMIN_PORT_FILE"
fi

# Read the last used admin port number from the file
last_used_admin_port=$(cat "$ADMIN_PORT_FILE")
echo "Last used admin port: $last_used_admin_port"

# Increment the admin port number starting from the last used port
last_used_admin_port=$(increment_port "$last_used_admin_port" "$last_used_admin_port")

# Save the updated admin port number back to the file and update the global variable
echo "$last_used_admin_port" > "$ADMIN_PORT_FILE"
ADMIN_PORT="$last_used_admin_port"

# Check if inbound port file exists and if not, create and initialize it
if [ ! -e "$INBOUND_PORT_FILE" ]; then
echo "$INBOUND_PORT" > "$INBOUND_PORT_FILE"
fi

# Read the last used inbound port number from the file
last_used_inbound_port=$(cat "$INBOUND_PORT_FILE")
echo "Last used inbound port: $last_used_inbound_port"

# Increment the inbound port number starting from the last used port
last_used_inbound_port=$(increment_port "$last_used_inbound_port" "$last_used_inbound_port")

# Save the updated inbound port number back to the file and update the global variable
echo "$last_used_inbound_port" > "$INBOUND_PORT_FILE"
INBOUND_PORT="$last_used_inbound_port"

echo "Last used admin port: $ADMIN_PORT"
echo "Last used inbound port: $INBOUND_PORT"

echo "AGENT SPIN-UP STARTED"

if [ -d "${PWD}/apps/agent-provisioning/AFJ/endpoints" ]; then
echo "Endpoints directory exists."
else
Expand Down Expand Up @@ -87,7 +124,7 @@ services:
agent:
image: $AFJ_VERSION
container_name: agent${AGENCY}_${CONTAINER_NAME}
container_name: ${AGENCY}_${CONTAINER_NAME}
restart: always
environment:
AFJ_REST_LOG_LEVEL: 1
Expand Down Expand Up @@ -115,7 +152,7 @@ if [ $? -eq 0 ]; then
echo "container-name::::::${CONTAINER_NAME}"
echo "file-name::::::$FILE_NAME"

docker-compose -f $FILE_NAME --project-name agent${AGENCY}_${CONTAINER_NAME} up -d
docker-compose -f $FILE_NAME --project-name ${AGENCY}_${CONTAINER_NAME} up -d
if [ $? -eq 0 ]; then

n=0
Expand Down Expand Up @@ -143,9 +180,6 @@ if [ $? -eq 0 ]; then
cat <<EOF >>${PWD}/endpoints/${AGENCY}_${CONTAINER_NAME}.json
{
"CONTROLLER_ENDPOINT":"${EXTERNAL_IP}:${ADMIN_PORT}",
"CONTROLLER_IP" : "${CONTROLLER_IP}",
"CONTROLLER_PORT" : "${CONTROLLER_PORT}",
"POSTGRES_ENDPOINT" : "${POSTGRES_IP}:${POSTGRES_PORT}",
"AGENT_ENDPOINT" : "${INTERNAL_IP}:${ADMIN_PORT}"
}
EOF
Expand All @@ -159,4 +193,4 @@ else
echo "ERROR : Failed to execute!" && exit 125
fi

echo "Total time elapsed: $(date -ud "@$(($(date +%s) - $START_TIME))" +%T) (HH:MM:SS)"
echo "Total time elapsed: $(date -ud "@$(($(date +%s) - $START_TIME))" +%T) (HH:MM:SS)"
70 changes: 53 additions & 17 deletions apps/agent-provisioning/AFJ/scripts/start_agent_ecs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,64 @@ AWS_ACCOUNT_ID=${17}
S3_BUCKET_ARN=${18}
CLUSTER_NAME=${19}
TESKDEFINITION_FAMILY=${20}
ADMIN_PORT=$((8000 + AGENCY))
INBOUND_PORT=$((9000 + AGENCY))
CONTROLLER_PORT=$((3000 + AGENCY))
POSTGRES_PORT=$((5432 + AGENCY))

SERVICE_NAME="${AGENCY}-${CONTAINER_NAME}-service"
DESIRED_COUNT=1

EXTERNAL_IP=$(echo "$2" | tr -d '[:space:]')
ADMIN_PORT_FILE="$PWD/apps/agent-provisioning/AFJ/port-file/last-admin-port.txt"
INBOUND_PORT_FILE="$PWD/apps/agent-provisioning/AFJ/port-file/last-inbound-port.txt"
ADMIN_PORT=8001
INBOUND_PORT=9001

AGENT_ENDPOINT="${PROTOCOL}://${EXTERNAL_IP}:${INBOUND_PORT}"
increment_port() {
local port="$1"
local lower_limit="$2"

while [ "$port" -le "$lower_limit" ]; do
port=$((port + 1)) # Increment the port using arithmetic expansion
done

echo "$port"
}

# Check if admin port file exists and if not, create and initialize it
if [ ! -e "$ADMIN_PORT_FILE" ]; then
echo "$ADMIN_PORT" > "$ADMIN_PORT_FILE"
fi

# Read the last used admin port number from the file
last_used_admin_port=$(cat "$ADMIN_PORT_FILE")
echo "Last used admin port: $last_used_admin_port"

# Increment the admin port number starting from the last used port
last_used_admin_port=$(increment_port "$last_used_admin_port" "$last_used_admin_port")

# Save the updated admin port number back to the file and update the global variable
echo "$last_used_admin_port" > "$ADMIN_PORT_FILE"
ADMIN_PORT="$last_used_admin_port"

# Check if inbound port file exists and if not, create and initialize it
if [ ! -e "$INBOUND_PORT_FILE" ]; then
echo "$INBOUND_PORT" > "$INBOUND_PORT_FILE"
fi

# Read the last used inbound port number from the file
last_used_inbound_port=$(cat "$INBOUND_PORT_FILE")
echo "Last used inbound port: $last_used_inbound_port"

# Increment the inbound port number starting from the last used port
last_used_inbound_port=$(increment_port "$last_used_inbound_port" "$last_used_inbound_port")

# Save the updated inbound port number back to the file and update the global variable
echo "$last_used_inbound_port" > "$INBOUND_PORT_FILE"
INBOUND_PORT="$last_used_inbound_port"

echo "Last used admin port: $ADMIN_PORT"
echo "Last used inbound port: $INBOUND_PORT"
echo "AGENT SPIN-UP STARTED"

AGENT_ENDPOINT="${PROTOCOL}://${EXTERNAL_IP}:${INBOUND_PORT}"

cat <<EOF >>/app/agent-provisioning/AFJ/agent-config/${AGENCY}_${CONTAINER_NAME}.json
{
"label": "${AGENCY}_${CONTAINER_NAME}",
Expand Down Expand Up @@ -69,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 All @@ -90,11 +135,6 @@ CONTAINER_DEFINITIONS=$(
"containerPort": $INBOUND_PORT,
"hostPort": $INBOUND_PORT,
"protocol": "tcp"
},
{
"containerPort": $CONTROLLER_PORT,
"hostPort": $CONTROLLER_PORT,
"protocol": "tcp"
}
],
"essential": true,
Expand Down Expand Up @@ -196,17 +236,13 @@ if [ $? -eq 0 ]; then
cat <<EOF >>${PWD}/agent-provisioning/AFJ/endpoints/${AGENCY}_${CONTAINER_NAME}.json
{
"CONTROLLER_ENDPOINT":"${EXTERNAL_IP}:${ADMIN_PORT}",
"CONTROLLER_IP" : "${CONTROLLER_IP}",
"CONTROLLER_PORT" : "${CONTROLLER_PORT}",
"POSTGRES_ENDPOINT" : "${POSTGRES_IP}:${POSTGRES_PORT}",
"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 "==============="
echo "ERROR : Failed to spin up the agent!"
echo "===============" && exit 125
fi
echo "Total time elapsed: $(date -ud "@$(($(date +%s) - $START_TIME))" +%T) (HH:MM:SS)"
echo "Total time elapsed: $(date -ud "@$(($(date +%s) - $START_TIME))" +%T) (HH:MM:SS)"
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable quotes */
import { AgentType } from "@credebl/enum/enum";

export interface IWalletProvision {
Expand Down Expand Up @@ -42,7 +43,7 @@ export interface IAgentSpinUp {

export interface IStartStopAgent {
action: string;
orgId: number;
orgId: string;
orgName: string;
}

Expand Down
18 changes: 13 additions & 5 deletions apps/agent-service/src/agent-service.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class AgentServiceController {

@MessagePattern({ cmd: 'agent-create-credential-definition' })
async createCredentialDefinition(payload: ITenantCredDef): Promise<object> {

return this.agentServiceService.createCredentialDefinition(payload);
}

Expand All @@ -45,6 +46,7 @@ export class AgentServiceController {

@MessagePattern({ cmd: 'agent-create-connection-legacy-invitation' })
async createLegacyConnectionInvitation(payload: { connectionPayload: IConnectionDetails, url: string, apiKey: string }): Promise<object> {

return this.agentServiceService.createLegacyConnectionInvitation(payload.connectionPayload, payload.url, payload.apiKey);
}

Expand Down Expand Up @@ -93,7 +95,7 @@ export class AgentServiceController {
}

@MessagePattern({ cmd: 'agent-health' })
async getAgentHealth(payload: { user: user, orgId: number }): Promise<object> {
async getAgentHealth(payload: { user: user, orgId: string }): Promise<object> {
return this.agentServiceService.getAgentHealthDetails(payload.orgId);
}

Expand All @@ -104,29 +106,35 @@ export class AgentServiceController {

@MessagePattern({ cmd: 'agent-proof-form-data' })
async getProofFormData(payload: { url: string, apiKey: string }): Promise<object> {

return this.agentServiceService.getProofFormData(payload.url, payload.apiKey);
}

@MessagePattern({ cmd: 'agent-schema-endorsement-request' })
async schemaEndorsementRequest(payload: { url: string, apiKey: string, requestSchemaPayload:object }): Promise<object> {
async schemaEndorsementRequest(payload: { url: string, apiKey: string, requestSchemaPayload: object }): Promise<object> {
return this.agentServiceService.schemaEndorsementRequest(payload.url, payload.apiKey, payload.requestSchemaPayload);
}
@MessagePattern({ cmd: 'agent-credDef-endorsement-request' })
async credDefEndorsementRequest(payload: { url: string, apiKey: string, requestSchemaPayload:object }): Promise<object> {
async credDefEndorsementRequest(payload: { url: string, apiKey: string, requestSchemaPayload: object }): Promise<object> {
return this.agentServiceService.credDefEndorsementRequest(payload.url, payload.apiKey, payload.requestSchemaPayload);
}

@MessagePattern({ cmd: 'agent-sign-transaction' })
async signTransaction(payload: { url: string, apiKey: string, signEndorsementPayload:object }): Promise<object> {
async signTransaction(payload: { url: string, apiKey: string, signEndorsementPayload: object }): Promise<object> {
return this.agentServiceService.signTransaction(payload.url, payload.apiKey, payload.signEndorsementPayload);
}
@MessagePattern({ cmd: 'agent-submit-transaction' })
async submitTransaction(payload: { url: string, apiKey: string, submitEndorsementPayload:object }): Promise<object> {
async submitTransaction(payload: { url: string, apiKey: string, submitEndorsementPayload: object }): Promise<object> {
return this.agentServiceService.sumbitTransaction(payload.url, payload.apiKey, payload.submitEndorsementPayload);
}

@MessagePattern({ cmd: 'agent-out-of-band-credential-offer' })
async outOfBandCredentialOffer(payload: { outOfBandIssuancePayload: OutOfBandCredentialOffer, url: string, apiKey: string }): Promise<object> {
return this.agentServiceService.outOfBandCredentialOffer(payload.outOfBandIssuancePayload, payload.url, payload.apiKey);
}

@MessagePattern({ cmd: 'delete-wallet' })
async deleteWallet(payload: { url, apiKey }): Promise<object> {
return this.agentServiceService.deleteWallet(payload.url, payload.apiKey);
}
}
Loading

0 comments on commit dd832d9

Please sign in to comment.