Skip to content

Commit

Permalink
merge: develop to qa (#723)
Browse files Browse the repository at this point in the history
* Docker file changes comment npx generate and migrate

Signed-off-by: KambleSahil3 <[email protected]>

* comment puppeter installation in utility

Signed-off-by: KambleSahil3 <[email protected]>

* yarn.lock fie

Signed-off-by: KambleSahil3 <[email protected]>

* added primsa generate and mirgate in first stage

Signed-off-by: KambleSahil3 <[email protected]>

* refactor: ledger api

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: create schema api

Signed-off-by: bhavanakarwade <[email protected]>

* resolved sonar lint checks

Signed-off-by: bhavanakarwade <[email protected]>

* fix: modify database column name

Signed-off-by: bhavanakarwade <[email protected]>

* fix: modify validation message

Signed-off-by: bhavanakarwade <[email protected]>

* fix: security vulnerabilities

Signed-off-by: pranalidhanavade <[email protected]>

* added only npx deploy in CMD

Signed-off-by: KambleSahil3 <[email protected]>

* fix: security issues

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: env sample

Signed-off-by: bhavanakarwade <[email protected]>

* fix: API error for get credef by id (#656)

Signed-off-by: Krishna <[email protected]>

* refactor: updated webauthn version to latest (9.0.3) (#657)

* fido version updated

Signed-off-by: tipusinghaw <[email protected]>

* fix: email auth issue

Signed-off-by: tipusinghaw <[email protected]>

---------

Signed-off-by: tipusinghaw <[email protected]>

* fix: http method for delete

Signed-off-by: sanjay.khatal <[email protected]>

* refactor: ledger table

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: update import of enum

Signed-off-by: bhavanakarwade <[email protected]>

* fix: added the validation for the pageNumber and pageSize

Signed-off-by: KulkarniShashank <[email protected]>

* refactor: cred-def controller APIs (#661)

* refactor: get all cred defs api

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: cred def controller apis

Signed-off-by: bhavanakarwade <[email protected]>

* resolved comments

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: update import

Signed-off-by: bhavanakarwade <[email protected]>

---------

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: update import of enum

Signed-off-by: bhavanakarwade <[email protected]>

* Changed stage 1:npx commands to migrate and generate in dockerfiles

Signed-off-by: KambleSahil3 <[email protected]>

* fix: added the organization name validation

Signed-off-by: KulkarniShashank <[email protected]>

* fix: validation for UUID fixed for connectionId in proof

Signed-off-by: Krishna <[email protected]>

* fix: path traversal for updating org details

Signed-off-by: Krishna <[email protected]>

* fix: added the validation in connection and ecosystem module for sql-injection

Signed-off-by: KulkarniShashank <[email protected]>

* Removed all unnecessary comments

Signed-off-by: KambleSahil3 <[email protected]>

* refactor: interface parameters

Signed-off-by: bhavanakarwade <[email protected]>

* fix: added the decode URI component in main.ts

Signed-off-by: KulkarniShashank <[email protected]>

* fix: added the messages for the invalid URL

Signed-off-by: KulkarniShashank <[email protected]>

* fix: logo uri validation in image update for org for security testing

Signed-off-by: Krishna <[email protected]>

* fix: update validation for empty string for logo

Signed-off-by: Krishna <[email protected]>

* fix: name validation in update org

Signed-off-by: Krishna <[email protected]>

* refactor:added `outOfBandId` into issuance webhook (#669)

* refactor:added outOfBandId into issuance webhook

Signed-off-by: pallavicoder <[email protected]>

* chore:added type as null and string

Signed-off-by: pallavicoder <[email protected]>

---------

Signed-off-by: pallavicoder <[email protected]>

* feat: multi-did creation implementation for an organization (#667)

* feat: multi did support

Signed-off-by: tipusinghaw <[email protected]>

* refactor: added validation

Signed-off-by: tipusinghaw <[email protected]>

* refactor: added logic for pervious primary DID

Signed-off-by: tipusinghaw <[email protected]>

* refactor: changed primaryDid and added size to did veriable

Signed-off-by: tipusinghaw <[email protected]>

* fix: resloved commits

Signed-off-by: tipusinghaw <[email protected]>

* fix: updated the import url

Signed-off-by: tipusinghaw <[email protected]>

---------

Signed-off-by: tipusinghaw <[email protected]>

* feat: multiselect connection while issuance (#629)

* feat: multiselect connections while issuance

Signed-off-by: bhavanakarwade <[email protected]>

* feat: multi select connections functionality while issuance

Signed-off-by: bhavanakarwade <[email protected]>

* feat: multi select connections

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: modify error message

Signed-off-by: bhavanakarwade <[email protected]>

* fix: resolved comments

Signed-off-by: bhavanakarwade <[email protected]>

* resolved comments

Signed-off-by: bhavanakarwade <[email protected]>

---------

Signed-off-by: bhavanakarwade <[email protected]>

* fix: fix wallet spinup dto issue (#675)

Signed-off-by: tipusinghaw <[email protected]>

* add name attribute in w3c presentationDefinition payload (#678)

Signed-off-by: Ankita Patidar <[email protected]>

* add name attribute in w3c presentationDefinition payload

Signed-off-by: Ankita Patidar <[email protected]>

* add name attribute in w3c presentationDefinition payload

Signed-off-by: Ankita Patidar <[email protected]>

* fix: add hotfixes from main

Signed-off-by: Krishna <[email protected]>

* update validation on creddef field, optional for jsonld

Signed-off-by: Ankita Patidar <[email protected]>

* feat: add organization(s) into ecosystem (#670)

* feat: add self orgs in ecosystem

Signed-off-by: bhavanakarwade <[email protected]>

* feat: update return types

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: error handling

Signed-off-by: bhavanakarwade <[email protected]>

* feat: add role filter in get all organization api

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: get all organizations dto

Signed-off-by: bhavanakarwade <[email protected]>

* feat: apply filter for role

Signed-off-by: bhavanakarwade <[email protected]>

* feat: applied validation for uuid

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: nats message

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: improve error handling

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: applied uuid validation for ecosystemId

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: add organization function

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: added organization functionality

Signed-off-by: bhavanakarwade <[email protected]>

* fix: handled empty array condition

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: added organization into ecosystem with network validation

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: find ecosystem member functionality

Signed-off-by: bhavanakarwade <[email protected]>

---------

Signed-off-by: bhavanakarwade <[email protected]>

* added openssl installation

Signed-off-by: KambleSahil3 <[email protected]>

* Update Dockerfile.utility fixed Sonar cloud issues

Update Dockerfile.utility fixed Sonar cloud issues

Signed-off-by: KambleSahil3 <[email protected]>

* feat: implement w3c credential offer functionality with connection id

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: dto example

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: remove legacy connection invitation

Signed-off-by: KulkarniShashank <[email protected]>

* refactor: solved duplication error in agent-service

Signed-off-by: KulkarniShashank <[email protected]>

* fix: set primary did issue (#691)

Signed-off-by: tipusinghaw <[email protected]>

* Feat/verification w3c with connection (#690)

* Add: w3c verification with connection

Signed-off-by: Krishna <[email protected]>

* Added: validations

Signed-off-by: Krishna <[email protected]>

* Remove commented code

Signed-off-by: Krishna <[email protected]>

* fix: sonarlint issues

Signed-off-by: Krishna <[email protected]>

* fix: sonarlint issues

Signed-off-by: Krishna <[email protected]>

* Add: validations

Signed-off-by: Krishna <[email protected]>

---------

Signed-off-by: Krishna <[email protected]>

* add: zap changes merged from main

Signed-off-by: Krishna <[email protected]>

* feat: w3c credential for issuance by multiple sconnection id

Signed-off-by: bhavanakarwade <[email protected]>

* feat:add-invitation-did-for-reuse-connection

Signed-off-by: pallavicoder <[email protected]>

* feat: fetch all credential definitions from platform (#684)

* feat: get all platform cred defs

Signed-off-by: bhavanakarwade <[email protected]>

* reafctor: modify get all platform cred defs dto

Signed-off-by: bhavanakarwade <[email protected]>

---------

Signed-off-by: bhavanakarwade <[email protected]>

* fix: transaction request message (bug) (#686)

* fix: transaction request message

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: response message

Signed-off-by: bhavanakarwade <[email protected]>

---------

Signed-off-by: bhavanakarwade <[email protected]>

* Added goalCode in OOB presentationRequest payload

Signed-off-by: Ankita Patidar <[email protected]>

* fix: example in DTO

Signed-off-by: Krishna <[email protected]>

* fix: triming issues while getting all credential definitions by schema Id

Signed-off-by: Krishna <[email protected]>

* fix: store did document while creating did (#706)

* fix: set primary did issue

Signed-off-by: tipusinghaw <[email protected]>

* fix: did documentation issue

Signed-off-by: tipusinghaw <[email protected]>

* changes error message in get did details

Signed-off-by: tipusinghaw <[email protected]>

---------

Signed-off-by: tipusinghaw <[email protected]>

* fix/feat : Updated W3C schema response and Implemented schema store logic (#714)

* feat: added logic to store W3C schema

Signed-off-by: tipusinghaw <[email protected]>

* fix: Error messages

Signed-off-by: tipusinghaw <[email protected]>

---------

Signed-off-by: tipusinghaw <[email protected]>

* fix: did service endpoint while creating DID (#715)

* feat: added logic to store W3C schema

Signed-off-by: tipusinghaw <[email protected]>

* fix: Error messages

Signed-off-by: tipusinghaw <[email protected]>

* fix: did endpoint

Signed-off-by: tipusinghaw <[email protected]>

---------

Signed-off-by: tipusinghaw <[email protected]>

* refactor: updated sh file to pass schema manager URL (#716)

* feat: added logic to store W3C schema

Signed-off-by: tipusinghaw <[email protected]>

* fix: Error messages

Signed-off-by: tipusinghaw <[email protected]>

* fix: did endpoint

Signed-off-by: tipusinghaw <[email protected]>

* refactor: updated sh file

Signed-off-by: tipusinghaw <[email protected]>

---------

Signed-off-by: tipusinghaw <[email protected]>

* feat: on-premises agent configuration and spin-up

Signed-off-by: KulkarniShashank <[email protected]>

* fix: example in DTO

Signed-off-by: Krishna <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>

* fix: store did document while creating did (#706)

* fix: set primary did issue

Signed-off-by: tipusinghaw <[email protected]>

* fix: did documentation issue

Signed-off-by: tipusinghaw <[email protected]>

* changes error message in get did details

Signed-off-by: tipusinghaw <[email protected]>

---------

Signed-off-by: tipusinghaw <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>

* feat: on-premises connection invitation creation

Signed-off-by: KulkarniShashank <[email protected]>

* refactor: Added seprate method for agent configure

Signed-off-by: KulkarniShashank <[email protected]>

* fix: solved the sonarlint issues

Signed-off-by: KulkarniShashank <[email protected]>

* fix: solved the docker command as per version

Signed-off-by: KulkarniShashank <[email protected]>

* fix: solved the bug when store the dedicated connection, issuance and verification

Signed-off-by: KulkarniShashank <[email protected]>

* fix: resolved the error handling in agent config method

Signed-off-by: KulkarniShashank <[email protected]>

* fix/feat : Updated W3C schema response and Implemented schema store logic (#714)

* feat: added logic to store W3C schema

Signed-off-by: tipusinghaw <[email protected]>

* fix: Error messages

Signed-off-by: tipusinghaw <[email protected]>

---------

Signed-off-by: tipusinghaw <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>

* fix: did service endpoint while creating DID (#715)

* feat: added logic to store W3C schema

Signed-off-by: tipusinghaw <[email protected]>

* fix: Error messages

Signed-off-by: tipusinghaw <[email protected]>

* fix: did endpoint

Signed-off-by: tipusinghaw <[email protected]>

---------

Signed-off-by: tipusinghaw <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>

* fix: did service endpoint while creating DID (#715)

* feat: added logic to store W3C schema

Signed-off-by: tipusinghaw <[email protected]>

* fix: Error messages

Signed-off-by: tipusinghaw <[email protected]>

* fix: did endpoint

Signed-off-by: tipusinghaw <[email protected]>

---------

Signed-off-by: tipusinghaw <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>

* Added the error logger in agent configure

Signed-off-by: KulkarniShashank <[email protected]>

* fix/feat : Updated W3C schema response and Implemented schema store logic (#714)

* feat: added logic to store W3C schema

Signed-off-by: tipusinghaw <[email protected]>

* fix: Error messages

Signed-off-by: tipusinghaw <[email protected]>

---------

Signed-off-by: tipusinghaw <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>

* fix: validation for inboundEndpoint domain

Signed-off-by: KulkarniShashank <[email protected]>

* fix: remove json files

Signed-off-by: KulkarniShashank <[email protected]>

* fix: remove unnecessary files

Signed-off-by: KulkarniShashank <[email protected]>

* fix: added validation for wallet name

Signed-off-by: KulkarniShashank <[email protected]>

* fix/w3c schema (#721)

* feat: added logic to store W3C schema

Signed-off-by: tipusinghaw <[email protected]>

* fix: Error messages

Signed-off-by: tipusinghaw <[email protected]>

* fix: did endpoint

Signed-off-by: tipusinghaw <[email protected]>

* refactor: updated sh file

Signed-off-by: tipusinghaw <[email protected]>

---------

Signed-off-by: tipusinghaw <[email protected]>

* Added the logger in agent configure function

Signed-off-by: KulkarniShashank <[email protected]>

---------

Signed-off-by: KambleSahil3 <[email protected]>
Signed-off-by: bhavanakarwade <[email protected]>
Signed-off-by: pranalidhanavade <[email protected]>
Signed-off-by: Krishna <[email protected]>
Signed-off-by: tipusinghaw <[email protected]>
Signed-off-by: sanjay.khatal <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>
Signed-off-by: pallavicoder <[email protected]>
Signed-off-by: Ankita Patidar <[email protected]>
Signed-off-by: KambleSahil3 <[email protected]>
Co-authored-by: KambleSahil3 <[email protected]>
Co-authored-by: bhavanakarwade <[email protected]>
Co-authored-by: pranalidhanavade <[email protected]>
Co-authored-by: Sanjay Khatal <[email protected]>
Co-authored-by: Krishna <[email protected]>
Co-authored-by: tipusinghaw <[email protected]>
Co-authored-by: sanjay.khatal <[email protected]>
Co-authored-by: bhavanakarwade <[email protected]>
Co-authored-by: Krishna <[email protected]>
Co-authored-by: Sheetal-ayanworks <[email protected]>
Co-authored-by: pallavighule <[email protected]>
Co-authored-by: Ankita Patidar <[email protected]>
Co-authored-by: Ankita Patidar <[email protected]>
Co-authored-by: Sai Ranjit Tummalapalli <[email protected]>
Co-authored-by: KambleSahil3 <[email protected]>
Co-authored-by: pallavicoder <[email protected]>
  • Loading branch information
17 people committed Sep 11, 2024
1 parent c638723 commit cc47593
Show file tree
Hide file tree
Showing 61 changed files with 1,618 additions and 1,657 deletions.
2 changes: 1 addition & 1 deletion Dockerfiles/Dockerfile.agent-provisioning
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ COPY . .

# Generate Prisma client
# RUN cd libs/prisma-service && npx prisma migrate deploy && npx prisma generate
RUN cd libs/prisma-service && npx prisma migrate deploy && npx prisma generate
RUN cd libs/prisma-service && npx prisma migrate && npx prisma generate
RUN ls -R /app/apps/agent-provisioning/AFJ/

# Build the user service
Expand Down
2 changes: 1 addition & 1 deletion Dockerfiles/Dockerfile.agent-service
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ RUN pnpm i
# Copy the rest of the application code
COPY . .
# RUN cd libs/prisma-service && npx prisma migrate deploy && npx prisma generate
RUN cd libs/prisma-service && npx prisma migrate deploy && npx prisma generate
RUN cd libs/prisma-service && npx prisma migrate && npx prisma generate

# Build the user service
RUN pnpm run build agent-service
Expand Down
341 changes: 341 additions & 0 deletions apps/agent-provisioning/AFJ/scripts/on_premises_agent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,341 @@
#!/bin/bash

START_TIME=$(date +%s)

# Check if Docker is installed
if ! command -v docker &> /dev/null; then
echo "Docker is not installed. Installing Docker..."

# Install Docker
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

# Add the current user to the docker group
sudo usermod -aG docker $USER

# Start and enable the Docker service
sudo systemctl start docker
sudo systemctl enable docker

echo "Docker has been installed."
else
echo "Docker is already installed."
fi

# Function to prompt user for input
prompt_input() {
local prompt_message=$1
local input_variable=$2
read -p "$prompt_message" $input_variable
}

prompt_input_with_tenant_validation() {
local prompt_message=$1
local input_variable=$2
local validation_message=$3

while true; do
read -p "$prompt_message" $input_variable
case "${!input_variable}" in
true | false)
break
;;
*)
echo "$validation_message"
;;
esac
done
}

prompt_input_with_webhook_host_validation() {
local prompt_message=$1
local input_variable=$2
local validation_message=$3INDY_LEDGER_FORMATTED

while true; do
read -p "$prompt_message" $input_variable
local input_value="${!input_variable}"
local ip_address=$(echo "$input_value" | cut -d ':' -f 1 | sed 's/http:\/\///;s/https:\/\///')
local port=$(echo "$input_value" | cut -d ':' -f 3)

if [[ "$input_value" =~ ^http:\/\/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:[0-9]+$ && "$port" =~ ^[0-9]+$ ]]; then
break
elif [[ "$input_value" =~ ^https:\/\/[a-zA-Z0-9.-]+$ ]]; then
break
else
echo "$validation_message"
fi
done
}

# Function to validate INDY_LEDGER input against the provided options
validate_indy_ledger() {
local input_ledger=$1
case "$input_ledger" in
1) echo 'No ledger' ;; # Option for "no ledger"
2) echo 'Polygon' ;; # Option for "polygon"
3) echo '{"genesisTransactions":"http://test.bcovrin.vonx.io/genesis","indyNamespace":"bcovrin:testnet"}' ;;
4) echo '{"genesisTransactions":"https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_testnet_genesis","indyNamespace":"indicio:testnet"}' ;;
5) echo '{"genesisTransactions":"https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_demonet_genesis","indyNamespace":"indicio:demonet"}' ;;
6) echo '{"genesisTransactions":"https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_mainnet_genesis","indyNamespace":"indicio:mainnet"}' ;;
*) echo "Invalid choice" ;;
esac
}

# Prompt user for input
prompt_input "Enter ORGANIZATION_ID: " ORGANIZATION_ID
prompt_input "Enter WALLET_NAME: " WALLET_NAME
prompt_input "Enter WALLET_PASSWORD: " WALLET_PASSWORD

# Prompt user for RANDOM_SEED input and validate it
while true; do
prompt_input "Enter RANDOM_SEED: " RANDOM_SEED
if [ ${#RANDOM_SEED} -eq 32 ]; then
break
else
echo "Error: RANDOM_SEED must be exactly 32 characters."
fi
done

echo "RANDOM_SEED accepted: $RANDOM_SEED"

# Display options to the user for INDY_LEDGER
echo "Choose INDY_LEDGER option(s) (comma-separated, e.g., 1):"
echo "1) No ledger"
echo "2) Polygon"
echo "3) bcovrin:testnet"
echo "4) indicio:testnet"
echo "5) indicio:demonet"
echo "6) indicio:mainnet"

# Prompt user to choose INDY_LEDGER option(s)
INDY_LEDGER=()
read -r INDY_LEDGER_INPUT

# Split the input by commas and process each choice
IFS=',' read -ra CHOICES <<<"$INDY_LEDGER_INPUT"
for choice in "${CHOICES[@]}"; do
choice=$(echo "$choice" | tr -d ' ') # Remove any spaces
case $choice in
1 | 2 | 3 | 4 | 5 | 6)
if [ -n "${INDY_LEDGER}" ]; then
echo "Error: Only one INDY_LEDGER option can be selected."
exit 1
fi
INDY_LEDGER=$(validate_indy_ledger $choice)
;;
*)
echo "Invalid choice: $choice"
;;
esac
done

# Check if "No ledger" or "Polygon" is selected and set INDY_LEDGER_FORMATTED accordingly
if [ "$INDY_LEDGER" = "No ledger" ] || [ "$INDY_LEDGER" = "Polygon" ]; then
INDY_LEDGER_FORMATTED="[]"
else
# Set INDY_LEDGER_FORMATTED based on selected option
INDY_LEDGER_FORMATTED="[$INDY_LEDGER]"
fi

echo "INDY_LEDGER chosen: $INDY_LEDGER"
echo "Formatted INDY_LEDGER: $INDY_LEDGER_FORMATTED"

# Proceed to prompt for other parameters
prompt_input_with_webhook_host_validation "Enter WEBHOOK_HOST (host/domain): " WEBHOOK_HOST "Error: WEBHOOK_HOST must be in the format http://host:port or https://domain."
prompt_input "Enter WALLET_STORAGE_HOST: " WALLET_STORAGE_HOST
prompt_input "Enter WALLET_STORAGE_PORT: " WALLET_STORAGE_PORT
prompt_input "Enter WALLET_STORAGE_USER: " WALLET_STORAGE_USER
prompt_input "Enter WALLET_STORAGE_PASSWORD: " WALLET_STORAGE_PASSWORD
prompt_input "Enter AGENT_NAME: " AGENT_NAME
prompt_input "Enter PROTOCOL: " PROTOCOL
prompt_input_with_tenant_validation "Enter TENANT (true/false): " TENANT "Error: TENANT must be either 'true' or 'false'."
prompt_input "Enter CREDO_IMAGE: " CREDO_IMAGE
prompt_input "Enter INBOUND_ENDPOINT: " INBOUND_ENDPOINT
prompt_input "Enter ADMIN_PORT: " ADMIN_PORT
prompt_input "Enter INBOUND_PORT: " INBOUND_PORT

# Run the command using user input
on_premises_agent.sh --ORGANIZATION_ID "$ORGANIZATION_ID" --WALLET_NAME "$WALLET_NAME" --WALLET_PASSWORD "$WALLET_PASSWORD" --RANDOM_SEED "$RANDOM_SEED" --WEBHOOK_HOST "$WEBHOOK_HOST" --WALLET_STORAGE_HOST "$WALLET_STORAGE_HOST" --WALLET_STORAGE_PORT "$WALLET_STORAGE_PORT" --WALLET_STORAGE_USER "$WALLET_STORAGE_USER" --WALLET_STORAGE_PASSWORD "$WALLET_STORAGE_PASSWORD" --AGENT_NAME "$AGENT_NAME" --PROTOCOL "$PROTOCOL" --TENANT "$TENANT" --CREDO_IMAGE "$CREDO_IMAGE" --INDY_LEDGER "$INDY_LEDGER" --INBOUND_ENDPOINT "$INBOUND_ENDPOINT" --ADMIN_PORT "$ADMIN_PORT" --INBOUND_PORT "$INBOUND_PORT"

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

echo "AGENT SPIN-UP STARTED"

if [ -d "${PWD}/agent-config" ]; then
echo "agent-config directory exists."
else
echo "Error: agent-config directory does not exists."
mkdir ${PWD}/agent-config
fi

# Define a regular expression pattern for IP address
IP_REGEX="^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$"

# Check if the input is a domain
if echo "$INBOUND_ENDPOINT" | grep -qP "^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"; then
echo "INBOUND_ENDPOINT is a domain: $INBOUND_ENDPOINT"
AGENT_ENDPOINT=$INBOUND_ENDPOINT
else
# Check if the input is an IP address
if [[ $INBOUND_ENDPOINT =~ $IP_REGEX ]]; then
echo "INBOUND_ENDPOINT is an IP address: $INBOUND_ENDPOINT"
AGENT_ENDPOINT="${PROTOCOL}://${INBOUND_ENDPOINT}:${INBOUND_PORT}"
else
echo "Invalid input for INBOUND_ENDPOINT: $INBOUND_ENDPOINT"
fi
fi

echo "-----$AGENT_ENDPOINT----"
CONFIG_FILE="${PWD}/agent-config/${ORGANIZATION_ID}_${AGENT_NAME}.json"

# Check if the file exists
if [ -f "$CONFIG_FILE" ]; then
# If it exists, remove the file
rm "$CONFIG_FILE"
fi

cat <<EOF >${CONFIG_FILE}
{
"label": "${ORGANIZATION_ID}_${AGENT_NAME}",
"walletId": "$WALLET_NAME",
"walletKey": "$WALLET_PASSWORD",
"walletType": "postgres",
"walletUrl": "$WALLET_STORAGE_HOST:$WALLET_STORAGE_PORT",
"walletAccount": "$WALLET_STORAGE_USER",
"walletPassword": "$WALLET_STORAGE_PASSWORD",
"walletAdminAccount": "$WALLET_STORAGE_USER",
"walletAdminPassword": "$WALLET_STORAGE_PASSWORD",
"walletScheme": "DatabasePerWallet",
"indyLedger": $INDY_LEDGER_FORMATTED,
"endpoint": [
"$AGENT_ENDPOINT"
],
"autoAcceptConnections": true,
"autoAcceptCredentials": "contentApproved",
"autoAcceptProofs": "contentApproved",
"logLevel": 5,
"inboundTransport": [
{
"transport": "$PROTOCOL",
"port": "$INBOUND_PORT"
}
],
"outboundTransport": [
"$PROTOCOL"
],
"webhookUrl": "$WEBHOOK_HOST/wh/$ORGANIZATION_ID",
"adminPort": "$ADMIN_PORT",
"tenancy": $TENANT
}
EOF

FILE_NAME="docker-compose_${ORGANIZATION_ID}_${AGENT_NAME}.yaml"

DOCKER_COMPOSE="${PWD}/${FILE_NAME}"

# Check if the file exists
if [ -f "$DOCKER_COMPOSE" ]; then
# If it exists, remove the file
rm "$DOCKER_COMPOSE"
fi
cat <<EOF >${DOCKER_COMPOSE}
version: '3'
services:
agent:
image: $CREDO_IMAGE
container_name: ${ORGANIZATION_ID}_${AGENT_NAME}
restart: always
environment:
AFJ_REST_LOG_LEVEL: 1
ports:
- ${INBOUND_PORT}:${INBOUND_PORT}
- ${ADMIN_PORT}:${ADMIN_PORT}
volumes:
- ./agent-config/${ORGANIZATION_ID}_${AGENT_NAME}.json:/config.json
command: --auto-accept-connections --config /config.json
volumes:
pgdata:
agent-indy_client:
agent-tmp:
EOF

if [ $? -eq 0 ]; then
cd ${PWD}
echo "docker-compose generated successfully!"
echo "================="
echo "spinning up the container"
echo "================="
echo "container-name::::::${AGENT_NAME}"
echo "file-name::::::$FILE_NAME"

docker compose -p "${ORGANIZATION_ID}_${AGENT_NAME}" -f $FILE_NAME up -d
if [ $? -eq 0 ]; then

echo "Creating agent config"
# Capture the logs from the container
container_id=$(docker ps -q --filter "name=${ORGANIZATION_ID}_${AGENT_NAME}")

if [ -z "$container_id" ]; then
echo "Error: No container found with name ${ORGANIZATION_ID}_${AGENT_NAME}"
exit 1
fi

# Wait for the container to generate logs
retries=5
delay=10
while [ $retries -gt 0 ]; do
container_logs=$(docker logs "$container_id" 2>/dev/null)
if [ -n "$container_logs" ]; then
break
else
echo "Waiting for logs to be generated..."
sleep $delay
retries=$((retries - 1))
fi
done

if [ -z "$container_logs" ]; then
echo "Error: No logs found for container ${ORGANIZATION_ID}_${AGENT_NAME} after waiting"
exit 1
fi

# Extract the token from the logs using sed
token=$(echo "$container_logs" | sed -nE 's/.*API Token: ([^ ]+).*/\1/p')

if [ -z "$token" ]; then
echo "Error: Failed to extract API token from logs"
exit 1
fi

# Highlight the token line when printing
highlighted_token="Token: \x1b[1;31m$token\x1b[0m"

# Print the extracted token with highlighting
echo -e "$highlighted_token"
echo "Agent config created"

# Check if the token exists to determine if the agent is running
if [ -n "$token" ]; then
echo "Agent is running"
else
echo "Agent is not running"
exit 1
fi

else
echo "==============="
echo "ERROR : Failed to spin up the agent!"
echo "===============" && exit 125
fi
else
echo "ERROR : Failed to execute!" && exit 125
fi

echo "Total time elapsed: $(date -ud "@$(($(date +%s) - $START_TIME))" +%T) (HH:MM:SS)"
2 changes: 1 addition & 1 deletion apps/agent-provisioning/src/agent-provisioning.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class AgentProvisioningService {
const { containerName, externalIp, orgId, seed, walletName, walletPassword, walletStorageHost, walletStoragePassword, walletStoragePort, walletStorageUser, webhookEndpoint, agentType, protocol, credoImage, tenant, indyLedger, inboundEndpoint } = 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}" ${inboundEndpoint} ${process.env.SCHEMA_FILE_SERVER_URL} ${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} ${credoImage} "${indyLedger}" ${inboundEndpoint} ${process.env.SCHEMA_FILE_SERVER_URL} ${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) => {
Expand Down
Loading

0 comments on commit cc47593

Please sign in to comment.