diff --git a/apps/ssi-abstraction/.env.example b/apps/ssi-abstraction/.env.example index 708869532475cb102148eeb805ed1f8d90c1acca..2b2533be2f82ac0fc0e7374bce0c96dbc2ef26fa 100644 --- a/apps/ssi-abstraction/.env.example +++ b/apps/ssi-abstraction/.env.example @@ -11,11 +11,19 @@ AGENT_WALLET_ID=ssi-wallet-id AGENT_WALLET_KEY=ssi-wallet-key AGENT_HOST=http://localhost AGENT_INBOUND_PORT=3001 + AGENT_LEDGER_ID=ID_UNION AGENT_INDY_DID_SEED=00000000000_OCM_E1_Test_Endorser AGENT_INDY_DID=RVKyFidnaqJPznu8bgodDb AGENT_AUTO_ACCEPT_CONNECTION=true AGENT_AUTO_ACCEPT_CREDENTIAL=contentApproved +AGENT_WALLET_STORAGE_TYPE=postgres +AGENT_WALLET_STORAGE_CONFIG_HOST=localhost:5432 +AGENT_WALLET_STORAGE_CONFIG_TIMEOUT=10 +AGENT_WALLET_STORAGE_CREDENTIALS_ACCOUNT=postgres +AGENT_WALLET_STORAGE_CREDENTIALS_PASSWORD=postgres +AGENT_WALLET_STORAGE_CREDENTIALS_ADMIN_ACCOUNT=postgres +AGENT_WALLET_STORAGE_CREDENTIALS_ADMIN_PASSWORD=postgres TAILS_SERVER_BASE_URL=http://localhost:9000 TAILS_SERVER_BUCKET_NAME=ssi diff --git a/apps/ssi-abstraction/deployment/helm/templates/configmap.yaml b/apps/ssi-abstraction/deployment/helm/templates/configmap.yaml index 42062efb52260c66170bbc0e14960281539fab77..80a0616928790b422dd9660183b6e5221c51334a 100644 --- a/apps/ssi-abstraction/deployment/helm/templates/configmap.yaml +++ b/apps/ssi-abstraction/deployment/helm/templates/configmap.yaml @@ -19,4 +19,7 @@ data: AGENT_AUTO_ACCEPT_CREDENTIAL: contentApproved AGENT_LEDGER_ID: BCOVRIN_TEST TAILS_SERVER_BASE_URL: http://ocm-s3.{{ .Release.Namespace }}.svc.cluster.local:9000 - TAILS_SERVER_BUCKET_NAME: ssi \ No newline at end of file + TAILS_SERVER_BUCKET_NAME: ssi + AGENT_WALLET_STORAGE_TYPE: postgres + AGENT_WALLET_STORAGE_CONFIG_HOST: ocm-db.{{ .Release.Namespace }}.svc.cluster.local:5432 + AGENT_WALLET_STORAGE_CONFIG_TIMEOUT: 10 diff --git a/apps/ssi-abstraction/deployment/helm/templates/secret.yaml b/apps/ssi-abstraction/deployment/helm/templates/secret.yaml index 927f613f6e41d730f825b5f77c149d302378420c..103db2bb16054cc15934ab126c03d8d623bcbb14 100644 --- a/apps/ssi-abstraction/deployment/helm/templates/secret.yaml +++ b/apps/ssi-abstraction/deployment/helm/templates/secret.yaml @@ -11,3 +11,7 @@ type: Opaque data: AGENT_WALLET_KEY: M2NhZGZiNzNhYmQwYTEzZjM3NzA0NTI4YWI5Y2YzODY= AGENT_INDY_DID_SEED: NmI4Yjg4MmUyNjE4ZmE1ZDQ1ZWU3MjI5Y2EwMDAwMDA= + AGENT_WALLET_STORAGE_CREDENTIALS_ACCOUNT: postgres + AGENT_WALLET_STORAGE_CREDENTIALS_PASSWORD: postgres + AGENT_WALLET_STORAGE_CREDENTIALS_ADMIN_ACCOUNT: postgres + AGENT_WALLET_STORAGE_CREDENTIALS_ADMIN_PASSWORD: postgres diff --git a/apps/ssi-abstraction/src/agent/agent.service.ts b/apps/ssi-abstraction/src/agent/agent.service.ts index 2aba394d86c157d96431ed06bd42d57b355faae6..efcaf8e52e02a0f490f2c922ec879fc7a920b21c 100644 --- a/apps/ssi-abstraction/src/agent/agent.service.ts +++ b/apps/ssi-abstraction/src/agent/agent.service.ts @@ -1,5 +1,5 @@ import type { LedgerIds } from '../config/ledger.js'; -import type { InitConfig } from '@credo-ts/core'; +import type { InitConfig, WalletConfig } from '@credo-ts/core'; import type { IndyVdrPoolConfig } from '@credo-ts/indy-vdr'; import type { OnApplicationShutdown } from '@nestjs/common'; @@ -83,16 +83,47 @@ export class AgentService implements OnApplicationShutdown { } public get config(): InitConfig { - const { name, walletId, walletKey, host, inboundPort, path } = - this.configService.get('agent'); + const { + name, + walletId, + walletKey, + host, + inboundPort, + path, + walletStorageType, + walletStorageConfig, + walletStorageCredentials, + } = this.configService.get('agent'); const endpoints = [`${host}:${inboundPort}${path}`]; + let walletStorage: WalletConfig['storage']; + + if (walletStorageType && walletStorageType === 'postgres') { + walletStorage = { + type: walletStorageType, + config: { + host: walletStorageConfig.host, + connectionTimeout: walletStorageConfig.timeout, + }, + }; + + if (walletStorageCredentials) { + walletStorage.credentials = { + account: walletStorageCredentials.account, + password: walletStorageCredentials.password, + adminAccount: walletStorageCredentials.adminAccount, + adminPassword: walletStorageCredentials.adminPassword, + }; + } + } + return { label: name, walletConfig: { id: walletId, key: walletKey, + storage: walletStorage, }, endpoints, logger: new AgentLogger(LogLevel.debug), diff --git a/apps/ssi-abstraction/src/config/agent.config.ts b/apps/ssi-abstraction/src/config/agent.config.ts index 22884d6fb57ad5cf2702feec4a6a570eb8d806d1..a15fcc83e3678f17f0bf4031f49feca9c09e430f 100644 --- a/apps/ssi-abstraction/src/config/agent.config.ts +++ b/apps/ssi-abstraction/src/config/agent.config.ts @@ -5,6 +5,19 @@ export const agentConfig = registerAs('agent', () => ({ name: process.env.AGENT_NAME || '', walletId: process.env.AGENT_WALLET_ID || '', walletKey: process.env.AGENT_WALLET_KEY || '', + walletStorageType: process.env.AGENT_WALLET_STORAGE_TYPE || '', + walletStorageConfig: { + host: process.env.AGENT_WALLET_STORAGE_CONFIG_HOST || '', + timeout: Number(process.env.AGENT_WALLET_STORAGE_CONFIG_TIMEOUT || '0'), + }, + walletStorageCredentials: { + account: process.env.AGENT_WALLET_STORAGE_CREDENTIALS_ACCOUNT || '', + password: process.env.AGENT_WALLET_STORAGE_CREDENTIALS_PASSWORD || '', + adminAccount: + process.env.AGENT_WALLET_STORAGE_CREDENTIALS_ADMIN_ACCOUNT || '', + adminPassword: + process.env.AGENT_WALLET_STORAGE_CREDENTIALS_ADMIN_PASSWORD || '', + }, ledgerIds: process.env.AGENT_LEDGER_ID?.split(',') || [], indyDidSeed: process.env.AGENT_INDY_DID_SEED || '', indyDid: process.env.AGENT_INDY_DID || '', diff --git a/apps/ssi-abstraction/src/config/validation.ts b/apps/ssi-abstraction/src/config/validation.ts index 31887bb5c658cd4ab64ffee8276d7fa92bd0b6a3..b692fdf6398fa3897d8b47ac738e1bf8c9993389 100644 --- a/apps/ssi-abstraction/src/config/validation.ts +++ b/apps/ssi-abstraction/src/config/validation.ts @@ -29,4 +29,15 @@ export const validationSchema = Joi.object({ AGENT_LEDGER_ID: Joi.string().required(), AGENT_INDY_DID_SEED: Joi.string().required(), AGENT_INDY_DID: Joi.string().optional(), + + AGENT_WALLET_STORAGE_TYPE: Joi.valid('postgres'), + AGENT_WALLET_STORAGE_CONFIG_HOST: Joi.when('AGENT_WALLET_STORAGE_TYPE', { + is: 'postgres', + then: Joi.string().uri().required(), + }), + AGENT_WALLET_STORAGE_CONFIG_TIMEOUT: Joi.number(), + AGENT_WALLET_STORAGE_CREDENTIALS_ACCOUNT: Joi.string(), + AGENT_WALLET_STORAGE_CREDENTIALS_PASSWORD: Joi.string(), + AGENT_WALLET_STORAGE_CREDENTIALS_ADMIN_ACCOUNT: Joi.string(), + AGENT_WALLET_STORAGE_CREDENTIALS_ADMIN_PASSWORD: Joi.string(), }); diff --git a/docker-compose.yml b/docker-compose.yml index 5a018b4d14cb5aee8610b281edb6f20f69c3298d..6d13657923fa27f5defd728c67910b121ecebcbc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,7 @@ services: nats: image: nats ports: + - ${NATS_PORT:-4222}:4222 #Nats server port` - ${NATS_MONITORING_PORT:-8222}:8222 #Nats server Monitoring port command: [ @@ -19,6 +20,9 @@ services: s3: image: minio/minio + ports: + - ${S3_PORT:-9000}:9000 + - ${S3_CONSOLE_PORT:-9001}:9001 environment: MINIO_ROOT_USER: minio MINIO_ROOT_PASSWORD: minio123 @@ -41,6 +45,15 @@ services: depends_on: - s3 + postgres: + image: postgres + ports: + - ${POSTGRES_PORT:-5432}:5432 + volumes: + - postgresql-data:/var/lib/postgresql/data + environment: + POSTGRES_PASSWORD: postgres + ssi-abstraction: build: args: @@ -63,6 +76,13 @@ services: AGENT_INDY_DID_SEED: 6b8b882e2618fa5d45ee7229ca000000 AGENT_AUTO_ACCEPT_CONNECTION: true AGENT_AUTO_ACCEPT_CREDENTIAL: contentApproved + AGENT_WALLET_STORAGE_TYPE: postgres + AGENT_WALLET_STORAGE_CONFIG_HOST: postgres:5432 + AGENT_WALLET_STORAGE_CONFIG_TIMEOUT: 10 + AGENT_WALLET_STORAGE_CREDENTIALS_ACCOUNT: postgres + AGENT_WALLET_STORAGE_CREDENTIALS_PASSWORD: postgres + AGENT_WALLET_STORAGE_CREDENTIALS_ADMIN_ACCOUNT: postgres + AGENT_WALLET_STORAGE_CREDENTIALS_ADMIN_PASSWORD: postgres TAILS_SERVER_BASE_URL: http://s3:9000 TAILS_SERVER_BUCKET_NAME: ssi S3_ACCESS_KEY: ssi-abstraction @@ -70,6 +90,7 @@ services: depends_on: - nats - init-s3 + - postgres schema-manager: build: @@ -171,3 +192,6 @@ services: - '${TENANT_MANAGER_PORT:-4007}:3000' depends_on: - nats + +volumes: + postgresql-data: diff --git a/scripts/start_instance.sh b/scripts/start_instance.sh index 499bef0f8cdd9f413c7528abb720516922c132b1..fba397f366bf761eaca5abf0414fbbd775b66da0 100755 --- a/scripts/start_instance.sh +++ b/scripts/start_instance.sh @@ -9,7 +9,23 @@ base_DID_MANAGER_PORT=5005 base_TENANT_MANAGER_PORT=5006 base_SSI_PORT=5007 base_SSI_AGENT_PORT=5008 -base_NATS_MONITORING_PORT=5009 +base_NATS_PORT=5009 +base_NATS_MONITORING_PORT=5010 +base_S3_PORT=5011 +base_S3_CONSOLE_PORT=5012 +base_POSTGRES_PORT=5013 + +# Initialize docker_compose_options as an empty string +docker_compose_options="" + +# Parse command-line arguments +while [[ "$#" -gt 0 ]]; do + case $1 in + --rebuild) docker_compose_options="--build";; + *) echo "Unknown parameter passed: $1"; exit 1;; + esac + shift +done # Step 1: Get all running Docker Compose instances and extract the project numbers running_instances=$(docker compose ls --format json | jq -r '.[].Name') @@ -27,7 +43,7 @@ done new_number=$((max_number + 1)) # Calculate new port numbers based on new_number -increment=$((new_number * 10)) +increment=$((new_number * 100)) # Export the new port numbers export SCHEMA_MANAGER_PORT=$((base_SCHEMA_MANAGER_PORT + increment)) @@ -38,16 +54,20 @@ export DID_MANAGER_PORT=$((base_DID_MANAGER_PORT + increment)) export TENANT_MANAGER_PORT=$((base_TENANT_MANAGER_PORT + increment)) export SSI_PORT=$((base_SSI_PORT + increment)) export SSI_AGENT_PORT=$((base_SSI_AGENT_PORT + increment)) +export NATS_PORT=$((base_NATS_PORT + increment)) export NATS_MONITORING_PORT=$((base_NATS_MONITORING_PORT + increment)) +export S3_PORT=$((base_S3_PORT + increment)) +export S3_CONSOLE_PORT=$((base_S3_CONSOLE_PORT + increment)) +export POSTGRES_PORT=$((base_POSTGRES_PORT + increment)) # Proceed with starting the instance -docker compose -p "ocm-$new_number" up -d +docker compose -p "ocm-$new_number" up -d $docker_compose_options # Output the ports in a tabular view after the instance has started echo -echo "Service Port Assignments for ocm-$new_number:" +echo "Port Assignments for ocm-$new_number:" echo -printf "%-25s %-10s\n" "SERVICE" "PORT" +printf "%-25s %-10s\n" "VARIABLE" "PORT" printf '%-25s %-10s\n' '-------------------------' '----------' printf "%-25s %-10s\n" SCHEMA_MANAGER_PORT $SCHEMA_MANAGER_PORT printf "%-25s %-10s\n" CONNECTION_MANAGER_PORT $CONNECTION_MANAGER_PORT @@ -57,4 +77,8 @@ printf "%-25s %-10s\n" DID_MANAGER_PORT $DID_MANAGER_PORT printf "%-25s %-10s\n" TENANT_MANAGER_PORT $TENANT_MANAGER_PORT printf "%-25s %-10s\n" SSI_PORT $SSI_PORT printf "%-25s %-10s\n" SSI_AGENT_PORT $SSI_AGENT_PORT +printf "%-25s %-10s\n" NATS_PORT $NATS_PORT printf "%-25s %-10s\n" NATS_MONITORING_PORT $NATS_MONITORING_PORT +printf "%-25s %-10s\n" S3_PORT $S3_PORT +printf "%-25s %-10s\n" S3_CONSOLE_PORT $S3_CONSOLE_PORT +printf "%-25s %-10s\n" POSTGRES_PORT $POSTGRES_PORT