From b427d75ddde62046d10fdd704029b4f3035ffe97 Mon Sep 17 00:00:00 2001 From: Alexey Lunin <alexey.lunin@vereign.com> Date: Thu, 23 May 2024 09:24:07 +0000 Subject: [PATCH] refactor: refactor environment variables and applications OP#244 --- .env.example | 22 - .gitlab-ci.yml | 182 +---- README.md | 37 +- apps/agent/deployment/ci-cd/Dockerfile | 3 +- .../ci-cd/helm/templates/deployment.yaml | 65 -- .../ci-cd/helm/templates/ingress.yaml | 18 - apps/agent/deployment/ci-cd/helm/values.yaml | 76 -- apps/agent/src/app/app.module.ts | 9 +- apps/attestation-manager/README.md | 28 - .../deployment/ci-cd/helm/Chart.yaml | 6 - .../ci-cd/helm/templates/deployment.yaml | 73 -- .../deployment/ci-cd/helm/templates/hpa.yaml | 27 - .../ci-cd/helm/templates/service.yaml | 16 - .../deployment/ci-cd/helm/values.yaml | 112 --- .../deployment/local/Dockerfile | 16 - apps/attestation-manager/project.json | 63 -- .../src/app/app.controller.ts | 122 ---- .../attestation-manager/src/app/app.module.ts | 25 - apps/attestation-manager/src/main.ts | 37 - apps/connection-manager/.eslintrc.json | 18 - apps/connection-manager/README.md | 27 - .../deployment/ci-cd/Dockerfile | 37 - .../deployment/ci-cd/helm/Chart.yaml | 6 - .../ci-cd/helm/templates/_helpers.tpl | 94 --- .../ci-cd/helm/templates/deployment.yaml | 73 -- .../deployment/ci-cd/helm/templates/hpa.yaml | 27 - .../ci-cd/helm/templates/service.yaml | 16 - .../deployment/ci-cd/helm/values.yaml | 112 --- .../deployment/local/Dockerfile | 16 - apps/connection-manager/jest.config.ts | 11 - apps/connection-manager/project.json | 63 -- .../src/app/app.controller.ts | 52 -- apps/connection-manager/src/app/app.module.ts | 25 - apps/connection-manager/src/main.ts | 36 - apps/connection-manager/tsconfig.app.json | 12 - apps/connection-manager/tsconfig.json | 16 - apps/connection-manager/tsconfig.spec.json | 14 - apps/connection-manager/webpack.config.js | 8 - apps/gateway/.eslintrc.json | 18 - apps/gateway/README.md | 30 - apps/gateway/deployment/ci-cd/Dockerfile | 39 -- .../ci-cd/helm/templates/_helpers.tpl | 94 --- .../ci-cd/helm/templates/deployment.yaml | 97 --- .../deployment/ci-cd/helm/templates/hpa.yaml | 27 - .../gateway/deployment/ci-cd/helm/values.yaml | 156 ----- apps/gateway/deployment/local/Dockerfile | 17 - apps/gateway/jest.config.ts | 11 - apps/gateway/src/app/app.controller.ts | 33 - apps/gateway/src/app/app.module.ts | 61 -- .../src/app/decorators/IncludeOcmDtos.ts | 16 - .../src/app/decorators/OcmGatewayResponse.ts | 16 - .../OcmInternalServerErrorResponse.ts | 30 - apps/gateway/src/app/events.gateway.ts | 17 - apps/gateway/src/app/exception.handler.ts | 39 -- .../app/managers/attestation.controller.ts | 657 ------------------ .../src/app/managers/connection.controller.ts | 177 ----- .../src/app/managers/proof.controller.ts | 205 ------ apps/gateway/src/main.ts | 74 -- apps/gateway/tsconfig.app.json | 12 - apps/gateway/tsconfig.json | 16 - apps/gateway/tsconfig.spec.json | 14 - apps/gateway/webpack.config.js | 8 - .../.eslintrc.json | 0 apps/hin-agent/README.md | 32 + .../deployment/ci-cd/Dockerfile | 15 +- .../deployment/ci-cd/helm/Chart.yaml | 4 +- .../ci-cd/helm/templates/_helpers.tpl | 0 .../ci-cd/helm/templates/deployment.yaml | 92 +++ .../ci-cd/helm/templates/ingress.yaml | 18 +- .../ci-cd/helm/templates/service.yaml | 6 +- .../deployment/ci-cd/helm/values.yaml | 100 +++ .../deployment/local/Dockerfile | 8 +- apps/hin-agent/deployment/local/HinDockerfile | 15 + .../jest.config.ts | 6 +- apps/{gateway => hin-agent}/project.json | 23 +- apps/hin-agent/src/app/app.module.ts | 37 + .../src/app/config/hin.config.interface.ts | 7 + apps/hin-agent/src/app/config/hin.config.ts | 17 + apps/hin-agent/src/app/config/hin.schema.ts | 9 + .../app/svdx/agent-event-listener.service.ts | 105 +++ apps/hin-agent/src/app/svdx/svdx.utils.ts | 163 +++++ apps/hin-agent/src/main.ts | 52 ++ .../tsconfig.app.json | 0 .../tsconfig.json | 0 .../tsconfig.spec.json | 0 .../webpack.config.js | 0 apps/proof-manager/.eslintrc.json | 18 - apps/proof-manager/README.md | 27 - .../proof-manager/deployment/ci-cd/Dockerfile | 38 - .../deployment/ci-cd/helm/Chart.yaml | 6 - .../ci-cd/helm/templates/_helpers.tpl | 94 --- .../ci-cd/helm/templates/deployment.yaml | 73 -- .../deployment/ci-cd/helm/templates/hpa.yaml | 27 - .../ci-cd/helm/templates/service.yaml | 16 - .../deployment/ci-cd/helm/values.yaml | 112 --- apps/proof-manager/jest.config.ts | 11 - apps/proof-manager/project.json | 63 -- apps/proof-manager/src/app/app.controller.ts | 52 -- apps/proof-manager/src/app/app.module.ts | 25 - apps/proof-manager/src/main.ts | 37 - apps/proof-manager/tsconfig.app.json | 12 - apps/proof-manager/tsconfig.json | 16 - apps/proof-manager/tsconfig.spec.json | 14 - apps/proof-manager/webpack.config.js | 8 - compose/docker-compose.infra.yml | 10 - compose/docker-compose.yml | 192 ----- compose/env/holder.env | 28 +- compose/env/holder.simple.env | 27 +- compose/env/issuer.env | 27 +- compose/env/issuer.simple.env | 27 +- libs/askar/src/agent.utils.ts | 162 ----- .../src/askar-nats/agent.consumer.service.ts | 56 -- .../askar/src/askar-nats/askar.nats.module.ts | 42 -- .../src/askar-nats/event.handler.service.ts | 208 ------ libs/askar/src/askar-rest/auth/auth.guard.ts | 20 +- libs/askar/src/askar.dynamic.module.ts | 11 +- libs/askar/src/askar/askar.module.ts | 4 - .../services/agent-event-listener.service.ts | 128 ---- libs/clients/src/backend.ts | 4 - .../src/backend/attestation.manager.client.ts | 62 -- .../src/backend/connection.manager.client.ts | 57 -- libs/clients/src/backend/gateway.client.ts | 36 - .../src/backend/proof.manager.client.ts | 53 -- libs/config/src/config/agent.config.ts | 22 +- libs/config/src/config/attestation.manager.ts | 11 - libs/config/src/config/auth.config.ts | 15 + .../src/config/connection.manager.config.ts | 11 - libs/config/src/config/gateway.config.ts | 13 - libs/config/src/config/nats.config.ts | 18 - libs/config/src/config/proof.manager.ts | 11 - libs/config/src/index.ts | 17 +- .../src/interfaces/agent.config.interface.ts | 18 +- .../attestation.manager.config.interface.ts | 4 - .../src/interfaces/auth.config.interface.ts | 7 + .../connection.manager.config.interface.ts | 4 - .../interfaces/gateway.config.interface.ts | 6 - .../src/interfaces/nats.config.interface.ts | 5 - .../proof.manager.config.interface.ts | 4 - libs/config/src/schemas/agent.schema.ts | 10 +- .../src/schemas/attestation.manager.schema.ts | 6 - libs/config/src/schemas/auth.schema.ts | 6 +- .../src/schemas/connection.manager.schema.ts | 6 - libs/config/src/schemas/gateway.schema.ts | 8 - libs/config/src/schemas/nats.schema.ts | 7 - .../src/schemas/proof.manager.schema.ts | 6 - libs/dtos/src/events/dtoToEventTransformer.ts | 54 -- libs/dtos/src/events/event.ts | 49 -- libs/dtos/src/events/types.ts | 115 --- libs/dtos/src/index.ts | 4 - libs/nats/.eslintrc.json | 18 - libs/nats/README.md | 0 libs/nats/jest.config.ts | 0 libs/nats/package.json | 5 - libs/nats/project.json | 41 -- libs/nats/src/base.nats.service.ts | 108 --- libs/nats/src/consumer.nats.service.ts | 102 --- libs/nats/src/index.ts | 3 - libs/nats/src/nats.module.ts | 12 - libs/nats/src/producer.nats.service.ts | 21 - libs/nats/tsconfig.json | 22 - libs/nats/tsconfig.lib.json | 16 - libs/nats/tsconfig.spec.json | 14 - package.json | 21 +- tsconfig.base.json | 3 +- yarn.lock | 100 +-- 165 files changed, 807 insertions(+), 6092 deletions(-) delete mode 100644 apps/attestation-manager/README.md delete mode 100644 apps/attestation-manager/deployment/ci-cd/helm/Chart.yaml delete mode 100644 apps/attestation-manager/deployment/ci-cd/helm/templates/deployment.yaml delete mode 100644 apps/attestation-manager/deployment/ci-cd/helm/templates/hpa.yaml delete mode 100644 apps/attestation-manager/deployment/ci-cd/helm/templates/service.yaml delete mode 100644 apps/attestation-manager/deployment/ci-cd/helm/values.yaml delete mode 100644 apps/attestation-manager/deployment/local/Dockerfile delete mode 100644 apps/attestation-manager/project.json delete mode 100644 apps/attestation-manager/src/app/app.controller.ts delete mode 100644 apps/attestation-manager/src/app/app.module.ts delete mode 100644 apps/attestation-manager/src/main.ts delete mode 100644 apps/connection-manager/.eslintrc.json delete mode 100644 apps/connection-manager/README.md delete mode 100644 apps/connection-manager/deployment/ci-cd/Dockerfile delete mode 100644 apps/connection-manager/deployment/ci-cd/helm/Chart.yaml delete mode 100644 apps/connection-manager/deployment/ci-cd/helm/templates/_helpers.tpl delete mode 100644 apps/connection-manager/deployment/ci-cd/helm/templates/deployment.yaml delete mode 100644 apps/connection-manager/deployment/ci-cd/helm/templates/hpa.yaml delete mode 100644 apps/connection-manager/deployment/ci-cd/helm/templates/service.yaml delete mode 100644 apps/connection-manager/deployment/ci-cd/helm/values.yaml delete mode 100644 apps/connection-manager/deployment/local/Dockerfile delete mode 100644 apps/connection-manager/jest.config.ts delete mode 100644 apps/connection-manager/project.json delete mode 100644 apps/connection-manager/src/app/app.controller.ts delete mode 100644 apps/connection-manager/src/app/app.module.ts delete mode 100644 apps/connection-manager/src/main.ts delete mode 100644 apps/connection-manager/tsconfig.app.json delete mode 100644 apps/connection-manager/tsconfig.json delete mode 100644 apps/connection-manager/tsconfig.spec.json delete mode 100644 apps/connection-manager/webpack.config.js delete mode 100644 apps/gateway/.eslintrc.json delete mode 100644 apps/gateway/README.md delete mode 100644 apps/gateway/deployment/ci-cd/Dockerfile delete mode 100644 apps/gateway/deployment/ci-cd/helm/templates/_helpers.tpl delete mode 100644 apps/gateway/deployment/ci-cd/helm/templates/deployment.yaml delete mode 100644 apps/gateway/deployment/ci-cd/helm/templates/hpa.yaml delete mode 100644 apps/gateway/deployment/ci-cd/helm/values.yaml delete mode 100644 apps/gateway/deployment/local/Dockerfile delete mode 100644 apps/gateway/jest.config.ts delete mode 100644 apps/gateway/src/app/app.controller.ts delete mode 100644 apps/gateway/src/app/app.module.ts delete mode 100644 apps/gateway/src/app/decorators/IncludeOcmDtos.ts delete mode 100644 apps/gateway/src/app/decorators/OcmGatewayResponse.ts delete mode 100644 apps/gateway/src/app/decorators/OcmInternalServerErrorResponse.ts delete mode 100644 apps/gateway/src/app/events.gateway.ts delete mode 100644 apps/gateway/src/app/exception.handler.ts delete mode 100644 apps/gateway/src/app/managers/attestation.controller.ts delete mode 100644 apps/gateway/src/app/managers/connection.controller.ts delete mode 100644 apps/gateway/src/app/managers/proof.controller.ts delete mode 100644 apps/gateway/src/main.ts delete mode 100644 apps/gateway/tsconfig.app.json delete mode 100644 apps/gateway/tsconfig.json delete mode 100644 apps/gateway/tsconfig.spec.json delete mode 100644 apps/gateway/webpack.config.js rename apps/{attestation-manager => hin-agent}/.eslintrc.json (100%) create mode 100644 apps/hin-agent/README.md rename apps/{attestation-manager => hin-agent}/deployment/ci-cd/Dockerfile (75%) rename apps/{gateway => hin-agent}/deployment/ci-cd/helm/Chart.yaml (73%) rename apps/{attestation-manager => hin-agent}/deployment/ci-cd/helm/templates/_helpers.tpl (100%) create mode 100644 apps/hin-agent/deployment/ci-cd/helm/templates/deployment.yaml rename apps/{gateway => hin-agent}/deployment/ci-cd/helm/templates/ingress.yaml (63%) rename apps/{gateway => hin-agent}/deployment/ci-cd/helm/templates/service.yaml (79%) create mode 100644 apps/hin-agent/deployment/ci-cd/helm/values.yaml rename apps/{proof-manager => hin-agent}/deployment/local/Dockerfile (74%) create mode 100644 apps/hin-agent/deployment/local/HinDockerfile rename apps/{attestation-manager => hin-agent}/jest.config.ts (67%) rename apps/{gateway => hin-agent}/project.json (71%) create mode 100644 apps/hin-agent/src/app/app.module.ts create mode 100644 apps/hin-agent/src/app/config/hin.config.interface.ts create mode 100644 apps/hin-agent/src/app/config/hin.config.ts create mode 100644 apps/hin-agent/src/app/config/hin.schema.ts create mode 100644 apps/hin-agent/src/app/svdx/agent-event-listener.service.ts create mode 100644 apps/hin-agent/src/app/svdx/svdx.utils.ts create mode 100644 apps/hin-agent/src/main.ts rename apps/{attestation-manager => hin-agent}/tsconfig.app.json (100%) rename apps/{attestation-manager => hin-agent}/tsconfig.json (100%) rename apps/{attestation-manager => hin-agent}/tsconfig.spec.json (100%) rename apps/{attestation-manager => hin-agent}/webpack.config.js (100%) delete mode 100644 apps/proof-manager/.eslintrc.json delete mode 100644 apps/proof-manager/README.md delete mode 100644 apps/proof-manager/deployment/ci-cd/Dockerfile delete mode 100644 apps/proof-manager/deployment/ci-cd/helm/Chart.yaml delete mode 100644 apps/proof-manager/deployment/ci-cd/helm/templates/_helpers.tpl delete mode 100644 apps/proof-manager/deployment/ci-cd/helm/templates/deployment.yaml delete mode 100644 apps/proof-manager/deployment/ci-cd/helm/templates/hpa.yaml delete mode 100644 apps/proof-manager/deployment/ci-cd/helm/templates/service.yaml delete mode 100644 apps/proof-manager/deployment/ci-cd/helm/values.yaml delete mode 100644 apps/proof-manager/jest.config.ts delete mode 100644 apps/proof-manager/project.json delete mode 100644 apps/proof-manager/src/app/app.controller.ts delete mode 100644 apps/proof-manager/src/app/app.module.ts delete mode 100644 apps/proof-manager/src/main.ts delete mode 100644 apps/proof-manager/tsconfig.app.json delete mode 100644 apps/proof-manager/tsconfig.json delete mode 100644 apps/proof-manager/tsconfig.spec.json delete mode 100644 apps/proof-manager/webpack.config.js delete mode 100644 libs/askar/src/askar-nats/agent.consumer.service.ts delete mode 100644 libs/askar/src/askar-nats/askar.nats.module.ts delete mode 100644 libs/askar/src/askar-nats/event.handler.service.ts delete mode 100644 libs/askar/src/askar/services/agent-event-listener.service.ts delete mode 100644 libs/clients/src/backend.ts delete mode 100644 libs/clients/src/backend/attestation.manager.client.ts delete mode 100644 libs/clients/src/backend/connection.manager.client.ts delete mode 100644 libs/clients/src/backend/gateway.client.ts delete mode 100644 libs/clients/src/backend/proof.manager.client.ts delete mode 100644 libs/config/src/config/attestation.manager.ts create mode 100644 libs/config/src/config/auth.config.ts delete mode 100644 libs/config/src/config/connection.manager.config.ts delete mode 100644 libs/config/src/config/gateway.config.ts delete mode 100644 libs/config/src/config/nats.config.ts delete mode 100644 libs/config/src/config/proof.manager.ts delete mode 100644 libs/config/src/interfaces/attestation.manager.config.interface.ts create mode 100644 libs/config/src/interfaces/auth.config.interface.ts delete mode 100644 libs/config/src/interfaces/connection.manager.config.interface.ts delete mode 100644 libs/config/src/interfaces/gateway.config.interface.ts delete mode 100644 libs/config/src/interfaces/nats.config.interface.ts delete mode 100644 libs/config/src/interfaces/proof.manager.config.interface.ts delete mode 100644 libs/config/src/schemas/attestation.manager.schema.ts delete mode 100644 libs/config/src/schemas/connection.manager.schema.ts delete mode 100644 libs/config/src/schemas/gateway.schema.ts delete mode 100644 libs/config/src/schemas/nats.schema.ts delete mode 100644 libs/config/src/schemas/proof.manager.schema.ts delete mode 100644 libs/dtos/src/events/dtoToEventTransformer.ts delete mode 100644 libs/dtos/src/events/event.ts delete mode 100644 libs/dtos/src/events/types.ts delete mode 100644 libs/nats/.eslintrc.json delete mode 100644 libs/nats/README.md delete mode 100644 libs/nats/jest.config.ts delete mode 100644 libs/nats/package.json delete mode 100644 libs/nats/project.json delete mode 100644 libs/nats/src/base.nats.service.ts delete mode 100644 libs/nats/src/consumer.nats.service.ts delete mode 100644 libs/nats/src/index.ts delete mode 100644 libs/nats/src/nats.module.ts delete mode 100644 libs/nats/src/producer.nats.service.ts delete mode 100644 libs/nats/tsconfig.json delete mode 100644 libs/nats/tsconfig.lib.json delete mode 100644 libs/nats/tsconfig.spec.json diff --git a/.env.example b/.env.example index bd94b654..85faa037 100644 --- a/.env.example +++ b/.env.example @@ -12,28 +12,6 @@ AGENT_DB_HOST=0.0.0.0:5432 AGENT_DB_USER=postgres AGENT_DB_PASS=postgres AGENT_PORT=8001 -AGENT_CONSUMER_NAME=agent_1 -AGENT_IS_REST=false -AGENT_MAX_MESSAGES=10 -AGENT_RETE_LIMIT=5 - -NATS_SERVERS=0.0.0.0:4222 -NATS_STREAM_NAME=ssi_stream -NATS_SUBJECTS="connections.*,proofs.*,credentials.*,credentials.definition.*,credentials.offer.*,schemas.*,messages.*" - -GATEWAY_HTTP_PORT=8081 -GATEWAY_TCP_PORT=8881 -GATEWAY_MESSAGE_PATTERN=webhook -GATEWAY_HOST=0.0.0.0 - -CONNECTION_SERVICE_TCP_PORT=8882 -CONNECTION_SERVICE_HOST=0.0.0.0 - -ATTESTATION_SERVICE_TCP_PORT=8883 -ATTESTATION_SERVICE_HOST=0.0.0.0 - -PROOF_SERVICE_TCP_PORT=8884 -PROOF_SERVICE_HOST=0.0.0.0 ALLOWED_ORIGINS=* SWAGGER=false diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c7b85dc2..c2357d1d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,155 +19,83 @@ lint-agent: extends: .lint-agent stage: lint +lint-hin-agent: + extends: .lint-hin-agent + stage: lint + # lint-dashboard: # extends: .lint-dashboard # stage: lint -# lint-attestation-manager: -# extends: .lint-attestation-manager -# stage: lint - -# lint-connection-manager: -# extends: .lint-connection-manager -# stage: lint - -# lint-proof-manager: -# extends: .lint-proof-manager -# stage: lint - -# lint-gateway: -# extends: .lint-gateway -# stage: lint - # Test microservices test-agent: extends: .test-agent stage: test +test-hin-agent: + extends: .test-hin-agent + stage: test # test-dashboard: # extends: .test-dashboard # stage: test -# test-attestation-manager: -# extends: .test-attestation-manager -# stage: test - -# test-connection-manager: -# extends: .test-connection-manager -# stage: test - -# test-proof-manager: -# extends: .test-proof-manager -# stage: test - -# test-gateway: -# extends: .test-gateway -# stage: test - # Bare microservice build build-agent: extends: .build-agent stage: build +build-hin-agent: + extends: .build-hin-agent + stage: build + build-dashboard: extends: .build-dashboard stage: build -# build-attestation-manager: -# extends: .build-attestation-manager -# stage: build - -# build-connection-manager: -# extends: .build-connection-manager -# stage: build - -# build-proof-manager: -# extends: .build-proof-manager -# stage: build - -# build-gateway: -# extends: .build-gateway -# stage: build - # Docker build microservices docker-agent: extends: .docker-agent stage: docker +docker-hin-agent: + extends: .docker-hin-agent + stage: docker + docker-dashboard: extends: .docker-dashboard stage: docker -# docker-attestation-manager: -# extends: .docker-attestation-manager -# stage: docker - -# docker-connection-manager: -# extends: .docker-connection-manager -# stage: docker - -# docker-proof-manager: -# extends: .docker-proof-manager -# stage: docker - -# docker-gateway: -# extends: .docker-gateway -# stage: docker - # Push to registries registry-agent: extends: .registry-agent stage: registries +registry-hin-agent: + extends: .registry-hin-agent + stage: registries + registry-dashboard: extends: .registry-dashboard stage: registries -# registry-attestation-manager: -# extends: .registry-attestation-manager -# stage: registries - -# registry-connection-manager: -# extends: .registry-connection-manager -# stage: registries - -# registry-proof-manager: -# extends: .registry-proof-manager -# stage: registries - -# registry-gateway: -# extends: .registry-gateway -# stage: registries - # Configure helm helm-agent: extends: .helm-agent stage: helm +helm-hin-agent: + extends: .helm-hin-agent + stage: helm + helm-dashboard: extends: .helm-dashboard stage: helm -# helm-attestation-manager: -# extends: .helm-attestation-manager -# stage: helm - -# helm-connection-manager: -# extends: .helm-connection-manager -# stage: helm - -# helm-proof-manager: -# extends: .helm-proof-manager -# stage: helm - -# helm-gateway: -# extends: .helm-gateway -# stage: helm deploy agent hin: extends: .deploy-agent-hin-main @@ -217,70 +145,6 @@ deploy agent cloud auth tagged: extends: .deploy-agent-cloud-auth-tag stage: deploy-prod -# deploy attestation ocm: -# extends: .deploy-attestation-manager-ocm-main -# stage: deploy-test - -# deploy attestation ocm tagged: -# extends: .deploy-attestation-manager-ocm-main-tag -# stage: deploy-test - -# deploy attestation ocm test: -# extends: .deploy-attestation-manager-ocm-test -# stage: deploy-test - -# deploy attestation ocm test tagged: -# extends: .deploy-attestation-manager-ocm-test-tag -# stage: deploy-test - -# deploy connection ocm: -# extends: .deploy-connection-manager-ocm-main -# stage: deploy-test - -# deploy connection ocm tagged: -# extends: .deploy-connection-manager-ocm-main-tag -# stage: deploy-test - -# deploy connection ocm test: -# extends: .deploy-connection-manager-ocm-test -# stage: deploy-test - -# deploy connection ocm test tagged: -# extends: .deploy-connection-manager-ocm-test-tag -# stage: deploy-test - -# deploy proof ocm: -# extends: .deploy-proof-manager-ocm-main -# stage: deploy-test - -# deploy proof ocm tagged: -# extends: .deploy-proof-manager-ocm-main-tag -# stage: deploy-test - -# deploy proof ocm test: -# extends: .deploy-proof-manager-ocm-test -# stage: deploy-test - -# deploy proof ocm test tagged: -# extends: .deploy-proof-manager-ocm-test-tag -# stage: deploy-test - -# deploy gateway ocm: -# extends: .deploy-gateway-ocm-main -# stage: deploy-test - -# deploy gateway ocm tagged: -# extends: .deploy-gateway-ocm-main-tag -# stage: deploy-test - -# deploy gateway ocm test: -# extends: .deploy-gateway-ocm-test -# stage: deploy-test - -# deploy gateway ocm test tagged: -# extends: .deploy-gateway-ocm-test-tag -# stage: deploy-test - commit lint: extends: .commit-lint stage: lint diff --git a/README.md b/README.md index f4aaca1b..2019f172 100644 --- a/README.md +++ b/README.md @@ -15,10 +15,8 @@ OCM Engine is a monorepo based on [NestJS](http://nestjs.com) and [Nx](https://n ### Apps list: - Agent - - Attestation Manager - - Connection Manager - - Proof Manager - - Gateway + - HIN Agent + - Dashboard ### Library list: - Askar @@ -26,24 +24,19 @@ OCM Engine is a monorepo based on [NestJS](http://nestjs.com) and [Nx](https://n - Config - Dtos - Ledgers - - Nats ## Requirements - Git - NodeJS >= v18.16.0 - PostgresDB -- Nats ## Architecture ```mermaid flowchart TD - Postman --http--> Gateway - Gateway --ws--> Postman - Gateway --tcp--> cm[Connection Manager] & am[Attestation Manager] & pm[Proof Manager] --event--> nats[NATS] - nats --event--> Agent - Agent --tcp--> Gateway + Postman <--http--> Server[(Rest API)] + Server <--> Agent Agent <--> db[(PostgresDB)] Agent <--> Ledger[(Ledger)] ``` @@ -88,17 +81,9 @@ flowchart TD 1. copy .env.example to .env 2. edit .env to your liking 3. yarn install - 4. yarn infra:local or install PostgresDB and Nats broker locally and add them to .env + 4. yarn infra:local or install PostgresDB locally and add them to .env 5. yarn serve:all - Example of running only the agent service as a rest service. - - 1. copy .env.example to .env - 2. edit .env to your liking and change AGENT_IS_REST to true - 3. yarn install - 4. yarn infra:local or isntall PostgresDB and Nats broker locally and add them to .env - 5. yarn serve:agent - ## Docker Example: @@ -125,7 +110,7 @@ Example: Yarn commands are wrapper around docker-compose for easier use. You can still use docker-compose from compose dir. ## Usage via Postman - 1. Import postman collection from the repo + 1. Import postman collection from the repo 2. Connect to Web Socket on the gateway address, to listen for responses 3. Make a request 4. Response will be sent to the Web Socket @@ -139,19 +124,15 @@ Example: - Change `AGENT_NAME` and `AGENT_KEY` - those are the name and the key of the wallet - Change `AGENT_DID_SEED` - this is a seed for private key from which the DID will be created. 4. Start the issuer with `yarn run infra:issuer` or `npm run infra:issuer` -5. Connect to the socket via postman. `ws://localhost:8081` -6. `Create new invitation` via postman request, on the socket listener you will receive invitation url response -7. Copy and paste this url in the chat +5. `Create new invitation` via postman request +6. Copy and paste this url in the chat -8. Another OCM (which performed the same setup steps, but with different values) should get this invitation url +7. Another OCM (which performed the same setup steps, but with different values) should get this invitation url 8. Call `accept invitation` via postman with this invitation url as a body payload 9. Response will be returned on the socket, that a connection is made. 10. Get the connectionId from this response 11. Send basic message with connectionId and a string message - - -12. On the socket of issuer a event will be received with the message and connection id. ## License This project is licensed under the AGPL License - see the [LICENSE](LICENSE) file for details. diff --git a/apps/agent/deployment/ci-cd/Dockerfile b/apps/agent/deployment/ci-cd/Dockerfile index 4a3aca95..42e977d4 100644 --- a/apps/agent/deployment/ci-cd/Dockerfile +++ b/apps/agent/deployment/ci-cd/Dockerfile @@ -26,11 +26,10 @@ RUN unzip -q artifacts.zip && rm artifacts.zip RUN cp ./dist/apps/agent/main.js . RUN cp ./dist/apps/agent/main.js.map . RUN cp -r ./dist/libs/askar . -RUN cp -r ./dist/libs/clients . +#RUN cp -r ./dist/libs/clients . # no need by backend RUN cp -r ./dist/libs/config . RUN cp -r ./dist/libs/dtos . RUN cp -r ./dist/libs/ledgers . -RUN cp -r ./dist/libs/nats . RUN yarn install diff --git a/apps/agent/deployment/ci-cd/helm/templates/deployment.yaml b/apps/agent/deployment/ci-cd/helm/templates/deployment.yaml index cb3c1943..cd5c27c6 100644 --- a/apps/agent/deployment/ci-cd/helm/templates/deployment.yaml +++ b/apps/agent/deployment/ci-cd/helm/templates/deployment.yaml @@ -61,12 +61,6 @@ spec: value: {{ .Values.ocm.agent.db.pass | quote }} - name: AGENT_PORT value: {{ .Values.ocm.agent.port | quote }} - - name: AGENT_IS_REST - value: {{ .Values.ocm.agent.isRest | quote }} - - name: AGENT_MAX_MESSAGES - value: {{ .Values.ocm.agent.maxMessage | quote }} - - name: AGENT_RETE_LIMIT - value: {{ .Values.ocm.agent.rateLimit | quote }} - name: ALLOWED_ORIGINS value: {{ .Values.ocm.agent.allowedOrigin | quote }} - name: AUTH_BASIC_USER @@ -102,12 +96,6 @@ spec: value: {{ .Values.ocmtest.agent.db.pass | quote }} - name: AGENT_PORT value: {{ .Values.ocmtest.agent.port | quote }} - - name: AGENT_IS_REST - value: {{ .Values.ocmtest.agent.isRest | quote }} - - name: AGENT_MAX_MESSAGES - value: {{ .Values.ocmtest.agent.maxMessage | quote }} - - name: AGENT_RETE_LIMIT - value: {{ .Values.ocmtest.agent.rateLimit | quote }} - name: ALLOWED_ORIGINS value: {{ .Values.ocmtest.agent.allowedOrigin | quote }} - name: AUTH_BASIC_USER @@ -118,51 +106,6 @@ spec: value: {{ .Values.ocmtest.agent.api.jwt.publicKey | quote }} - name: AGENT_OOB_URL value: {{ .Values.ocmtest.agent.oob.url | quote }} - {{- else if eq .Release.Namespace "hin" }} - - name: LEDGERS - value: {{ .Values.hin.agent.ledgers | quote }} - - name : AGENT_PEER_URL - value: {{ .Values.hin.agent.peer.url | quote }} - - name: AGENT_NAME - value: {{ .Values.hin.agent.name | quote }} - - name: AGENT_KEY - value: {{ .Values.hin.agent.key | quote }} - - name: AGENT_DID_SEED - value: {{ .Values.hin.agent.did.seed | quote }} - - name: AGENT_DB_HOST - value: {{ .Values.hin.agent.db.host | quote }} - - name: AGENT_DB_USER - value: {{ .Values.hin.agent.db.user | quote }} - - name: AGENT_DB_PASS - value: {{ .Values.hin.agent.db.pass | quote }} - - name: AGENT_PORT - value: {{ .Values.hin.agent.port | quote }} - - name: AGENT_IS_REST - value: {{ .Values.hin.agent.is.rest | quote }} - - name: AGENT_IS_SVDX - value: {{ .Values.hin.agent.is.svdx | quote }} - - name: AGENT_SVDX_WEBHOOK_URL - value: {{ .Values.hin.agent.svdx.webhook.url | quote }} - - name: AGENT_SVDX_BASIC_USER - value: {{ .Values.hin.agent.svdx.basic.user | quote }} - - name: AGENT_SVDX_BASIC_PASS - value: {{ .Values.hin.agent.svdx.basic.pass | quote }} - - name: AGENT_MAX_MESSAGES - value: {{ .Values.hin.agent.max.messages | quote }} - - name: AGENT_RETE_LIMIT - value: {{ .Values.hin.agent.rete.limit | quote }} - - name: ALLOWED_ORIGINS - value: {{ .Values.hin.agent.allowedOrigin | quote }} - - name: AGENT_OOB_GOALS - value: {{ .Values.hin.agent.invitationGoals | quote }} - - name: AUTH_BASIC_USER - value: {{ .Values.hin.agent.api.basic.user | quote }} - - name: AUTH_BASIC_PASS - value: {{ .Values.hin.agent.api.basic.pass | quote }} - - name: AUTH_JWT_PUBLIC_KEY - value: {{ .Values.hin.agent.api.jwt.publicKey | quote }} - - name: AGENT_OOB_URL - value: {{ .Values.hin.agent.oob.url | quote }} {{- else if eq .Release.Namespace "cloud-auth" }} - name: LEDGERS value: {{ .Values.ca.agent.ledgers | quote }} @@ -182,14 +125,6 @@ spec: value: {{ .Values.ca.agent.db.pass | quote }} - name: AGENT_PORT value: {{ .Values.ca.agent.port | quote }} - - name: AGENT_IS_REST - value: {{ .Values.ca.agent.is.rest | quote }} - - name: AGENT_IS_SVDX - value: {{ .Values.ca.agent.is.svdx | quote }} - - name: AGENT_MAX_MESSAGES - value: {{ .Values.ca.agent.max.messages | quote }} - - name: AGENT_RETE_LIMIT - value: {{ .Values.ca.agent.rete.limit | quote }} - name: ALLOWED_ORIGINS value: {{ .Values.ca.agent.allowedOrigin | quote }} {{- end }} diff --git a/apps/agent/deployment/ci-cd/helm/templates/ingress.yaml b/apps/agent/deployment/ci-cd/helm/templates/ingress.yaml index 0a0fe7b7..fcf48e03 100644 --- a/apps/agent/deployment/ci-cd/helm/templates/ingress.yaml +++ b/apps/agent/deployment/ci-cd/helm/templates/ingress.yaml @@ -52,24 +52,6 @@ spec: name: {{ template "app.name" . }} port: number: {{ .Values.service.port }} - {{- else if eq .Release.Namespace "hin" }} - - host: {{ .Values.ingress.frontendDomain }} - http: - paths: - - path: /hin-agent(/|$)(.*) - pathType: Prefix - backend: - service: - name: {{ template "app.name" . }} - port: - number: {{ .Values.service.port1 }} - - path: /api-hin-agent(/|$)(.*) - pathType: Prefix - backend: - service: - name: {{ template "app.name" . }} - port: - number: {{ .Values.hin.agent.port }} {{- else if eq .Release.Namespace "cloud-auth" }} - host: {{ .Values.ingress.frontendDomain }} http: diff --git a/apps/agent/deployment/ci-cd/helm/values.yaml b/apps/agent/deployment/ci-cd/helm/values.yaml index 866e2100..8d734188 100644 --- a/apps/agent/deployment/ci-cd/helm/values.yaml +++ b/apps/agent/deployment/ci-cd/helm/values.yaml @@ -75,11 +75,6 @@ ocm: user: "" pass: "" port: 8080 - # consumer: - # name: "agent_1" - isRest: true - maxMessage: 10 - rateLimit: 5 allowedOrigin: "*" api: jwt: @@ -89,19 +84,6 @@ ocm: pass: "" oob: url: "https://issuer-dev.vereign.com" - # nats: - # server: "nats.ocm:4222" - # name: "ssi_issuer_stream" - # subjects: "connections.*,proofs.*,credentials.*,credentials.definition.*,credentials.offer.*,schemas.*,messages.*" - - # gateway: - # port: - # http: 8081 - # tcp: 8881 - # socket: - # name: "message" - # messagePattern: "webhook" - # host: "gateway.ocm" ocmtest: agent: @@ -121,11 +103,6 @@ ocmtest: user: "" pass: "" port: 8080 - # consumer: - # name: "agent_1" - isRest: true - maxMessage: 10 - rateLimit: 5 allowedOrigin: "*" api: jwt: @@ -136,59 +113,6 @@ ocmtest: oob: url: "https://holder-dev.vereign.com" - - # nats: - # server: "nats.ocm-test:4222" - # name: "ssi_holder_stream" - # subjects: "connections.*,proofs.*,credentials.*,credentials.definition.*,credentials.offer.*,schemas.*,messages.*" - - # gateway: - # port: - # http: 8081 - # tcp: 8881 - # socket: - # name: "message" - # messagePattern: "webhook" - # host: "gateway.ocm-test" - -hin: - agent: - ledgers: "BCOVRIN_TEST" - peer: - url: "https://ssi-dev.vereign.com/hin-agent" - name: "hin-agent-dev" - key: "Fpvsvz0seqevq7RRiPbRT6oopAcrMXcaY8d" - did: - seed: "8rQuMQ6YeVF1CVyKp4KZTjikpwM4irGl26Ds" - port: 8080 - is: - rest: "true" - svdx: "true" - svdx: - basic: - user: "" - pass: "" - webhook: - url: "https://did.svdx.pro/ocm/connection" - max: - messages: 10 - rete: - limit: 5 - db: - host: "" - user: "" - pass: "" - allowedOrigin: "*" - invitationGoals: "connection.exchange" - api: - jwt: - publicKey: "" - basic: - user: "ocmhin-admin" - pass: "" - oob: - url: "https://hin-dev.vereign.com" - ca: agent: ledgers: "BCOVRIN_TEST" diff --git a/apps/agent/src/app/app.module.ts b/apps/agent/src/app/app.module.ts index 203fd082..9043aaf8 100644 --- a/apps/agent/src/app/app.module.ts +++ b/apps/agent/src/app/app.module.ts @@ -5,13 +5,10 @@ import { ConfigModule } from "@nestjs/config"; import { agentConfig, agentSchema, + authConfig, authSchema, - gatewayConfig, - gatewaySchema, ledgersConfig, ledgersSchema, - natsConfig, - natsSchema, } from "@ocm-engine/config"; import Joi from "joi"; @@ -19,8 +16,6 @@ const validationSchema = Joi.object({ agent: agentSchema, auth: authSchema, ledgers: ledgersSchema, - nats: natsSchema, - gateway: gatewaySchema, }); @Module({ @@ -28,7 +23,7 @@ const validationSchema = Joi.object({ AskarDynamicModule.forRootAsync(), ConfigModule.forRoot({ isGlobal: true, - load: [agentConfig, ledgersConfig, natsConfig, gatewayConfig], + load: [agentConfig, authConfig, ledgersConfig], validationSchema, }), ], diff --git a/apps/attestation-manager/README.md b/apps/attestation-manager/README.md deleted file mode 100644 index 6c241a74..00000000 --- a/apps/attestation-manager/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# OCM ENGINE - Attestation Manager - -Internal service. - -Attestation manager accepts requests for schemas, credentials and messages. -That are coming from @ocm-engine/gateway api, then converts them to events and pushes to a NATS stream with specific for the event subject. - -## Attestation Manager setup - -### From the root of the project run: - -#### Install dependencies -``` -yarn install -``` -#### Copy .env.example to .env - -``` -cp .env.exampe .env -``` - -Do changes to the .env according to your needs. - -#### Start the agent locally: - -``` -yarn serve:am -``` diff --git a/apps/attestation-manager/deployment/ci-cd/helm/Chart.yaml b/apps/attestation-manager/deployment/ci-cd/helm/Chart.yaml deleted file mode 100644 index 540dbcbb..00000000 --- a/apps/attestation-manager/deployment/ci-cd/helm/Chart.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: v1 -appVersion: build-654 -description: attestation-manager deployment -name: attestation-manager -version: 0.0.2 -icon: "https://www.vereign.com/wp-content/themes/vereign2020/images/vereign-logo.svg" diff --git a/apps/attestation-manager/deployment/ci-cd/helm/templates/deployment.yaml b/apps/attestation-manager/deployment/ci-cd/helm/templates/deployment.yaml deleted file mode 100644 index d4710a09..00000000 --- a/apps/attestation-manager/deployment/ci-cd/helm/templates/deployment.yaml +++ /dev/null @@ -1,73 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: "{{ template "app.name" . }}" - namespace: {{ .Release.Namespace }} - labels: - {{- include "app.labels" . | nindent 4 }} - app.kubernetes.io/instance: {{ include "app.revision" . }} - app.kubernetes.io/part-of: rse -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: RollingUpdate - rollingUpdate: - maxSurge: 1 - maxUnavailable: 0 - selector: - matchLabels: - {{- include "app.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "app.labels" . | nindent 8 }} - annotations: - {{- include "app.metricsAnnotations" . | nindent 8 }} -{{- if .Values.podAnnotations }} -{{ toYaml .Values.podAnnotations | indent 8 }} -{{- end }} - spec: - securityContext: -{{- include "app.securitycontext" . | nindent 8 }} - imagePullSecrets: - - name: {{ .Values.image.pullSecrets }} - containers: - - name: {{ template "app.name" . }} - image: "{{ .Values.image.repository }}/{{ .Values.image.name }}:{{ default .Chart.AppVersion .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy | quote }} - env: - {{- if eq .Release.Namespace "ocm" }} - - name: NATS_SERVERS - value: {{ .Values.ocm.nats.server | quote }} - - name: NATS_STREAM_NAME - value: {{ .Values.ocm.nats.name | quote }} - - name: NATS_SUBJECTS - value: {{ .Values.ocm.nats.subjects | quote }} - - name: ATTESTATION_SERVICE_TCP_PORT - value: {{ .Values.ocm.attestationManager.service.tcp.port | quote }} - - name: ATTESTATION_SERVICE_HOST - value: {{ .Values.ocm.attestationManager.service.host | quote }} - {{- else if eq .Release.Namespace "ocm-test" }} - - name: NATS_SERVERS - value: {{ .Values.ocmtest.nats.server | quote }} - - name: NATS_STREAM_NAME - value: {{ .Values.ocmtest.nats.name | quote }} - - name: NATS_SUBJECTS - value: {{ .Values.ocmtest.nats.subjects | quote }} - - name: ATTESTATION_SERVICE_TCP_PORT - value: {{ .Values.ocmtest.attestationManager.service.tcp.port | quote }} - - name: ATTESTATION_SERVICE_HOST - value: {{ .Values.ocmtest.attestationManager.service.host | quote }} - {{- end }} -{{- if .Values.extraVars }} -{{ toYaml .Values.extraVars | indent 8 }} -{{- end }} - ports: - {{- if .Values.metrics.enabled }} - - name: monitoring - containerPort: {{ .Values.metrics.port }} - {{- end }} - - name: http - containerPort: {{ .Values.service.port }} - resources: -{{ toYaml .Values.resources | indent 10 }} diff --git a/apps/attestation-manager/deployment/ci-cd/helm/templates/hpa.yaml b/apps/attestation-manager/deployment/ci-cd/helm/templates/hpa.yaml deleted file mode 100644 index fc5c29e7..00000000 --- a/apps/attestation-manager/deployment/ci-cd/helm/templates/hpa.yaml +++ /dev/null @@ -1,27 +0,0 @@ -{{- if .Values.autoscaling.enabled }} -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - labels: - {{- include "app.labels" . | nindent 4 }} - name: {{ template "app.name" . }} - namespace: {{ .Release.Namespace }} -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: {{ template "app.name" . }} - minReplicas: {{ .Values.autoscaling.minReplicas }} - maxReplicas: {{ .Values.autoscaling.maxReplicas }} - metrics: -{{- with .Values.autoscaling.targetCPUUtilizationPercentage }} - - type: Resource - resource: - name: cpu -{{- end }} -{{- with .Values.autoscaling.targetMemoryUtilizationPercentage }} - - type: Resource - resource: - name: memory -{{- end }} -{{- end }} \ No newline at end of file diff --git a/apps/attestation-manager/deployment/ci-cd/helm/templates/service.yaml b/apps/attestation-manager/deployment/ci-cd/helm/templates/service.yaml deleted file mode 100644 index 21c57ac8..00000000 --- a/apps/attestation-manager/deployment/ci-cd/helm/templates/service.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ template "app.name" . }} - namespace: {{ .Release.Namespace }} - labels: - {{- include "app.labels" . | nindent 4 }} -spec: - clusterIP: None - ports: - - name: http - port: {{ .Values.service.port }} - targetPort: {{ .Values.service.port }} - selector: - {{- include "app.selectorLabels" . | nindent 4 }} - diff --git a/apps/attestation-manager/deployment/ci-cd/helm/values.yaml b/apps/attestation-manager/deployment/ci-cd/helm/values.yaml deleted file mode 100644 index b6838724..00000000 --- a/apps/attestation-manager/deployment/ci-cd/helm/values.yaml +++ /dev/null @@ -1,112 +0,0 @@ -# -- Default number of instances to start . -replicaCount: 1 -# -- Application name -name: attestation-manager -# -- Ovverwrites application name -nameOverride: "" - -image: - repository: eu.gcr.io/vrgn-infra-prj - # -- Image name - name: gaiax/ocm/ocm-engine/attestation-manager - # -- Image tag - # Uses .Chart.AppVersion if empty - tag: "" - # -- Image sha, usually generated by the CI - # Uses image.tag if empty - sha: "" - # -- Image pull policy - pullPolicy: IfNotPresent - # -- Image pull secret when internal image is used - pullSecrets: deployment-key-light - - -podAnnotations: {} -## -## Pass extra environment variables to the container. -## -# extraVars: -# - name: EXTRA_VAR_1 -# value: extra-var-value-1 -# - name: EXTRA_VAR_2 -# value: extra-var-value-2 -## -## Create new service when true, and use the specified uner name when set to the name specified -## - -resources: - requests: - cpu: 25m - memory: 64Mi - limits: - cpu: 150m - memory: 128Mi - -## Configure pod autoscaling -## - -autoscaling: - # -- Enable autoscaling - enabled: false - # -- Minimum replicas - minReplicas: 1 - # -- Maximum replicas - maxReplicas: 3 - # -- CPU target for autoscaling trigger - targetCPUUtilizationPercentage: 70 - # -- Memory target for autoscaling trigger - targetMemoryUtilizationPercentage: 70 -## -## Prometheus Exporter / Metrics -## - -metrics: - # -- Enable prometheus metrics - enabled: true - # -- Port for prometheus metrics - port: 2112 - -log: - level: "INFO" - encoding: json - -## -## Kubernetes [SecurityContext](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) object. -## - -security: - # -- by default, apps run as non-root - runAsNonRoot: false - # -- User used by the apps - runAsUid: 0 - # -- Group used by the apps - runAsGid: 0 -## -## -service: - port: 8883 - -ocm: - attestationManager: - service: - tcp: - port: 8883 - host: "attestation-manager.ocm" - nats: - server: "nats.ocm:4222" - name: "ssi_issuer_stream" - subjects: "connections.*,proofs.*,credentials.*,credentials.definition.*,credentials.offer.*,schemas.*,messages.*" - -ocmtest: - attestationManager: - service: - tcp: - port: 8883 - host: "attestation-manager.ocm-test" - nats: - server: "nats.ocm-test:4222" - name: "ssi_holder_stream" - subjects: "connections.*,proofs.*,credentials.*,credentials.definition.*,credentials.offer.*,schemas.*,messages.*" - -ingress: - enabled: false diff --git a/apps/attestation-manager/deployment/local/Dockerfile b/apps/attestation-manager/deployment/local/Dockerfile deleted file mode 100644 index dab88e16..00000000 --- a/apps/attestation-manager/deployment/local/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM node:18.16.0-buster-slim - -RUN apt update -y && apt install python3 git make build-essential -y - -WORKDIR app - -COPY ./dist/apps/attestation-manager . -COPY package.json yarn.lock ./ - -RUN yarn install - - -EXPOSE 8883 - -CMD ["node", "main.js"] - diff --git a/apps/attestation-manager/project.json b/apps/attestation-manager/project.json deleted file mode 100644 index 193c32f5..00000000 --- a/apps/attestation-manager/project.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "name": "attestation-manager", - "$schema": "../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "apps/attestation-manager/src", - "projectType": "application", - "targets": { - "build": { - "executor": "@nx/webpack:webpack", - "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", - "options": { - "target": "node", - "compiler": "tsc", - "outputPath": "dist/apps/attestation-manager", - "main": "apps/attestation-manager/src/main.ts", - "tsConfig": "apps/attestation-manager/tsconfig.app.json", - "isolatedConfig": true, - "webpackConfig": "apps/attestation-manager/webpack.config.js" - }, - "configurations": { - "development": {}, - "production": {} - } - }, - "serve": { - "executor": "@nx/js:node", - "defaultConfiguration": "development", - "options": { - "buildTarget": "attestation-manager:build" - }, - "configurations": { - "development": { - "buildTarget": "attestation-manager:build:development" - }, - "production": { - "buildTarget": "attestation-manager:build:production" - } - } - }, - "lint": { - "executor": "@nx/linter:eslint", - "outputs": ["{options.outputFile}"], - "options": { - "lintFilePatterns": ["apps/attestation-manager/**/*.ts"] - } - }, - "test": { - "executor": "@nx/jest:jest", - "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], - "options": { - "jestConfig": "apps/attestation-manager/jest.config.ts", - "passWithNoTests": true - }, - "configurations": { - "ci": { - "ci": true, - "codeCoverage": true - } - } - } - }, - "tags": [] -} diff --git a/apps/attestation-manager/src/app/app.controller.ts b/apps/attestation-manager/src/app/app.controller.ts deleted file mode 100644 index 5d4176c7..00000000 --- a/apps/attestation-manager/src/app/app.controller.ts +++ /dev/null @@ -1,122 +0,0 @@ -import { Body, Controller, Logger } from "@nestjs/common"; - -import { MessagePattern, RpcException } from "@nestjs/microservices"; -import { - BasicMessageEvent, - CloudEventDto, - CreateCredentialDefinitionRequestDto, - CreateSchemaRequestDto, - CredentialEvent, - GatewayAcceptedResponseDto, - OfferCredentialRequestDto, - MakeBasicMessageRequestDto, - makeEvent, - SchemaEvent, -} from "@ocm-engine/dtos"; -import { ProducerService } from "@ocm-engine/nats"; - -@Controller() -export class AppController { - private readonly logger: Logger = new Logger(AppController.name); - - constructor(private readonly producerService: ProducerService) {} - - @MessagePattern("schemas") - async create( - @Body() - payload: { - data: null | CreateSchemaRequestDto | CreateSchemaRequestDto; - type: SchemaEvent; - source: string; - }, - ): Promise<GatewayAcceptedResponseDto> { - this.logger.debug(JSON.stringify(payload, null, 2)); - - try { - const event = makeEvent(payload); - this.logger.debug(JSON.stringify(event, null, 2)); - await this.producerService.publish<typeof payload.data>( - payload.type, - event as CloudEventDto<typeof payload.data>, - ); - - return GatewayAcceptedResponseDto.fromJson({ - id: event.id, - }); - } catch (e) { - this.logger.debug(JSON.stringify(e, null, 2)); - if (e instanceof Error) { - throw new RpcException(e.message); - } - - throw new RpcException("Internal server error"); - } - } - - @MessagePattern("credentials") - async createCredential( - @Body() - payload: { - data: - | null - | CreateCredentialDefinitionRequestDto - | OfferCredentialRequestDto; - type: CredentialEvent; - source: string; - }, - ): Promise<GatewayAcceptedResponseDto> { - this.logger.debug(JSON.stringify(payload, null, 2)); - - try { - const event = makeEvent(payload); - this.logger.debug(JSON.stringify(event, null, 2)); - await this.producerService.publish<typeof payload.data>( - payload.type, - event as CloudEventDto<typeof payload.data>, - ); - - return GatewayAcceptedResponseDto.fromJson({ - id: event.id, - }); - } catch (e) { - this.logger.debug(JSON.stringify(e, null, 2)); - if (e instanceof Error) { - throw new RpcException(e.message); - } - - throw new RpcException("Internal server error"); - } - } - - @MessagePattern("messages") - async sendMessage( - @Body() - payload: { - data: MakeBasicMessageRequestDto; - type: BasicMessageEvent; - source: string; - }, - ): Promise<GatewayAcceptedResponseDto> { - this.logger.debug(JSON.stringify(payload, null, 2)); - - try { - const event = makeEvent(payload); - this.logger.debug(JSON.stringify(event, null, 2)); - await this.producerService.publish<typeof payload.data>( - payload.type, - event as CloudEventDto<typeof payload.data>, - ); - - return GatewayAcceptedResponseDto.fromJson({ - id: event.id, - }); - } catch (e) { - this.logger.debug(JSON.stringify(e, null, 2)); - if (e instanceof Error) { - throw new RpcException(e.message); - } - - throw new RpcException("Internal server error"); - } - } -} diff --git a/apps/attestation-manager/src/app/app.module.ts b/apps/attestation-manager/src/app/app.module.ts deleted file mode 100644 index 337144b3..00000000 --- a/apps/attestation-manager/src/app/app.module.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Module } from "@nestjs/common"; - -import { AppController } from "./app.controller"; -import { ConfigModule } from "@nestjs/config"; -import { amConfig, amSchema, natsConfig, natsSchema } from "@ocm-engine/config"; -import { ProducerService } from "@ocm-engine/nats"; -import Joi from "joi"; - -const validationSchema = Joi.object({ - nats: natsSchema, - am: amSchema, -}); - -@Module({ - imports: [ - ConfigModule.forRoot({ - isGlobal: true, - load: [natsConfig, amConfig], - validationSchema, - }), - ], - controllers: [AppController], - providers: [ProducerService], -}) -export class AppModule {} diff --git a/apps/attestation-manager/src/main.ts b/apps/attestation-manager/src/main.ts deleted file mode 100644 index f2abf774..00000000 --- a/apps/attestation-manager/src/main.ts +++ /dev/null @@ -1,37 +0,0 @@ -/** - * This is not a production server yet! - * This is only a minimal backend to get started. - */ - -import { Logger } from "@nestjs/common"; -import { NestFactory } from "@nestjs/core"; - -import { AppModule } from "./app/app.module"; - -import { MicroserviceOptions, Transport } from "@nestjs/microservices"; -import { ConfigService } from "@nestjs/config"; -import { IAttestationManagerConfig } from "@ocm-engine/config"; -async function bootstrap() { - const app = await NestFactory.create(AppModule); - - const configService = app.get(ConfigService); - const am = configService.get<IAttestationManagerConfig>("am")!; - - app.enableShutdownHooks(); - - const microservice = app.connectMicroservice<MicroserviceOptions>({ - transport: Transport.TCP, - options: { - host: am.host, - port: am.port, - }, - }); - - await app.startAllMicroservices(); - - app.enableShutdownHooks(); - - Logger.log(`Application is running ${am.host}:${am.port} TCP`); -} - -bootstrap(); diff --git a/apps/connection-manager/.eslintrc.json b/apps/connection-manager/.eslintrc.json deleted file mode 100644 index 9d9c0db5..00000000 --- a/apps/connection-manager/.eslintrc.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "extends": ["../../.eslintrc.json"], - "ignorePatterns": ["!**/*"], - "overrides": [ - { - "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], - "rules": {} - }, - { - "files": ["*.ts", "*.tsx"], - "rules": {} - }, - { - "files": ["*.js", "*.jsx"], - "rules": {} - } - ] -} diff --git a/apps/connection-manager/README.md b/apps/connection-manager/README.md deleted file mode 100644 index e8328122..00000000 --- a/apps/connection-manager/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# OCM ENGINE - Connection Manager - -Internal service. - -Connection manager accepts requests for connections, that are coming from @ocm-engine/gateway api, then converts them to events and pushes to a NATS stream with specific for the event subject. - -## Connection Manager setup - -### From the root of the project run: - -#### Install dependencies -``` -yarn install -``` -#### Copy .env.example to .env - -``` -cp .env.exampe .env -``` - -Do changes to the .env according to your needs. - -#### Start the agent locally: - -``` -yarn serve:cm -``` diff --git a/apps/connection-manager/deployment/ci-cd/Dockerfile b/apps/connection-manager/deployment/ci-cd/Dockerfile deleted file mode 100644 index 19be1735..00000000 --- a/apps/connection-manager/deployment/ci-cd/Dockerfile +++ /dev/null @@ -1,37 +0,0 @@ -FROM node:18.16.0-buster-slim - -# Argument handler -ARG API_TOKEN -ARG JOB_ID -# Instal required software -RUN apt update -y && apt install python3 git make build-essential wget unzip -y - -# Set the working directory -WORKDIR app - -# Set the ENV variables -ENV GITLAB_BASE_URL=https://code.vereign.com/api/v4 -ENV GITLAB_PROJECT_ID=662 -ENV TOKEN=$API_TOKEN -ENV ID=$JOB_ID - -# Download the artifacts from the GitLab API -RUN wget --header "PRIVATE-TOKEN: $TOKEN" -O artifacts.zip "${GITLAB_BASE_URL}/projects/${GITLAB_PROJECT_ID}/jobs/${ID}/artifacts" - -# Unzip the artifacts (if needed) - adjust this command based on your artifact type -RUN unzip -q artifacts.zip && rm artifacts.zip - -# Fix locations -RUN cp ./dist/apps/connection-manager/main.js . -RUN cp ./dist/apps/connection-manager/main.js.map . -RUN cp -r ./dist/libs/config . -RUN cp -r ./dist/libs/dtos . -RUN cp -r ./dist/libs/nats . - -RUN yarn install - -# Expose required ports -EXPOSE 8882 - -# Command to run -CMD ["node", "main.js"] diff --git a/apps/connection-manager/deployment/ci-cd/helm/Chart.yaml b/apps/connection-manager/deployment/ci-cd/helm/Chart.yaml deleted file mode 100644 index 1c65bbe1..00000000 --- a/apps/connection-manager/deployment/ci-cd/helm/Chart.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: v1 -appVersion: build-654 -description: connection-manager deployment -name: connection-manager -version: 0.0.2 -icon: "https://www.vereign.com/wp-content/themes/vereign2020/images/vereign-logo.svg" diff --git a/apps/connection-manager/deployment/ci-cd/helm/templates/_helpers.tpl b/apps/connection-manager/deployment/ci-cd/helm/templates/_helpers.tpl deleted file mode 100644 index 6cba3ffc..00000000 --- a/apps/connection-manager/deployment/ci-cd/helm/templates/_helpers.tpl +++ /dev/null @@ -1,94 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "app.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "app.fullname" -}} -{{- $name := default .Chart.Name .Values.nameOverride -}} -{{- printf "%s-%s" $name .Release.Namespace | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create instance name based on app version and short image sha. -*/}} -{{- define "app.revision" -}} -{{- default .Release.Name .Values.appRel | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "app.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "app.labels" -}} -helm.sh/chart: {{ include "app.chart" . }} -{{ include "app.selectorLabels" . }} -app.kubernetes.io/version: {{ .Chart.AppVersion }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "app.selectorLabels" -}} -app.kubernetes.io/name: {{ include "app.name" . }} -app.kubernetes.io/component: {{ include "app.fullname" . }} -{{- end -}} - -{{/* -Metrics Annotations -*/}} -{{- define "app.metricsAnnotations" -}} -{{- if .Values.metrics.enabled -}} -prometheus.io/scrape: "true" -prometheus.io/port: "{{ .Values.metrics.port }}" -prometheus.io/path: {{ .Values.metrics.path | default "/metrics" | quote }} -{{- end -}} -{{- end -}} - -{{/* -Image string -*/}} -{{- define "app.image" -}} -{{- if .Values.image.sha -}} -{{ .Values.image.repository }}/{{ .Values.image.name }}@{{ .Values.image.sha }} -{{- else -}} -{{ .Values.image.repository }}/{{ .Values.image.name }}:{{ default .Chart.AppVersion .Values.image.tag }} -{{- end -}} -{{- end -}} - -{{/* -Security context -*/}} -{{- define "app.securitycontext" -}} -runAsNonRoot: {{ .Values.security.runAsNonRoot | default false }} -runAsGroup: {{ .Values.security.runAsGid | default 0 }} -runAsUser: {{ .Values.security.runAsUid | default 0 }} -fsGroup: {{ .Values.security.runAsGid | default 0 }} -{{- end -}} - -{{/* -PostgreSQL Connection string URI -*/}} -{{- define "app.postgresql.connectionstring" -}} -postgresql://{{ .Values.attestationManager.database.user }}:{{ .Values.attestationManager.database.password }}@{{ .Values.attestationManager.database.host }}:{{ .Values.attestationManager.database.port }}/{{ .Release.Namespace }}_{{ include "app.name" . | replace "-" "_" }}?schema={{ .Values.attestationManager.database.schema }} -{{- end -}} - -{{/* -Ingress custom path. -*/}} -{{- define "app.path" -}} -{{- default .Chart.Name .Values.ingress.pathOverride | replace "-manager" "" | trunc 63 | trimSuffix "-" -}} -{{- end -}} diff --git a/apps/connection-manager/deployment/ci-cd/helm/templates/deployment.yaml b/apps/connection-manager/deployment/ci-cd/helm/templates/deployment.yaml deleted file mode 100644 index d54ef3e5..00000000 --- a/apps/connection-manager/deployment/ci-cd/helm/templates/deployment.yaml +++ /dev/null @@ -1,73 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: "{{ template "app.name" . }}" - namespace: {{ .Release.Namespace }} - labels: - {{- include "app.labels" . | nindent 4 }} - app.kubernetes.io/instance: {{ include "app.revision" . }} - app.kubernetes.io/part-of: rse -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: RollingUpdate - rollingUpdate: - maxSurge: 1 - maxUnavailable: 0 - selector: - matchLabels: - {{- include "app.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "app.labels" . | nindent 8 }} - annotations: - {{- include "app.metricsAnnotations" . | nindent 8 }} -{{- if .Values.podAnnotations }} -{{ toYaml .Values.podAnnotations | indent 8 }} -{{- end }} - spec: - securityContext: -{{- include "app.securitycontext" . | nindent 8 }} - imagePullSecrets: - - name: {{ .Values.image.pullSecrets }} - containers: - - name: {{ template "app.name" . }} - image: "{{ .Values.image.repository }}/{{ .Values.image.name }}:{{ default .Chart.AppVersion .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy | quote }} - env: - {{- if eq .Release.Namespace "ocm" }} - - name: NATS_SERVERS - value: {{ .Values.ocm.nats.server | quote }} - - name: NATS_STREAM_NAME - value: {{ .Values.ocm.nats.name | quote }} - - name: NATS_SUBJECTS - value: {{ .Values.ocm.nats.subjects | quote }} - - name: CONNECTION_SERVICE_TCP_PORT - value: {{ .Values.ocm.connectionManager.service.tcp.port | quote }} - - name: CONNECTION_SERVICE_HOST - value: {{ .Values.ocm.connectionManager.service.host | quote }} - {{- else if eq .Release.Namespace "ocm-test" }} - - name: NATS_SERVERS - value: {{ .Values.ocmtest.nats.server | quote }} - - name: NATS_STREAM_NAME - value: {{ .Values.ocmtest.nats.name | quote }} - - name: NATS_SUBJECTS - value: {{ .Values.ocmtest.nats.subjects | quote }} - - name: CONNECTION_SERVICE_TCP_PORT - value: {{ .Values.ocmtest.connectionManager.service.tcp.port | quote }} - - name: CONNECTION_SERVICE_HOST - value: {{ .Values.ocmtest.connectionManager.service.host | quote }} - {{- end }} -{{- if .Values.extraVars }} -{{ toYaml .Values.extraVars | indent 8 }} -{{- end }} - ports: - {{- if .Values.metrics.enabled }} - - name: monitoring - containerPort: {{ .Values.metrics.port }} - {{- end }} - - name: http - containerPort: {{ .Values.service.port }} - resources: -{{ toYaml .Values.resources | indent 10 }} diff --git a/apps/connection-manager/deployment/ci-cd/helm/templates/hpa.yaml b/apps/connection-manager/deployment/ci-cd/helm/templates/hpa.yaml deleted file mode 100644 index fc5c29e7..00000000 --- a/apps/connection-manager/deployment/ci-cd/helm/templates/hpa.yaml +++ /dev/null @@ -1,27 +0,0 @@ -{{- if .Values.autoscaling.enabled }} -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - labels: - {{- include "app.labels" . | nindent 4 }} - name: {{ template "app.name" . }} - namespace: {{ .Release.Namespace }} -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: {{ template "app.name" . }} - minReplicas: {{ .Values.autoscaling.minReplicas }} - maxReplicas: {{ .Values.autoscaling.maxReplicas }} - metrics: -{{- with .Values.autoscaling.targetCPUUtilizationPercentage }} - - type: Resource - resource: - name: cpu -{{- end }} -{{- with .Values.autoscaling.targetMemoryUtilizationPercentage }} - - type: Resource - resource: - name: memory -{{- end }} -{{- end }} \ No newline at end of file diff --git a/apps/connection-manager/deployment/ci-cd/helm/templates/service.yaml b/apps/connection-manager/deployment/ci-cd/helm/templates/service.yaml deleted file mode 100644 index 21c57ac8..00000000 --- a/apps/connection-manager/deployment/ci-cd/helm/templates/service.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ template "app.name" . }} - namespace: {{ .Release.Namespace }} - labels: - {{- include "app.labels" . | nindent 4 }} -spec: - clusterIP: None - ports: - - name: http - port: {{ .Values.service.port }} - targetPort: {{ .Values.service.port }} - selector: - {{- include "app.selectorLabels" . | nindent 4 }} - diff --git a/apps/connection-manager/deployment/ci-cd/helm/values.yaml b/apps/connection-manager/deployment/ci-cd/helm/values.yaml deleted file mode 100644 index b3b77877..00000000 --- a/apps/connection-manager/deployment/ci-cd/helm/values.yaml +++ /dev/null @@ -1,112 +0,0 @@ -# -- Default number of instances to start -replicaCount: 1 -# -- Application name -name: connection-manager -# -- Ovverwrites application name -nameOverride: "" - -image: - repository: eu.gcr.io/vrgn-infra-prj - # -- Image name - name: gaiax/ocm/ocm-engine/connection-manager - # -- Image tag - # Uses .Chart.AppVersion if empty - tag: "" - # -- Image sha, usually generated by the CI - # Uses image.tag if empty - sha: "" - # -- Image pull policy - pullPolicy: IfNotPresent - # -- Image pull secret when internal image is used - pullSecrets: deployment-key-light - - -podAnnotations: {} -## -## Pass extra environment variables to the container. -## -# extraVars: -# - name: EXTRA_VAR_1 -# value: extra-var-value-1 -# - name: EXTRA_VAR_2 -# value: extra-var-value-2 -## -## Create new service when true, and use the specified uner name when set to the name specified -## - -resources: - requests: - cpu: 25m - memory: 64Mi - limits: - cpu: 150m - memory: 128Mi - -## Configure pod autoscaling -## - -autoscaling: - # -- Enable autoscaling - enabled: false - # -- Minimum replicas - minReplicas: 1 - # -- Maximum replicas - maxReplicas: 3 - # -- CPU target for autoscaling trigger - targetCPUUtilizationPercentage: 70 - # -- Memory target for autoscaling trigger - targetMemoryUtilizationPercentage: 70 -## -## Prometheus Exporter / Metrics -## - -metrics: - # -- Enable prometheus metrics - enabled: true - # -- Port for prometheus metrics - port: 2112 - -log: - level: "INFO" - encoding: json - -## -## Kubernetes [SecurityContext](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) object. -## - -security: - # -- by default, apps run as non-root - runAsNonRoot: false - # -- User used by the apps - runAsUid: 0 - # -- Group used by the apps - runAsGid: 0 -## -## -service: - port: 8882 - -ocm: - connectionManager: - service: - tcp: - port: 8882 - host: "connection-manager.ocm" - nats: - server: "nats.ocm:4222" - name: "ssi_issuer_stream" - subjects: "connections.*,proofs.*,credentials.*,credentials.definition.*,credentials.offer.*,schemas.*,messages.*" - -ocmtest: - connectionManager: - service: - tcp: - port: 8882 - host: "connection-manager.ocm-test" - nats: - server: "nats.ocm-test:4222" - name: "ssi_holder_stream" - subjects: "connections.*,proofs.*,credentials.*,credentials.definition.*,credentials.offer.*,schemas.*,messages.*" - -ingress: - enabled: false \ No newline at end of file diff --git a/apps/connection-manager/deployment/local/Dockerfile b/apps/connection-manager/deployment/local/Dockerfile deleted file mode 100644 index 0ec6f0a7..00000000 --- a/apps/connection-manager/deployment/local/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM node:18.16.0-buster-slim - -RUN apt update -y && apt install python3 git make build-essential -y - -WORKDIR app - -COPY ./dist/apps/connection-manager . -COPY package.json yarn.lock ./ - -RUN yarn install - - -EXPOSE 8882 - -CMD ["node", "main.js"] - diff --git a/apps/connection-manager/jest.config.ts b/apps/connection-manager/jest.config.ts deleted file mode 100644 index 60f58d10..00000000 --- a/apps/connection-manager/jest.config.ts +++ /dev/null @@ -1,11 +0,0 @@ -/* eslint-disable */ -export default { - displayName: "connection-manager", - preset: "../../jest.preset.js", - testEnvironment: "node", - transform: { - "^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }], - }, - moduleFileExtensions: ["ts", "js", "html"], - coverageDirectory: "../../coverage/apps/connection-manager", -}; diff --git a/apps/connection-manager/project.json b/apps/connection-manager/project.json deleted file mode 100644 index 55b568a4..00000000 --- a/apps/connection-manager/project.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "name": "connection-manager", - "$schema": "../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "apps/connection-manager/src", - "projectType": "application", - "targets": { - "build": { - "executor": "@nx/webpack:webpack", - "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", - "options": { - "target": "node", - "compiler": "tsc", - "outputPath": "dist/apps/connection-manager", - "main": "apps/connection-manager/src/main.ts", - "tsConfig": "apps/connection-manager/tsconfig.app.json", - "isolatedConfig": true, - "webpackConfig": "apps/connection-manager/webpack.config.js" - }, - "configurations": { - "development": {}, - "production": {} - } - }, - "serve": { - "executor": "@nx/js:node", - "defaultConfiguration": "development", - "options": { - "buildTarget": "connection-manager:build" - }, - "configurations": { - "development": { - "buildTarget": "connection-manager:build:development" - }, - "production": { - "buildTarget": "connection-manager:build:production" - } - } - }, - "lint": { - "executor": "@nx/linter:eslint", - "outputs": ["{options.outputFile}"], - "options": { - "lintFilePatterns": ["apps/connection-manager/**/*.ts"] - } - }, - "test": { - "executor": "@nx/jest:jest", - "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], - "options": { - "jestConfig": "apps/connection-manager/jest.config.ts", - "passWithNoTests": true - }, - "configurations": { - "ci": { - "ci": true, - "codeCoverage": true - } - } - } - }, - "tags": [] -} diff --git a/apps/connection-manager/src/app/app.controller.ts b/apps/connection-manager/src/app/app.controller.ts deleted file mode 100644 index 067c9778..00000000 --- a/apps/connection-manager/src/app/app.controller.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { Body, Controller, Logger } from "@nestjs/common"; - -import { ProducerService } from "@ocm-engine/nats"; -import { MessagePattern, RpcException } from "@nestjs/microservices"; -import { - CloudEventDto, - ConnectionEvent, - CreateInvitationResponseDto, - GatewayAcceptedResponseDto, - makeEvent, - IdReqDto, -} from "@ocm-engine/dtos"; - -@Controller() -export class AppController { - private readonly logger: Logger = new Logger(AppController.name); - - constructor(private readonly producerService: ProducerService) {} - - @MessagePattern("connections") - async create( - @Body() - payload: { - data: null | CreateInvitationResponseDto | IdReqDto; - type: ConnectionEvent; - source: string; - }, - ): Promise<GatewayAcceptedResponseDto> { - this.logger.debug(JSON.stringify(payload, null, 2)); - - try { - const event = makeEvent(payload); - this.logger.debug(JSON.stringify(event, null, 2)); - - await this.producerService.publish<typeof payload.data>( - payload.type, - event as CloudEventDto<typeof payload.data>, - ); - - return GatewayAcceptedResponseDto.fromJson({ - id: event.id, - }); - } catch (e) { - this.logger.debug(JSON.stringify(e, null, 2)); - if (e instanceof Error) { - throw new RpcException(e.message); - } - - throw new RpcException("Internal server error"); - } - } -} diff --git a/apps/connection-manager/src/app/app.module.ts b/apps/connection-manager/src/app/app.module.ts deleted file mode 100644 index 5370512c..00000000 --- a/apps/connection-manager/src/app/app.module.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Module } from "@nestjs/common"; - -import { AppController } from "./app.controller"; -import { ProducerService } from "@ocm-engine/nats"; -import { ConfigModule } from "@nestjs/config"; -import { cmConfig, cmSchema, natsConfig, natsSchema } from "@ocm-engine/config"; -import Joi from "joi"; - -const validationSchema = Joi.object({ - nats: natsSchema, - cm: cmSchema, -}); - -@Module({ - imports: [ - ConfigModule.forRoot({ - isGlobal: true, - load: [natsConfig, cmConfig], - validationSchema, - }), - ], - controllers: [AppController], - providers: [ProducerService], -}) -export class AppModule {} diff --git a/apps/connection-manager/src/main.ts b/apps/connection-manager/src/main.ts deleted file mode 100644 index eb1af5cf..00000000 --- a/apps/connection-manager/src/main.ts +++ /dev/null @@ -1,36 +0,0 @@ -/** - * This is not a production server yet! - * This is only a minimal backend to get started. - */ - -import { Logger } from "@nestjs/common"; -import { NestFactory } from "@nestjs/core"; - -import { AppModule } from "./app/app.module"; -import { MicroserviceOptions, Transport } from "@nestjs/microservices"; -import { ConfigService } from "@nestjs/config"; -import { IConnectionManagerConfig } from "@ocm-engine/config"; -async function bootstrap() { - const app = await NestFactory.create(AppModule); - - const configService = app.get(ConfigService); - const cmConfig = configService.get<IConnectionManagerConfig>("cm")!; - - app.enableShutdownHooks(); - - const microservice = app.connectMicroservice<MicroserviceOptions>({ - transport: Transport.TCP, - options: { - host: cmConfig.host, - port: cmConfig.port, - }, - }); - - await app.startAllMicroservices(); - - app.enableShutdownHooks(); - - Logger.log("Application is running"); -} - -bootstrap(); diff --git a/apps/connection-manager/tsconfig.app.json b/apps/connection-manager/tsconfig.app.json deleted file mode 100644 index 954f3ad1..00000000 --- a/apps/connection-manager/tsconfig.app.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "../../dist/out-tsc", - "module": "commonjs", - "types": ["node"], - "emitDecoratorMetadata": true, - "target": "es2015" - }, - "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], - "include": ["src/**/*.ts"] -} diff --git a/apps/connection-manager/tsconfig.json b/apps/connection-manager/tsconfig.json deleted file mode 100644 index c1e2dd4e..00000000 --- a/apps/connection-manager/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "files": [], - "include": [], - "references": [ - { - "path": "./tsconfig.app.json" - }, - { - "path": "./tsconfig.spec.json" - } - ], - "compilerOptions": { - "esModuleInterop": true - } -} diff --git a/apps/connection-manager/tsconfig.spec.json b/apps/connection-manager/tsconfig.spec.json deleted file mode 100644 index 9b2a121d..00000000 --- a/apps/connection-manager/tsconfig.spec.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "../../dist/out-tsc", - "module": "commonjs", - "types": ["jest", "node"] - }, - "include": [ - "jest.config.ts", - "src/**/*.test.ts", - "src/**/*.spec.ts", - "src/**/*.d.ts" - ] -} diff --git a/apps/connection-manager/webpack.config.js b/apps/connection-manager/webpack.config.js deleted file mode 100644 index 0ab513e8..00000000 --- a/apps/connection-manager/webpack.config.js +++ /dev/null @@ -1,8 +0,0 @@ -const { composePlugins, withNx } = require("@nx/webpack"); - -// Nx plugins for webpack. -module.exports = composePlugins(withNx(), (config) => { - // Update the webpack config as needed here. - // e.g. `config.plugins.push(new MyPlugin())` - return config; -}); diff --git a/apps/gateway/.eslintrc.json b/apps/gateway/.eslintrc.json deleted file mode 100644 index 9d9c0db5..00000000 --- a/apps/gateway/.eslintrc.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "extends": ["../../.eslintrc.json"], - "ignorePatterns": ["!**/*"], - "overrides": [ - { - "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], - "rules": {} - }, - { - "files": ["*.ts", "*.tsx"], - "rules": {} - }, - { - "files": ["*.js", "*.jsx"], - "rules": {} - } - ] -} diff --git a/apps/gateway/README.md b/apps/gateway/README.md deleted file mode 100644 index 054da564..00000000 --- a/apps/gateway/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# OCM ENGINE - Gateway - -External service. - -This is the single point of communication, between Client and OCM. - -Gateway have a HTTP API described in gateway-swagger.json. It will accept all valid request and return a UUID. Then after the result is ready the gateway will push result object through websocket. Socket name can be configured according to usage. - - -## Attestation Manager setup - -### From the root of the project run: - -#### Install dependencies -``` -yarn install -``` -#### Copy .env.example to .env - -``` -cp .env.exampe .env -``` - -Do changes to the .env according to your needs. - -#### Start the agent locally: - -``` -yarn serve:gw -``` diff --git a/apps/gateway/deployment/ci-cd/Dockerfile b/apps/gateway/deployment/ci-cd/Dockerfile deleted file mode 100644 index 18b057de..00000000 --- a/apps/gateway/deployment/ci-cd/Dockerfile +++ /dev/null @@ -1,39 +0,0 @@ -FROM node:18.16.0-buster-slim - -# Argument handler a -ARG API_TOKEN -ARG JOB_ID - -# Instal required software -RUN apt update -y && apt install python3 git make build-essential wget unzip -y - -# Set the working directory -WORKDIR app - -# Set the ENV variables -ENV GITLAB_BASE_URL=https://code.vereign.com/api/v4 -ENV GITLAB_PROJECT_ID=662 -ENV TOKEN=$API_TOKEN -ENV ID=$JOB_ID - -# Download the artifacts from the GitLab API -RUN wget --header "PRIVATE-TOKEN: $TOKEN" -O artifacts.zip "${GITLAB_BASE_URL}/projects/${GITLAB_PROJECT_ID}/jobs/${ID}/artifacts" - -# Unzip the artifacts (if needed) - adjust this command based on your artifact type -RUN unzip -q artifacts.zip && rm artifacts.zip - -# Fix locations -RUN cp ./dist/apps/gateway/main.js . -RUN cp ./dist/apps/gateway/main.js.map . -RUN cp -r ./dist/libs/config . -RUN cp -r ./dist/libs/dtos . -RUN cp -r ./dist/libs/clients . - -RUN yarn install - -# Expose required ports -EXPOSE 8081 -EXPOSE 8881 - -# Command to run -CMD ["node", "main.js"] diff --git a/apps/gateway/deployment/ci-cd/helm/templates/_helpers.tpl b/apps/gateway/deployment/ci-cd/helm/templates/_helpers.tpl deleted file mode 100644 index 2c27cb68..00000000 --- a/apps/gateway/deployment/ci-cd/helm/templates/_helpers.tpl +++ /dev/null @@ -1,94 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "app.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "app.fullname" -}} -{{- $name := default .Chart.Name .Values.nameOverride -}} -{{- printf "%s-%s" $name .Release.Namespace | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create instance name based on app version and short image sha. -*/}} -{{- define "app.revision" -}} -{{- default .Release.Name .Values.appRel | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "app.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "app.labels" -}} -helm.sh/chart: {{ include "app.chart" . }} -{{ include "app.selectorLabels" . }} -app.kubernetes.io/version: {{ .Chart.AppVersion }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "app.selectorLabels" -}} -app.kubernetes.io/name: {{ include "app.name" . }} -app.kubernetes.io/component: {{ include "app.fullname" . }} -{{- end -}} - -{{/* -Metrics Annotations -*/}} -{{- define "app.metricsAnnotations" -}} -{{- if .Values.metrics.enabled -}} -prometheus.io/scrape: "true" -prometheus.io/port: "{{ .Values.metrics.port }}" -prometheus.io/path: {{ .Values.metrics.path | default "/metrics" | quote }} -{{- end -}} -{{- end -}} - -{{/* -Image string -*/}} -{{- define "app.image" -}} -{{- if .Values.image.sha -}} -{{ .Values.image.repository }}/{{ .Values.image.name }}@{{ .Values.image.sha }} -{{- else -}} -{{ .Values.image.repository }}/{{ .Values.image.name }}:{{ default .Chart.AppVersion .Values.image.tag }} -{{- end -}} -{{- end -}} - -{{/* -Security context -*/}} -{{- define "app.securitycontext" -}} -runAsNonRoot: {{ .Values.security.runAsNonRoot | default false }} -runAsGroup: {{ .Values.security.runAsGid | default 0 }} -runAsUser: {{ .Values.security.runAsUid | default 0 }} -fsGroup: {{ .Values.security.runAsGid | default 0 }} -{{- end -}} - -{{/* -PostgreSQL Connection string URI -*/}} -{{- define "app.postgresql.connectionstring" -}} -postgresql://{{ .Values.connectionManager.database.user }}:{{ .Values.connectionManager.database.password }}@{{ .Values.connectionManager.database.host }}:{{ .Values.connectionManager.database.port }}/{{ .Release.Namespace }}_{{ include "app.name" . | replace "-" "_" }}?schema={{ .Values.connectionManager.database.schema }} -{{- end -}} - -{{/* -Ingress custom path. -*/}} -{{- define "app.path" -}} -{{- default .Chart.Name .Values.ingress.pathOverride | replace "-manager" "" | trunc 63 | trimSuffix "-" -}} -{{- end -}} diff --git a/apps/gateway/deployment/ci-cd/helm/templates/deployment.yaml b/apps/gateway/deployment/ci-cd/helm/templates/deployment.yaml deleted file mode 100644 index 48a5eea6..00000000 --- a/apps/gateway/deployment/ci-cd/helm/templates/deployment.yaml +++ /dev/null @@ -1,97 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: "{{ template "app.name" . }}" - namespace: {{ .Release.Namespace }} - labels: - {{- include "app.labels" . | nindent 4 }} - app.kubernetes.io/instance: {{ include "app.revision" . }} - app.kubernetes.io/part-of: rse -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: RollingUpdate - rollingUpdate: - maxSurge: 1 - maxUnavailable: 0 - selector: - matchLabels: - {{- include "app.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "app.labels" . | nindent 8 }} - annotations: - {{- include "app.metricsAnnotations" . | nindent 8 }} -{{- if .Values.podAnnotations }} -{{ toYaml .Values.podAnnotations | indent 8 }} -{{- end }} - spec: - securityContext: -{{- include "app.securitycontext" . | nindent 8 }} - imagePullSecrets: - - name: {{ .Values.image.pullSecrets }} - containers: - - name: {{ template "app.name" . }} - image: "{{ .Values.image.repository }}/{{ .Values.image.name }}:{{ default .Chart.AppVersion .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy | quote }} - env: - {{- if eq .Release.Namespace "ocm" }} - - name: GATEWAY_HTTP_PORT - value: {{ .Values.ocm.gateway.http.port | quote }} - - name: GATEWAY_TCP_PORT - value: {{ .Values.ocm.gateway.tcp.port | quote }} - - name: GATEWAY_SOCKET_EVENT_NAME - value: {{ .Values.ocm.gateway.socket.event.name | quote }} - - name: GATEWAY_MESSAGE_PATTERN - value: {{ .Values.ocm.gateway.message.pattern | quote }} - - name: GATEWAY_HOST - value: {{ .Values.ocm.gateway.host | quote }} - - name: CONNECTION_SERVICE_TCP_PORT - value: {{ .Values.ocm.gateway.connection.service.tcp.port | quote }} - - name: CONNECTION_SERVICE_HOST - value: {{ .Values.ocm.gateway.connection.service.host | quote }} - - name: ATTESTATION_SERVICE_TCP_PORT - value: {{ .Values.ocm.gateway.attestation.service.tcp.port | quote }} - - name: ATTESTATION_SERVICE_HOST - value: {{ .Values.ocm.gateway.attestation.service.host | quote }} - - name: PROOF_SERVICE_TCP_PORT - value: {{ .Values.ocm.gateway.proof.service.tcp.port | quote }} - - name: PROOF_SERVICE_HOST - value: {{ .Values.ocm.gateway.proof.service.host | quote }} - {{- else if eq .Release.Namespace "ocm-test" }} - - name: GATEWAY_HTTP_PORT - value: {{ .Values.ocmtest.gateway.http.port | quote }} - - name: GATEWAY_TCP_PORT - value: {{ .Values.ocmtest.gateway.tcp.port | quote }} - - name: GATEWAY_SOCKET_EVENT_NAME - value: {{ .Values.ocmtest.gateway.socket.event.name | quote }} - - name: GATEWAY_MESSAGE_PATTERN - value: {{ .Values.ocmtest.gateway.message.pattern | quote }} - - name: GATEWAY_HOST - value: {{ .Values.ocmtest.gateway.host | quote }} - - name: CONNECTION_SERVICE_TCP_PORT - value: {{ .Values.ocmtest.gateway.connection.service.tcp.port | quote }} - - name: CONNECTION_SERVICE_HOST - value: {{ .Values.ocmtest.gateway.connection.service.host | quote }} - - name: ATTESTATION_SERVICE_TCP_PORT - value: {{ .Values.ocmtest.gateway.attestation.service.tcp.port | quote }} - - name: ATTESTATION_SERVICE_HOST - value: {{ .Values.ocmtest.gateway.attestation.service.host | quote }} - - name: PROOF_SERVICE_TCP_PORT - value: {{ .Values.ocmtest.gateway.proof.service.tcp.port | quote }} - - name: PROOF_SERVICE_HOST - value: {{ .Values.ocmtest.gateway.proof.service.host | quote }} - {{- end }} -{{- if .Values.extraVars }} -{{ toYaml .Values.extraVars | indent 8 }} -{{- end }} - ports: - {{- if .Values.metrics.enabled }} - - name: monitoring - containerPort: {{ .Values.metrics.port }} - {{- end }} - - name: http - containerPort: {{ .Values.service.port }} - resources: -{{ toYaml .Values.resources | indent 10 }} diff --git a/apps/gateway/deployment/ci-cd/helm/templates/hpa.yaml b/apps/gateway/deployment/ci-cd/helm/templates/hpa.yaml deleted file mode 100644 index fc5c29e7..00000000 --- a/apps/gateway/deployment/ci-cd/helm/templates/hpa.yaml +++ /dev/null @@ -1,27 +0,0 @@ -{{- if .Values.autoscaling.enabled }} -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - labels: - {{- include "app.labels" . | nindent 4 }} - name: {{ template "app.name" . }} - namespace: {{ .Release.Namespace }} -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: {{ template "app.name" . }} - minReplicas: {{ .Values.autoscaling.minReplicas }} - maxReplicas: {{ .Values.autoscaling.maxReplicas }} - metrics: -{{- with .Values.autoscaling.targetCPUUtilizationPercentage }} - - type: Resource - resource: - name: cpu -{{- end }} -{{- with .Values.autoscaling.targetMemoryUtilizationPercentage }} - - type: Resource - resource: - name: memory -{{- end }} -{{- end }} \ No newline at end of file diff --git a/apps/gateway/deployment/ci-cd/helm/values.yaml b/apps/gateway/deployment/ci-cd/helm/values.yaml deleted file mode 100644 index fd7d1261..00000000 --- a/apps/gateway/deployment/ci-cd/helm/values.yaml +++ /dev/null @@ -1,156 +0,0 @@ -# -- Default number of instances to start -replicaCount: 1 -# -- Application name -name: gateway -# -- Ovverwrites application name a -nameOverride: "" - -image: - repository: eu.gcr.io/vrgn-infra-prj - # -- Image name - name: gaiax/ocm/ocm-engine/gateway - # -- Image tag - # Uses .Chart.AppVersion if empty - tag: "" - # -- Image sha, usually generated by the CI - # Uses image.tag if empty - sha: "" - # -- Image pull policy - pullPolicy: IfNotPresent - # -- Image pull secret when internal image is used - pullSecrets: deployment-key-light - - -podAnnotations: {} -## -## Pass extra environment variables to the container. -## -# extraVars: -# - name: EXTRA_VAR_1 -# value: extra-var-value-1 -# - name: EXTRA_VAR_2 -# value: extra-var-value-2 -## -## Create new service when true, and use the specified uner name when set to the name specified -## - -resources: - requests: - cpu: 25m - memory: 64Mi - limits: - cpu: 150m - memory: 128Mi - -## Configure pod autoscaling -## - -autoscaling: - # -- Enable autoscaling - enabled: false - # -- Minimum replicas - minReplicas: 1 - # -- Maximum replicas - maxReplicas: 3 - # -- CPU target for autoscaling trigger - targetCPUUtilizationPercentage: 70 - # -- Memory target for autoscaling trigger - targetMemoryUtilizationPercentage: 70 -## -## Prometheus Exporter / Metrics -## - -metrics: - # -- Enable prometheus metrics - enabled: true - # -- Port for prometheus metrics - port: 2112 - -log: - level: "INFO" - encoding: json - -## -## Kubernetes [SecurityContext](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) object. -## - -security: - # -- by default, apps run as non-root - runAsNonRoot: false - # -- User used by the apps - runAsUid: 0 - # -- Group used by the apps - runAsGid: 0 -## -## -service: - port: 8081 - port1: 8881 - - -ocm: - gateway: - http: - port: 8081 - tcp: - port: 8881 - socket: - event: - name: message - message: - pattern: webhook - host: gateway.ocm - connection: - service: - tcp: - port: 8882 - host: connection-manager.ocm - attestation: - service: - tcp: - port: 8883 - host: attestation-manager.ocm - proof: - service: - tcp: - port: 8884 - host: proof-manager.ocm - -ocmtest: - gateway: - http: - port: 8081 - tcp: - port: 8881 - socket: - event: - name: message - message: - pattern: webhook - host: gateway.ocm-test - connection: - service: - tcp: - port: 8882 - host: connection-manager.ocm-test - attestation: - service: - tcp: - port: 8883 - host: attestation-manager.ocm-test - proof: - service: - tcp: - port: 8884 - host: proof-manager.ocm-test - -ingress: - enabled: true - annotations: - cert-manager.io/cluster-issuer: letsencrypt-production-http - kubernetes.io/ingress.class: nginx - nginx.ingress.kubernetes.io/rewrite-target: /$2 - tlsEnabled: true - frontendDomain: ssi-dev.vereign.com - frontendTlsSecretName: cert-manager-tls - pathOverride: "" diff --git a/apps/gateway/deployment/local/Dockerfile b/apps/gateway/deployment/local/Dockerfile deleted file mode 100644 index 25901e7f..00000000 --- a/apps/gateway/deployment/local/Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -FROM node:18.16.0-buster-slim - -RUN apt update -y && apt install python3 git make build-essential -y - -WORKDIR app - -COPY ./dist/apps/gateway . -COPY package.json yarn.lock ./ - -RUN yarn install - - -EXPOSE 8081 -EXPOSE 8881 - -CMD ["node", "main.js"] - diff --git a/apps/gateway/jest.config.ts b/apps/gateway/jest.config.ts deleted file mode 100644 index bfabc3f2..00000000 --- a/apps/gateway/jest.config.ts +++ /dev/null @@ -1,11 +0,0 @@ -/* eslint-disable */ -export default { - displayName: "gateway", - preset: "../../jest.preset.js", - testEnvironment: "node", - transform: { - "^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }], - }, - moduleFileExtensions: ["ts", "js", "html"], - coverageDirectory: "../../coverage/apps/gateway", -}; diff --git a/apps/gateway/src/app/app.controller.ts b/apps/gateway/src/app/app.controller.ts deleted file mode 100644 index 67a178b4..00000000 --- a/apps/gateway/src/app/app.controller.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { Controller, Body, Logger } from "@nestjs/common"; -import { EventsGateway } from "./events.gateway"; -import { MessagePattern } from "@nestjs/microservices"; -import { CloudEventDto } from "@ocm-engine/dtos"; -import { ConfigService } from "@nestjs/config"; -import { IGateway } from "@ocm-engine/config"; - -@Controller() -export class AppController { - private gatewayConfig: IGateway; - private readonly logger: Logger = new Logger(AppController.name); - - constructor( - private eventsGateway: EventsGateway, - private readonly configService: ConfigService, - ) { - this.gatewayConfig = configService.get<IGateway>("gateway"); - } - - @MessagePattern(process.env["GATEWAY_MESSAGE_PATTERN"]) - create<T>(@Body() dto: CloudEventDto<T>): string { - this.logger.debug( - `received event from agent, sending to web socket ${JSON.stringify( - dto, - null, - 2, - )}`, - ); - - this.eventsGateway.sentEvent(dto); - return "ok"; - } -} diff --git a/apps/gateway/src/app/app.module.ts b/apps/gateway/src/app/app.module.ts deleted file mode 100644 index 5591b06d..00000000 --- a/apps/gateway/src/app/app.module.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { Module, ValidationPipe } from "@nestjs/common"; - -import { EventsGateway } from "./events.gateway"; -import { ConfigModule } from "@nestjs/config"; -import { AppController } from "./app.controller"; -import { - amConfig, - amSchema, - cmConfig, - cmSchema, - gatewayConfig, - gatewaySchema, - pmConfig, - pmSchema, -} from "@ocm-engine/config"; -import { - AttestationManagerClient, - ConnectionManagerClient, - ProofManagerClient, -} from "@ocm-engine/clients"; -import Joi from "joi"; -import { ConnectionController } from "./managers/connection.controller"; -import { APP_PIPE } from "@nestjs/core"; -import { AttestationController } from "./managers/attestation.controller"; -import { ProofController } from "./managers/proof.controller"; - -const validationSchema = Joi.object({ - gateway: gatewaySchema, - cm: cmSchema, - am: amSchema, - pm: pmSchema, -}); - -@Module({ - imports: [ - ConfigModule.forRoot({ - isGlobal: true, - load: [gatewayConfig, cmConfig, amConfig, pmConfig], - validationSchema, - }), - ], - controllers: [ - AppController, - ConnectionController, - AttestationController, - ProofController, - ], - providers: [ - EventsGateway, - ConnectionManagerClient, - AttestationManagerClient, - ProofManagerClient, - { - provide: APP_PIPE, - useValue: new ValidationPipe({ - transform: true, - }), - }, - ], -}) -export class AppModule {} diff --git a/apps/gateway/src/app/decorators/IncludeOcmDtos.ts b/apps/gateway/src/app/decorators/IncludeOcmDtos.ts deleted file mode 100644 index f1e490e2..00000000 --- a/apps/gateway/src/app/decorators/IncludeOcmDtos.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { ApiExtraModels } from "@nestjs/swagger"; -import * as dtos from "@ocm-engine/dtos"; -import { applyDecorators } from "@nestjs/common"; - -const IncludeOcmDtos = () => { - // Filter and get only the classes from the dtos object - // eslint-disable-next-line @typescript-eslint/ban-types - const dtoClasses: Function[] = Object.values(dtos).filter( - (dto) => typeof dto === "function", - // eslint-disable-next-line @typescript-eslint/ban-types - ) as Function[]; - - return applyDecorators(ApiExtraModels(...dtoClasses)); -}; - -export default IncludeOcmDtos; diff --git a/apps/gateway/src/app/decorators/OcmGatewayResponse.ts b/apps/gateway/src/app/decorators/OcmGatewayResponse.ts deleted file mode 100644 index 227ce5a1..00000000 --- a/apps/gateway/src/app/decorators/OcmGatewayResponse.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { ApiResponse } from "@nestjs/swagger"; -import { applyDecorators } from "@nestjs/common"; -import { GatewayAcceptedResponseDto } from "@ocm-engine/dtos"; - -const OcmGatewayResponse = () => { - return applyDecorators( - ApiResponse({ - status: 201, - description: - "Request is accepted for execution, the response id will match the event id received from the web socket", - type: GatewayAcceptedResponseDto, - }), - ); -}; - -export default OcmGatewayResponse; diff --git a/apps/gateway/src/app/decorators/OcmInternalServerErrorResponse.ts b/apps/gateway/src/app/decorators/OcmInternalServerErrorResponse.ts deleted file mode 100644 index 60c090d1..00000000 --- a/apps/gateway/src/app/decorators/OcmInternalServerErrorResponse.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { ApiInternalServerErrorResponse } from "@nestjs/swagger"; -import { applyDecorators } from "@nestjs/common"; - -const OcmInternalServerErrorResponse = (name: string) => { - return applyDecorators( - ApiInternalServerErrorResponse({ - description: `Error in sending data to ${name}. This error shows that ${name} could not convert request to event or ${name} could not send the event to the broker.`, - content: { - "application/json": { - schema: { - type: "object", - properties: { - statusCode: { - type: "number", - example: 500, - }, - - message: { - type: "string", - example: "connect ECONNREFUSED 0.0.0.0:1234", - }, - }, - }, - }, - }, - }), - ); -}; - -export default OcmInternalServerErrorResponse; diff --git a/apps/gateway/src/app/events.gateway.ts b/apps/gateway/src/app/events.gateway.ts deleted file mode 100644 index b29decd9..00000000 --- a/apps/gateway/src/app/events.gateway.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { WebSocketGateway, WebSocketServer } from "@nestjs/websockets"; -import { Server, WebSocket } from "ws"; -import { CloudEventDto } from "@ocm-engine/dtos"; - -@WebSocketGateway() -export class EventsGateway { - @WebSocketServer() - server: Server; - - sentEvent<T>(dto: CloudEventDto<T>) { - this.server.clients.forEach((client) => { - if (client.readyState === WebSocket.OPEN) { - client.send(JSON.stringify(dto)); - } - }); - } -} diff --git a/apps/gateway/src/app/exception.handler.ts b/apps/gateway/src/app/exception.handler.ts deleted file mode 100644 index 7223c236..00000000 --- a/apps/gateway/src/app/exception.handler.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { - ExceptionFilter, - Catch, - ArgumentsHost, - HttpException, - HttpStatus, - BadRequestException, -} from "@nestjs/common"; - -@Catch() -export class AllExceptionsHandler implements ExceptionFilter { - catch(exception: unknown, host: ArgumentsHost) { - const ctx = host.switchToHttp(); - const response = ctx.getResponse(); - - const status = - exception instanceof HttpException - ? exception.getStatus() - : HttpStatus.INTERNAL_SERVER_ERROR; - - let message: string | string[] = "Internal server error"; - - if (exception instanceof Error) { - message = exception.message; - } - - if (exception instanceof BadRequestException) { - message = exception.getResponse() as string[]; - - response.status(status).json(message); - return; - } - - response.status(status).json({ - statusCode: status, - message, - }); - } -} diff --git a/apps/gateway/src/app/managers/attestation.controller.ts b/apps/gateway/src/app/managers/attestation.controller.ts deleted file mode 100644 index 52053a79..00000000 --- a/apps/gateway/src/app/managers/attestation.controller.ts +++ /dev/null @@ -1,657 +0,0 @@ -import { - Body, - Controller, - Get, - Param, - Post, - Delete, - UseFilters, - Query, -} from "@nestjs/common"; -import { AllExceptionsHandler } from "../exception.handler"; -import { AttestationManagerClient } from "@ocm-engine/clients"; -import { - CreateCredentialDefinitionRequestDto, - CreateSchemaRequestDto, - CredentialFilterDto, - OfferCredentialRequestDto, - GatewayAcceptedResponseDto, - CRED_DEF_CREATE, - CRED_DEF_LIST, - CRED_DEF_GET, - CRED_SEND_OFFER, - CRED_LIST, - CRED_GET, - CRED_OFFER_ACCEPT, - CRED_OFFER_DECLINE, - CRED_DELETE, - MakeBasicMessageRequestDto, - MessageFilterDto, - MESSAGE_MAKE, - MESSAGE_LIST, - MESSAGE_DELETE, - SCHEMA_CREATE, - SCHEMA_GET, - SCHEMA_LIST, - IdReqDto, - AcceptCredentialDto, -} from "@ocm-engine/dtos"; -import { ApiBadRequestResponse, ApiOperation } from "@nestjs/swagger"; -import IncludeOcmDtos from "../decorators/IncludeOcmDtos"; -import OcmGatewayResponse from "../decorators/OcmGatewayResponse"; -import OcmInternalServerErrorResponse from "../decorators/OcmInternalServerErrorResponse"; - -@UseFilters(AllExceptionsHandler) -@Controller("v1") -@IncludeOcmDtos() -export class AttestationController { - constructor(private readonly amClient: AttestationManagerClient) {} - - @Post("/schemas") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("attestation manager") - @ApiBadRequestResponse({ - description: "Validation error", - content: { - "application/json": { - schema: { - type: "object", - properties: { - statusCode: { - type: "number", - example: 400, - }, - - message: { - type: "array", - example: ["name must be a string", "name should not be empty"], - }, - error: { - type: "string", - example: "Bad Request", - }, - }, - }, - }, - }, - }) - @ApiOperation({ - summary: "Create schema", - description: - "Method will create schema. The id of the response will be matched when you receive event from the websocket", - tags: ["Schema"], - }) - async createSchema( - @Body() schemaDto: CreateSchemaRequestDto, - ): Promise<GatewayAcceptedResponseDto> { - return this.amClient.sendPayload<CreateSchemaRequestDto>({ - pattern: "schemas", - payload: { - source: "/schema", - data: schemaDto, - type: SCHEMA_CREATE, - }, - }); - } - - @Post("/schemas/get-by-id") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("attestation manager") - @ApiBadRequestResponse({ - description: "Validation error", - content: { - "application/json": { - schema: { - type: "object", - properties: { - statusCode: { - type: "number", - example: 400, - }, - - message: { - type: "array", - example: ["id must be a string", "id should not be empty"], - }, - error: { - type: "string", - example: "Bad Request", - }, - }, - }, - }, - }, - }) - @ApiOperation({ - summary: "Get schema by id", - description: - "Method will fetch specific schema or throw exception. The id of the response will be matched when you receive event from the websocket", - tags: ["Schema"], - }) - async getSchemaById( - @Body() dto: IdReqDto, - ): Promise<GatewayAcceptedResponseDto> { - return this.amClient.sendPayload<IdReqDto>({ - pattern: "schemas", - payload: { - source: "/schemas/get-by-id", - data: dto, - type: SCHEMA_GET, - }, - }); - } - - @Get("/schemas") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("attestation manager") - @ApiOperation({ - summary: "List all schemas", - description: - "Method will fetch all schemas. The id of the response will be matched when you receive event from the websocket", - tags: ["Schema"], - }) - async fetchSchemas(): Promise<GatewayAcceptedResponseDto> { - return this.amClient.sendPayload<null>({ - pattern: "schemas", - payload: { - source: "/schema", - data: null, - type: SCHEMA_LIST, - }, - }); - } - - @Get("/definitions") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("attestation manager") - @ApiOperation({ - summary: "List all created credential definitions", - description: - "Method list credential definition no filters applied. The id of the response will be matched when you receive event from the websocket", - tags: ["Credentials"], - }) - async credentialDefinitions(): Promise<GatewayAcceptedResponseDto> { - return this.amClient.sendPayload({ - pattern: "credentials", - payload: { - source: "/definitions", - data: null, - type: CRED_DEF_LIST, - }, - }); - } - - @Post("/definitions/get-by-id") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("attestation manager") - @ApiBadRequestResponse({ - description: "Validation error", - content: { - "application/json": { - schema: { - type: "object", - properties: { - statusCode: { - type: "number", - example: 400, - }, - - message: { - type: "array", - example: ["id must be a string", "id should not be empty"], - }, - error: { - type: "string", - example: "Bad Request", - }, - }, - }, - }, - }, - }) - @ApiOperation({ - summary: "Get credential definition by id", - description: - "Method will fetch specific credential definition or return null. The id of the response will be matched when you receive event from the websocket", - tags: ["Credentials"], - }) - async getCredentialDefinitionById( - @Body() dto: IdReqDto, - ): Promise<GatewayAcceptedResponseDto> { - return this.amClient.sendPayload<IdReqDto>({ - pattern: "credentials", - payload: { - source: "/definitions/get-by-id", - data: dto, - type: CRED_DEF_GET, - }, - }); - } - - @Post("/definitions") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("attestation manager") - @ApiBadRequestResponse({ - description: "Validation error", - content: { - "application/json": { - schema: { - type: "object", - properties: { - statusCode: { - type: "number", - example: 400, - }, - - message: { - type: "array", - example: [ - "schemaId must be a string", - "schemaId should not be empty", - "tag must be a string", - "tag should not be empty", - ], - }, - error: { - type: "string", - example: "Bad Request", - }, - }, - }, - }, - }, - }) - @ApiOperation({ - summary: "Create credential definition", - description: - "Method create credential definition. The id of the response will be matched when you receive event from the websocket", - tags: ["Credentials"], - }) - async createCredentialDefinition( - @Body() credentialDefinitionDto: CreateCredentialDefinitionRequestDto, - ): Promise<GatewayAcceptedResponseDto> { - return this.amClient.sendPayload({ - pattern: "credentials", - payload: { - source: "/definitions", - data: credentialDefinitionDto, - type: CRED_DEF_CREATE, - }, - }); - } - - @Post("/credentials/offers") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("attestation manager") - @ApiBadRequestResponse({ - description: "Validation error", - content: { - "application/json": { - schema: { - type: "object", - properties: { - statusCode: { - type: "number", - example: 400, - }, - - message: { - type: "array", - example: [ - "connectionId must be a string", - "connectionId should not be empty", - "credentialDefinitionId must be a string", - "credentialDefinitionId should not be empty", - ], - }, - error: { - type: "string", - example: "Bad Request", - }, - }, - }, - }, - }, - }) - @ApiOperation({ - summary: "Offer credential", - description: - "Method offer credential, it will create an offer and send it to specified receiver (connectionId). In case connectionId not provided, it will create connectionless credential offer. The id of the response will be matched when you receive event from the websocket", - tags: ["Credentials"], - }) - async offerCredential( - @Body() dto: OfferCredentialRequestDto, - ): Promise<GatewayAcceptedResponseDto> { - return this.amClient.sendPayload({ - pattern: "credentials", - payload: { - source: "/credentials/offers", - data: dto, - type: CRED_SEND_OFFER, - }, - }); - } - - @Get("/credentials") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("attestation manager") - @ApiOperation({ - summary: "List all credential", - description: - "Method list credential definition based on provided filters. The id of the response will be matched when you receive event from the websocket", - tags: ["Credentials"], - }) - async fetchCredentials( - @Query() credentialFilterDto: CredentialFilterDto, - ): Promise<GatewayAcceptedResponseDto> { - return this.amClient.sendPayload({ - pattern: "credentials", - payload: { - source: "/credentials", - data: credentialFilterDto, - type: CRED_LIST, - }, - }); - } - - @Get("/credentials/:id") - @OcmGatewayResponse() - @ApiBadRequestResponse({ - description: "Validation error", - content: { - "application/json": { - schema: { - type: "object", - properties: { - statusCode: { - type: "number", - example: 400, - }, - message: { - type: "array", - example: ["id must be a string", "id should not be empty"], - }, - error: { - type: "string", - example: "Bad Request", - }, - }, - }, - }, - }, - }) - @OcmInternalServerErrorResponse("attestation manager") - @ApiOperation({ - summary: "Get credential by ID", - description: - "Method retrieves a specific credential based on the provided ID or returns null if not found. The ID of the response will be matched when you receive an event from the websocket", - tags: ["Credentials"], - }) - async getCredentialById( - @Param("id") credentialId: string, - ): Promise<GatewayAcceptedResponseDto> { - const data = new IdReqDto(); - data.id = credentialId; - - return this.amClient.sendPayload<IdReqDto>({ - pattern: "credentials", - payload: { - source: "/credentials/:id", - data, - type: CRED_GET, - }, - }); - } - - @Post("/credentials/offers/accept") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("attestation manager") - @ApiOperation({ - summary: "Accept credential offers", - description: - "Method list accept credential offer. The id of the response will be matched when you receive event from the websocket", - tags: ["Credentials Offers"], - }) - async acceptCredential( - @Body() dto: AcceptCredentialDto, - ): Promise<GatewayAcceptedResponseDto> { - return this.amClient.sendPayload({ - pattern: "credentials", - payload: { - source: "/credentials/offers/accept", - data: dto, - type: CRED_OFFER_ACCEPT, - }, - }); - } - - @Post("/credentials/offers/:credential_record_id/decline") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("attestation manager") - @ApiOperation({ - summary: "Decline credential offers", - description: - "Method to decline a credential offer. The id of the response will be matched when you receive an event from the websocket.", - tags: ["Credentials Offers"], - }) - async declineCredential( - @Param("credential_record_id") credentialRecordId: string, - ): Promise<GatewayAcceptedResponseDto> { - const data = new IdReqDto(); - data.id = credentialRecordId; - - return this.amClient.sendPayload({ - pattern: "credentials", - payload: { - source: "/credentials/offers/:id/decline", - data, - type: CRED_OFFER_DECLINE, - }, - }); - } - - @Delete("/credentials/:id") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("attestation manager") - @ApiBadRequestResponse({ - description: "Validation error", - content: { - "application/json": { - schema: { - type: "object", - properties: { - statusCode: { - type: "number", - example: 400, - }, - message: { - type: "array", - example: [ - "credentialId must be a string", - "credentialId should not be empty", - ], - }, - error: { - type: "string", - example: "Bad Request", - }, - }, - }, - }, - }, - }) - @ApiOperation({ - summary: "Delete a credential by ID", - description: - "Method deletes a specific credential based on provided ID. The id of the response will be matched when you receive an event from the websocket", - tags: ["Credentials"], - }) - async deleteCredentialById( - @Param("id") credentialId: string, - ): Promise<GatewayAcceptedResponseDto> { - const data = new IdReqDto(); - data.id = credentialId; - - return this.amClient.sendPayload<IdReqDto>({ - pattern: "credentials", - payload: { - source: "/credentials/:id", - data, - type: CRED_DELETE, - }, - }); - } - - @Post("/messages") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("attestation manager") - @ApiBadRequestResponse({ - description: "Validation error", - content: { - "application/json": { - schema: { - type: "object", - properties: { - statusCode: { - type: "number", - example: 400, - }, - - message: { - type: "array", - example: [ - "connectionId must be a string", - "connectionId should not be empty", - "message must be a string", - "message should not be empty", - ], - }, - error: { - type: "string", - example: "Bad Request", - }, - }, - }, - }, - }, - }) - @ApiOperation({ - summary: "Send basic message", - description: - "Method will send basic message to a connection. The id of the response will be matched when you receive event from the websocket", - tags: ["Credentials Offers"], - }) - async sendMessage( - @Body() message: MakeBasicMessageRequestDto, - ): Promise<GatewayAcceptedResponseDto> { - return this.amClient.sendPayload({ - pattern: "messages", - payload: { - source: "/messages", - data: message, - type: MESSAGE_MAKE, - }, - }); - } - - @Get("/messages") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("attestation manager") - @ApiBadRequestResponse({ - description: "Validation error", - content: { - "application/json": { - schema: { - type: "object", - properties: { - statusCode: { - type: "number", - example: 400, - }, - message: { - type: "array", - example: [ - "message must be a string", - "message should not be empty", - ], - }, - error: { - type: "string", - example: "Bad Request", - }, - }, - }, - }, - }, - }) - @ApiOperation({ - summary: "Fetch messages based on filters", - description: - "Method will list and return messages based on the provided filters. The id of the response will be matched when you receive event from the websocket", - tags: ["Messages"], - }) - async fetchBasicMessages( - @Query() filter: MessageFilterDto, - ): Promise<GatewayAcceptedResponseDto> { - return this.amClient.sendPayload<MessageFilterDto>({ - pattern: "messages", - payload: { - source: "/messages", - data: filter, - type: MESSAGE_LIST, - }, - }); - } - - @Delete("/messages/:id") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("attestation manager") - @ApiBadRequestResponse({ - description: "Validation error", - content: { - "application/json": { - schema: { - type: "object", - properties: { - statusCode: { - type: "number", - example: 400, - }, - message: { - type: "array", - example: [ - "messageId must be a string", - "messageId should not be empty", - ], - }, - error: { - type: "string", - example: "Bad Request", - }, - }, - }, - }, - }, - }) - @ApiOperation({ - summary: "Delete message by ID", - description: - "Method will delete a specific message by ID. The id of the response will be matched when you receive an event from the websocket", - tags: ["Messages"], - }) - async deleteBasicMessage( - @Param("id") messageId: string, - ): Promise<GatewayAcceptedResponseDto> { - const data = new IdReqDto(); - data.id = messageId; - - return this.amClient.sendPayload({ - pattern: "messages", - payload: { - source: "/messages/:id", - data: data, - type: MESSAGE_DELETE, - }, - }); - } -} diff --git a/apps/gateway/src/app/managers/connection.controller.ts b/apps/gateway/src/app/managers/connection.controller.ts deleted file mode 100644 index 8d2ac857..00000000 --- a/apps/gateway/src/app/managers/connection.controller.ts +++ /dev/null @@ -1,177 +0,0 @@ -import { - BadRequestException, - Body, - Controller, - Delete, - Get, - Param, - Post, - UseFilters, -} from "@nestjs/common"; -import { ConnectionManagerClient } from "@ocm-engine/clients"; -import { - CONNECTION_ACCEPT, - CONNECTION_CREATE, - CONNECTION_DELETE, - CONNECTION_GET, - CONNECTION_LIST, - CreateInvitationResponseDto, - GatewayAcceptedResponseDto, - IdReqDto, -} from "@ocm-engine/dtos"; -import { AllExceptionsHandler } from "../exception.handler"; -import { ApiBadRequestResponse, ApiOperation } from "@nestjs/swagger"; -import IncludeOcmDtos from "../decorators/IncludeOcmDtos"; -import OcmGatewayResponse from "../decorators/OcmGatewayResponse"; -import OcmInternalServerErrorResponse from "../decorators/OcmInternalServerErrorResponse"; - -@UseFilters(AllExceptionsHandler) -@Controller("v1") -@IncludeOcmDtos() -export class ConnectionController { - constructor(private readonly cmClient: ConnectionManagerClient) {} - - @Post("/invitations") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("connection manager") - @ApiOperation({ - summary: "Create invitation for connection", - description: - "Method will create invitation url. The id of the response will be matched when you receive event from the websocket", - tags: ["Connections"], - }) - async createInvitation(): Promise<GatewayAcceptedResponseDto> { - return this.cmClient.sendPayload<null>({ - pattern: "connections", - payload: { - source: "/invitations", - data: null, - type: CONNECTION_CREATE, - }, - }); - } - - @Post("/invitations/accept") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("connection manager") - @ApiBadRequestResponse({ - description: "Validation error", - content: { - "application/json": { - schema: { - type: "object", - properties: { - statusCode: { - type: "number", - example: 400, - }, - - message: { - type: "array", - example: [ - "invitationUrl must be a string", - "invitationUrl should not be empty", - ], - }, - error: { - type: "string", - example: "Bad Request", - }, - }, - }, - }, - }, - }) - @ApiOperation({ - summary: "Accept invitation long and short urls for connection", - description: - "Method will accept long and short invitation urls and will return connection thought the websocket. The id of the response will be matched when you receive event from the websocket", - tags: ["Connections"], - }) - async acceptInvitation( - @Body() createInvitationDto: CreateInvitationResponseDto, - ): Promise<GatewayAcceptedResponseDto> { - try { - return this.cmClient.sendPayload<CreateInvitationResponseDto>({ - pattern: "connections", - payload: { - source: "/invitations/accept", - data: createInvitationDto, - type: CONNECTION_ACCEPT, - }, - }); - } catch (e) { - throw new BadRequestException(e); - } - } - - @Get("/connections") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("connection manager") - @ApiOperation({ - summary: "List all connections", - description: - "The id of the response will be matched when you receive event from the websocket", - tags: ["Connections"], - }) - async fetchConnections(): Promise<GatewayAcceptedResponseDto> { - return this.cmClient.sendPayload<null>({ - pattern: "connections", - payload: { - source: "/connections", - data: null, - type: CONNECTION_LIST, - }, - }); - } - - @Get("/connections/:id") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("connection manager") - @ApiOperation({ - summary: "Get connection by id", - description: - "The method will search for connection id, if not found null will be returned. The id of the response will be matched when you receive event from the websocket", - tags: ["Connections"], - }) - async getConnectionById( - @Param("id") id: string, - ): Promise<GatewayAcceptedResponseDto> { - const request = new IdReqDto(); - request.id = id; - - return this.cmClient.sendPayload<IdReqDto>({ - pattern: "connections", - payload: { - source: "/connections/:id", - data: request, - type: CONNECTION_GET, - }, - }); - } - - @Delete("/connections/:id") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("connection manager") - @ApiOperation({ - summary: "Delete connection by id", - description: - "The method will attempt to delete a connection by its ID. The id of the response will be matched when you receive an event from the websocket.", - tags: ["Connections"], - }) - async deleteConnectionById( - @Param("id") id: string, - ): Promise<GatewayAcceptedResponseDto> { - const request = new IdReqDto(); - request.id = id; - - return this.cmClient.sendPayload<IdReqDto>({ - pattern: "connections", - payload: { - source: "/connections/:id", - data: request, - type: CONNECTION_DELETE, - }, - }); - } -} diff --git a/apps/gateway/src/app/managers/proof.controller.ts b/apps/gateway/src/app/managers/proof.controller.ts deleted file mode 100644 index 792b36ab..00000000 --- a/apps/gateway/src/app/managers/proof.controller.ts +++ /dev/null @@ -1,205 +0,0 @@ -import { - Body, - Controller, - Get, - Param, - Post, - Delete, - UseFilters, - Query, -} from "@nestjs/common"; -import { - AcceptProofDto, - GatewayAcceptedResponseDto, - RequestProofDto, - ProofFilterDto, - PROOF_ACCEPT, - PROOF_DECLINE, - PROOF_GET, - PROOF_REQUEST, - PROOF_LIST, - PROOF_DELETE, - IdReqDto, -} from "@ocm-engine/dtos"; -import { AllExceptionsHandler } from "../exception.handler"; -import { ProofManagerClient } from "@ocm-engine/clients"; -import { ApiBadRequestResponse, ApiOperation } from "@nestjs/swagger"; -import IncludeOcmDtos from "../decorators/IncludeOcmDtos"; -import OcmGatewayResponse from "../decorators/OcmGatewayResponse"; -import OcmInternalServerErrorResponse from "../decorators/OcmInternalServerErrorResponse"; - -@UseFilters(AllExceptionsHandler) -@Controller("v1") -@IncludeOcmDtos() -export class ProofController { - constructor(private readonly pmClient: ProofManagerClient) {} - - @Get("/proofs") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("proof manager") - @ApiOperation({ - summary: "List received unaccepted proofs", - description: - "This method list proofs based on provided filters. The id of the response will be matched when you receive event from the websocket", - tags: ["Credentials Proof"], - }) - async fetchProofs( - @Query() proofFilterDto: ProofFilterDto, - ): Promise<GatewayAcceptedResponseDto> { - return this.pmClient.sendPayload({ - pattern: "proofs", - payload: { - source: "/proofs", - data: proofFilterDto, - type: PROOF_LIST, - }, - }); - } - - @Get("/proofs/:proof_record_id") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("proof manager") - @ApiOperation({ - summary: "Get a single proof record by providing proof record id.", - description: - "Method get proof by id. Status - request-receive. The id of the response will be matched when you receive event from the websocket", - tags: ["Credentials Proof"], - }) - async getProofById( - @Param("proof_record_id") proofRecordId: string, - ): Promise<GatewayAcceptedResponseDto> { - const data = new IdReqDto(); - data.id = proofRecordId; - - return this.pmClient.sendPayload<IdReqDto>({ - pattern: "proofs", - payload: { - source: "/credentials/proofs/:proof_record_id", - data, - type: PROOF_GET, - }, - }); - } - - @Post("/proofs/request") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("proof manager") - @ApiBadRequestResponse({ - description: "Validation error", - content: { - "application/json": { - schema: { - type: "object", - properties: { - statusCode: { - type: "number", - example: 400, - }, - - message: { - type: "array", - example: [ - "attributes must contain at least 1 elements", - "attributes must be an array", - ], - }, - error: { - type: "string", - example: "Bad Request", - }, - }, - }, - }, - }, - }) - @ApiOperation({ - summary: "Request proof for credential", - description: - "Method will request proof. If connection id is not passed, the proof will be OOB. The id of the response will be matched when you receive event from the websocket", - tags: ["Credentials Proof"], - }) - async requestProof( - @Body() requestProofDto: RequestProofDto, - ): Promise<GatewayAcceptedResponseDto> { - return this.pmClient.sendPayload<RequestProofDto>({ - pattern: "proofs", - payload: { - source: "/proofs/request", - data: requestProofDto, - type: PROOF_REQUEST, - }, - }); - } - - @Post(`/proofs/accept`) - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("proof manager") - @ApiOperation({ - summary: "Accept credential proof", - description: - "Method accept credential proof. The id of the response will be matched when you receive event from the websocket", - tags: ["Credentials Proof"], - }) - async acceptProof( - @Body() acceptProofRequestDto: AcceptProofDto, - ): Promise<GatewayAcceptedResponseDto> { - return this.pmClient.sendPayload<AcceptProofDto>({ - pattern: "proofs", - payload: { - source: "/proofs/accept", - data: acceptProofRequestDto, - type: PROOF_ACCEPT, - }, - }); - } - - @Post("/proofs/:proof_record_id/decline") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("proof manager") - @ApiOperation({ - summary: "Decline a proof request.", - description: - "Method to decline a proof request by id. Status - request-receive. The id of the response will be matched when you receive event from the websocket", - tags: ["Credentials Proof"], - }) - async declineProofRequest( - @Param("proof_record_id") proofRecordId: string, - ): Promise<GatewayAcceptedResponseDto> { - const data = new IdReqDto(); - data.id = proofRecordId; - - return this.pmClient.sendPayload<IdReqDto>({ - pattern: "proofs", - payload: { - source: "/proofs/:proof_record_id/decline", - data, - type: PROOF_DECLINE, - }, - }); - } - - @Delete("/proofs/:proof_record_id") - @OcmGatewayResponse() - @OcmInternalServerErrorResponse("proof manager") - @ApiOperation({ - summary: "Delete a proof record by its ID", - description: - "This method deletes a specific proof based on the provided ID. The ID of the response will be matched when you receive an event from the websocket", - tags: ["Credentials Proof"], - }) - async deleteProofById( - @Param("proof_record_id") proofRecordId: string, - ): Promise<GatewayAcceptedResponseDto> { - const data = new IdReqDto(); - data.id = proofRecordId; - - return this.pmClient.sendPayload<IdReqDto>({ - pattern: "proofs", - payload: { - source: "/proofs/:proof_record_id", - data, - type: PROOF_DELETE, - }, - }); - } -} diff --git a/apps/gateway/src/main.ts b/apps/gateway/src/main.ts deleted file mode 100644 index 33762f56..00000000 --- a/apps/gateway/src/main.ts +++ /dev/null @@ -1,74 +0,0 @@ -/** - * This is not a production server yet! - * This is only a minimal backend to get started. - */ - -import { Logger } from "@nestjs/common"; -import { NestFactory } from "@nestjs/core"; - -import { AppModule } from "./app/app.module"; - -import { MicroserviceOptions, Transport } from "@nestjs/microservices"; -import { ConfigService } from "@nestjs/config"; -import { IGateway } from "@ocm-engine/config"; -import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"; -import { WsAdapter } from "@nestjs/platform-ws"; -import * as fs from "fs"; - -async function bootstrap() { - const app = await NestFactory.create(AppModule); - - const origins = (process.env.ALLOWED_ORIGINS || "").split(","); - app.enableCors({ - origin: origins.length > 1 ? origins : origins[0] || "", - methods: "GET,HEAD,PUT,PATCH,POST,DELETE", - }); - app.useWebSocketAdapter(new WsAdapter(app)); - - const configService = app.get(ConfigService); - const gatewayConfig = configService.get<IGateway>("gateway")!; - - const globalPrefix = "api"; - app.setGlobalPrefix(globalPrefix); - app.enableShutdownHooks(); - - app.connectMicroservice<MicroserviceOptions>({ - transport: Transport.TCP, - options: { - host: gatewayConfig.host, - port: gatewayConfig.tcpPort, - }, - }); - - await app.startAllMicroservices(); - - app.enableShutdownHooks(); - - if (process.env.SWAGGER === "true") { - const config = new DocumentBuilder() - .setTitle("OCM Gateway") - .setDescription("OCM ENGINE GATEWAY API") - .setVersion("1.0") - .addServer(`http://${gatewayConfig.host}:${gatewayConfig.httpPort}`) - .build(); - - const document = SwaggerModule.createDocument(app, config); - fs.writeFileSync( - "./gateway-swagger.json", - JSON.stringify(document, null, 2), - ); - SwaggerModule.setup("api", app, document); - - Logger.log(`Swagger file written`); - return process.kill(0); - } - const port = gatewayConfig.httpPort || 3000; - - await app.listen(port, gatewayConfig.host); - - Logger.log( - `🚀 Application is running on: http://${gatewayConfig.host}:${port}/${globalPrefix}`, - ); -} - -bootstrap(); diff --git a/apps/gateway/tsconfig.app.json b/apps/gateway/tsconfig.app.json deleted file mode 100644 index 954f3ad1..00000000 --- a/apps/gateway/tsconfig.app.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "../../dist/out-tsc", - "module": "commonjs", - "types": ["node"], - "emitDecoratorMetadata": true, - "target": "es2015" - }, - "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], - "include": ["src/**/*.ts"] -} diff --git a/apps/gateway/tsconfig.json b/apps/gateway/tsconfig.json deleted file mode 100644 index c1e2dd4e..00000000 --- a/apps/gateway/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "files": [], - "include": [], - "references": [ - { - "path": "./tsconfig.app.json" - }, - { - "path": "./tsconfig.spec.json" - } - ], - "compilerOptions": { - "esModuleInterop": true - } -} diff --git a/apps/gateway/tsconfig.spec.json b/apps/gateway/tsconfig.spec.json deleted file mode 100644 index 9b2a121d..00000000 --- a/apps/gateway/tsconfig.spec.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "../../dist/out-tsc", - "module": "commonjs", - "types": ["jest", "node"] - }, - "include": [ - "jest.config.ts", - "src/**/*.test.ts", - "src/**/*.spec.ts", - "src/**/*.d.ts" - ] -} diff --git a/apps/gateway/webpack.config.js b/apps/gateway/webpack.config.js deleted file mode 100644 index 0ab513e8..00000000 --- a/apps/gateway/webpack.config.js +++ /dev/null @@ -1,8 +0,0 @@ -const { composePlugins, withNx } = require("@nx/webpack"); - -// Nx plugins for webpack. -module.exports = composePlugins(withNx(), (config) => { - // Update the webpack config as needed here. - // e.g. `config.plugins.push(new MyPlugin())` - return config; -}); diff --git a/apps/attestation-manager/.eslintrc.json b/apps/hin-agent/.eslintrc.json similarity index 100% rename from apps/attestation-manager/.eslintrc.json rename to apps/hin-agent/.eslintrc.json diff --git a/apps/hin-agent/README.md b/apps/hin-agent/README.md new file mode 100644 index 00000000..63a0c611 --- /dev/null +++ b/apps/hin-agent/README.md @@ -0,0 +1,32 @@ +# OCM ENGINE - AGENT + +Agent service is a wrapper around @ocm-engine/askar library. + +The agent can be started with two different mods - Rest and Consumer, default behaviour is a message consumer. + +Agent will consume messages from a broker (NATS) on a pre-configured stream and subjects. + +Then it will do execute the task and send result to the @ocm-engine/gateway. + +## Agent setup + +### From the root of the project run: + + +#### Install dependencies +``` +yarn install +``` +#### Copy .env.example to .env + +``` +cp .env.exampe .env +``` + +Do changes to the .env according to your needs. + +#### Start the agent locally: + +``` +yarn serve:agent +``` diff --git a/apps/attestation-manager/deployment/ci-cd/Dockerfile b/apps/hin-agent/deployment/ci-cd/Dockerfile similarity index 75% rename from apps/attestation-manager/deployment/ci-cd/Dockerfile rename to apps/hin-agent/deployment/ci-cd/Dockerfile index b5563b41..d141cf84 100644 --- a/apps/attestation-manager/deployment/ci-cd/Dockerfile +++ b/apps/hin-agent/deployment/ci-cd/Dockerfile @@ -23,16 +23,21 @@ RUN wget --header "PRIVATE-TOKEN: $TOKEN" -O artifacts.zip "${GITLAB_BASE_URL}/p RUN unzip -q artifacts.zip && rm artifacts.zip # Fix locations -RUN cp ./dist/apps/attestation-manager/main.js . -RUN cp ./dist/apps/attestation-manager/main.js.map . +RUN cp ./dist/apps/hin-agent/main.js . +RUN cp ./dist/apps/hin-agent/main.js.map . +RUN cp -r ./dist/libs/askar . +#RUN cp -r ./dist/libs/clients . # no need by backend RUN cp -r ./dist/libs/config . RUN cp -r ./dist/libs/dtos . -RUN cp -r ./dist/libs/nats . +RUN cp -r ./dist/libs/ledgers . RUN yarn install # Expose required ports -EXPOSE 8883 +EXPOSE 8080 +EXPOSE 8001 +EXPOSE 6001 -# Command to run +#####hashtag +# Command / Entrypoint CMD ["node", "main.js"] diff --git a/apps/gateway/deployment/ci-cd/helm/Chart.yaml b/apps/hin-agent/deployment/ci-cd/helm/Chart.yaml similarity index 73% rename from apps/gateway/deployment/ci-cd/helm/Chart.yaml rename to apps/hin-agent/deployment/ci-cd/helm/Chart.yaml index 29abdf2d..e90911dc 100644 --- a/apps/gateway/deployment/ci-cd/helm/Chart.yaml +++ b/apps/hin-agent/deployment/ci-cd/helm/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 appVersion: build-654 -description: gateway deployment -name: gateway +description: hin-agent deployment +name: hin-agent version: 0.0.2 icon: "https://www.vereign.com/wp-content/themes/vereign2020/images/vereign-logo.svg" diff --git a/apps/attestation-manager/deployment/ci-cd/helm/templates/_helpers.tpl b/apps/hin-agent/deployment/ci-cd/helm/templates/_helpers.tpl similarity index 100% rename from apps/attestation-manager/deployment/ci-cd/helm/templates/_helpers.tpl rename to apps/hin-agent/deployment/ci-cd/helm/templates/_helpers.tpl diff --git a/apps/hin-agent/deployment/ci-cd/helm/templates/deployment.yaml b/apps/hin-agent/deployment/ci-cd/helm/templates/deployment.yaml new file mode 100644 index 00000000..75d9ea00 --- /dev/null +++ b/apps/hin-agent/deployment/ci-cd/helm/templates/deployment.yaml @@ -0,0 +1,92 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: "{{ template "app.name" . }}" + namespace: {{ .Release.Namespace }} + labels: + {{- include "app.labels" . | nindent 4 }} + app.kubernetes.io/instance: {{ include "app.revision" . }} + app.kubernetes.io/part-of: rse +spec: + replicas: {{ .Values.replicaCount }} + strategy: + type: RollingUpdate + rollingUpdate: + maxSurge: 1 + maxUnavailable: 0 + selector: + matchLabels: + {{- include "app.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "app.labels" . | nindent 8 }} + annotations: + {{- include "app.metricsAnnotations" . | nindent 8 }} +{{- if .Values.podAnnotations }} +{{ toYaml .Values.podAnnotations | indent 8 }} +{{- end }} + spec: + securityContext: +{{- include "app.securitycontext" . | nindent 8 }} + imagePullSecrets: + - name: {{ .Values.image.pullSecrets }} + containers: + - name: {{ template "app.name" . }} + image: "{{ .Values.image.repository }}/{{ .Values.image.name }}:{{ default .Chart.AppVersion .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy | quote }} + env: + {{- if eq .Release.Namespace "hin" }} + - name: LEDGERS + value: {{ .Values.hin.agent.ledgers | quote }} + - name : AGENT_PEER_URL + value: {{ .Values.hin.agent.peer.url | quote }} + - name: AGENT_NAME + value: {{ .Values.hin.agent.name | quote }} + - name: AGENT_KEY + value: {{ .Values.hin.agent.key | quote }} + - name: AGENT_DID_SEED + value: {{ .Values.hin.agent.did.seed | quote }} + - name: AGENT_DB_HOST + value: {{ .Values.hin.agent.db.host | quote }} + - name: AGENT_DB_USER + value: {{ .Values.hin.agent.db.user | quote }} + - name: AGENT_DB_PASS + value: {{ .Values.hin.agent.db.pass | quote }} + - name: AGENT_PORT + value: {{ .Values.hin.agent.port | quote }} + - name: ALLOWED_ORIGINS + value: {{ .Values.hin.agent.allowedOrigin | quote }} + - name: AUTH_BASIC_USER + value: {{ .Values.hin.agent.api.basic.user | quote }} + - name: AUTH_BASIC_PASS + value: {{ .Values.hin.agent.api.basic.pass | quote }} + - name: AUTH_JWT_PUBLIC_KEY + value: {{ .Values.hin.agent.api.jwt.publicKey | quote }} + - name: HIN_SVDX_WEBHOOK_URL + value: {{ .Values.hin.agent.svdx.webhook.url | quote }} + - name: HIN_SVDX_BASIC_USER + value: {{ .Values.hin.agent.svdx.basic.user | quote }} + - name: HIN_SVDX_BASIC_PASS + value: {{ .Values.hin.agent.svdx.basic.pass | quote }} + - name: HIN_OOB_GOALS + value: {{ .Values.hin.agent.invitationGoals | quote }} + - name: HIN_WEBHOOK_URL + value: {{ .Values.hin.agent.oob.url | quote }} + {{- end }} +{{- if .Values.extraVars }} +{{ toYaml .Values.extraVars | indent 8 }} +{{- end }} + ports: + {{- if .Values.metrics.enabled }} + - name: monitoring + containerPort: {{ .Values.metrics.port }} + {{- end }} + - name: http + containerPort: {{ .Values.service.port }} + - name: peer + containerPort: {{ .Values.service.port1 }} + - name: http2 + containerPort: {{ .Values.service.port2 }} + resources: +{{ toYaml .Values.resources | indent 10 }} diff --git a/apps/gateway/deployment/ci-cd/helm/templates/ingress.yaml b/apps/hin-agent/deployment/ci-cd/helm/templates/ingress.yaml similarity index 63% rename from apps/gateway/deployment/ci-cd/helm/templates/ingress.yaml rename to apps/hin-agent/deployment/ci-cd/helm/templates/ingress.yaml index d4bcb022..01defc00 100644 --- a/apps/gateway/deployment/ci-cd/helm/templates/ingress.yaml +++ b/apps/hin-agent/deployment/ci-cd/helm/templates/ingress.yaml @@ -5,9 +5,6 @@ metadata: name: {{ template "app.name" . }} namespace: {{ .Release.Namespace }} annotations: - nginx.ingress.kubernetes.io/proxy-connect-timeout: "3600" - nginx.ingress.kubernetes.io/proxy-send-timeout: "3600" - nginx.ingress.kubernetes.io/proxy-read-timeout: "3600" {{ toYaml .Values.ingress.annotations | indent 4 }} labels: {{- include "app.labels" . | nindent 4 }} @@ -19,14 +16,23 @@ spec: secretName: {{ .Values.ingress.frontendTlsSecretName }} {{- end }} rules: + {{- if eq .Release.Namespace "hin" }} - host: {{ .Values.ingress.frontendDomain }} http: paths: - - path: /{{ .Release.Namespace }}-{{ template "app.path" . }}(/|$)(.*) + - path: /hin-agent(/|$)(.*) pathType: Prefix backend: service: name: {{ template "app.name" . }} port: - number: {{ .Values.service.port }} -{{- end }} \ No newline at end of file + number: {{ .Values.service.port1 }} + - path: /api-hin-agent(/|$)(.*) + pathType: Prefix + backend: + service: + name: {{ template "app.name" . }} + port: + number: {{ .Values.hin.agent.port }} + {{- end }} +{{- end }} diff --git a/apps/gateway/deployment/ci-cd/helm/templates/service.yaml b/apps/hin-agent/deployment/ci-cd/helm/templates/service.yaml similarity index 79% rename from apps/gateway/deployment/ci-cd/helm/templates/service.yaml rename to apps/hin-agent/deployment/ci-cd/helm/templates/service.yaml index d2687b90..46c59e5c 100644 --- a/apps/gateway/deployment/ci-cd/helm/templates/service.yaml +++ b/apps/hin-agent/deployment/ci-cd/helm/templates/service.yaml @@ -11,9 +11,11 @@ spec: - name: http port: {{ .Values.service.port }} targetPort: {{ .Values.service.port }} - - name: tcp + - name: http1 port: {{ .Values.service.port1 }} targetPort: {{ .Values.service.port1 }} + - name: http2 + port: {{ .Values.service.port2 }} + targetPort: {{ .Values.service.port2 }} selector: {{- include "app.selectorLabels" . | nindent 4 }} - diff --git a/apps/hin-agent/deployment/ci-cd/helm/values.yaml b/apps/hin-agent/deployment/ci-cd/helm/values.yaml new file mode 100644 index 00000000..73c5f1ee --- /dev/null +++ b/apps/hin-agent/deployment/ci-cd/helm/values.yaml @@ -0,0 +1,100 @@ +# -- Default number of instances to start ..... +replicaCount: 1 +# -- Application name ... +name: hin-agent +# -- Ovverwrites application name ... +nameOverride: "" + +image: + repository: eu.gcr.io/vrgn-infra-prj + # -- Image name .. + name: gaiax/ocm/ocm-engine/hin-agent + # -- Image tag .. + # Uses .Chart.AppVersion if empty . + tag: "" + # -- Image sha, usually generated by the CI . + # Uses image.tag if empty . + sha: "" + # -- Image pull policy . + pullPolicy: Always + # -- Image pull secret when internal image is used . + pullSecrets: deployment-key-light + +resources: + requests: + cpu: 250m + +autoscaling: + # -- Enable autoscaling . + enabled: false + # -- Minimum replicas . + minReplicas: 1 + # -- Maximum replicas . + maxReplicas: 3 + # -- CPU target for autoscaling trigger . + targetCPUUtilizationPercentage: 70 + # -- Memory target for autoscaling trigger . + targetMemoryUtilizationPercentage: 70 +## +## Prometheus Exporter / Metrics . +## + +metrics: + # -- Enable prometheus metrics . + enabled: true + # -- Port for prometheus metrics . + port: 2112 + +## +## Kubernetes [SecurityContext](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) object. +## + +security: + # -- by default, apps run as non-root . + runAsNonRoot: false + # -- User used by the apps . + runAsUid: 0 + # -- Group used by the apps . + runAsGid: 0 + +hin: + agent: + ledgers: "BCOVRIN_TEST" + peer: + url: "https://ssi-dev.vereign.com/hin-agent" + name: "hin-agent-dev" + key: "Fpvsvz0seqevq7RRiPbRT6oopAcrMXcaY8d" + did: + seed: "8rQuMQ6YeVF1CVyKp4KZTjikpwM4irGl26Ds" + port: 8080 + svdx: + basic: + user: "" + pass: "" + webhook: + url: "https://did.svdx.pro/ocm/connection" + db: + host: "" + user: "" + pass: "" + allowedOrigin: "*" + invitationGoals: "connection.exchange" + api: + jwt: + publicKey: "" + basic: + user: "ocmhin-admin" + pass: "" + oob: + url: "https://hin-dev.vereign.com" + +service: + port: 8080 + port1: 8001 + port2: 8010 + +ingress: + enabled: true + tlsEnabled: true + frontendDomain: ssi-dev.vereign.com + frontendTlsSecretName: cert-manager-tls diff --git a/apps/proof-manager/deployment/local/Dockerfile b/apps/hin-agent/deployment/local/Dockerfile similarity index 74% rename from apps/proof-manager/deployment/local/Dockerfile rename to apps/hin-agent/deployment/local/Dockerfile index 2f225456..e8c3e323 100644 --- a/apps/proof-manager/deployment/local/Dockerfile +++ b/apps/hin-agent/deployment/local/Dockerfile @@ -4,13 +4,13 @@ RUN apt update -y && apt install python3 git make build-essential -y WORKDIR app -COPY ./dist/apps/proof-manager . +COPY ./dist/apps/hin-agent . COPY package.json yarn.lock ./ RUN yarn install - -EXPOSE 8882 +EXPOSE 8080 +EXPOSE 8001 +EXPOSE 6001 CMD ["node", "main.js"] - diff --git a/apps/hin-agent/deployment/local/HinDockerfile b/apps/hin-agent/deployment/local/HinDockerfile new file mode 100644 index 00000000..50326cd4 --- /dev/null +++ b/apps/hin-agent/deployment/local/HinDockerfile @@ -0,0 +1,15 @@ +FROM node:18.16.0-buster-slim + +RUN apt update -y && apt install python3 git make cmake build-essential -y + +WORKDIR /app + +COPY . . + +RUN yarn install +RUN yarn build:hin-agent + +EXPOSE 8080 +EXPOSE 8001 + +CMD ["node", "./dist/apps/hin-agent/main.js"] diff --git a/apps/attestation-manager/jest.config.ts b/apps/hin-agent/jest.config.ts similarity index 67% rename from apps/attestation-manager/jest.config.ts rename to apps/hin-agent/jest.config.ts index 18a7bc1c..ffeddf42 100644 --- a/apps/attestation-manager/jest.config.ts +++ b/apps/hin-agent/jest.config.ts @@ -1,11 +1,13 @@ /* eslint-disable */ export default { - displayName: "attestation-manager", + displayName: "agent", preset: "../../jest.preset.js", testEnvironment: "node", transform: { "^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }], }, moduleFileExtensions: ["ts", "js", "html"], - coverageDirectory: "../../coverage/apps/attestation-manager", + coverageDirectory: "../../coverage/apps/hin-agent", + collectCoverage: true, + verbose: true, }; diff --git a/apps/gateway/project.json b/apps/hin-agent/project.json similarity index 71% rename from apps/gateway/project.json rename to apps/hin-agent/project.json index 4ffc547b..727ba92a 100644 --- a/apps/gateway/project.json +++ b/apps/hin-agent/project.json @@ -1,7 +1,7 @@ { - "name": "gateway", + "name": "hin-agent", "$schema": "../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "apps/gateway/src", + "sourceRoot": "apps/hin-agent/src", "projectType": "application", "targets": { "build": { @@ -11,11 +11,11 @@ "options": { "target": "node", "compiler": "tsc", - "outputPath": "dist/apps/gateway", - "main": "apps/gateway/src/main.ts", - "tsConfig": "apps/gateway/tsconfig.app.json", + "outputPath": "dist/apps/hin-agent", + "main": "apps/hin-agent/src/main.ts", + "tsConfig": "apps/hin-agent/tsconfig.app.json", "isolatedConfig": true, - "webpackConfig": "apps/gateway/webpack.config.js", + "webpackConfig": "apps/hin-agent/webpack.config.js", "transformers": [ { "name": "@nestjs/swagger/plugin", @@ -25,6 +25,7 @@ } ] }, + "configurations": { "development": {}, "production": {} @@ -34,14 +35,14 @@ "executor": "@nx/js:node", "defaultConfiguration": "development", "options": { - "buildTarget": "gateway:build" + "buildTarget": "agent:build" }, "configurations": { "development": { - "buildTarget": "gateway:build:development" + "buildTarget": "agent:build:development" }, "production": { - "buildTarget": "gateway:build:production" + "buildTarget": "agent:build:production" } } }, @@ -49,14 +50,14 @@ "executor": "@nx/linter:eslint", "outputs": ["{options.outputFile}"], "options": { - "lintFilePatterns": ["apps/gateway/**/*.ts"] + "lintFilePatterns": ["apps/hin-agent/**/*.ts"] } }, "test": { "executor": "@nx/jest:jest", "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], "options": { - "jestConfig": "apps/gateway/jest.config.ts", + "jestConfig": "apps/hin-agent/jest.config.ts", "passWithNoTests": true }, "configurations": { diff --git a/apps/hin-agent/src/app/app.module.ts b/apps/hin-agent/src/app/app.module.ts new file mode 100644 index 00000000..5769d21c --- /dev/null +++ b/apps/hin-agent/src/app/app.module.ts @@ -0,0 +1,37 @@ +import { Module } from "@nestjs/common"; + +import { AskarDynamicModule } from "@ocm-engine/askar"; +import { ConfigModule } from "@nestjs/config"; +import { + agentConfig, + agentSchema, + authConfig, + authSchema, + ledgersConfig, + ledgersSchema, +} from "@ocm-engine/config"; +import Joi from "joi"; +import { hinSchema } from "./config/hin.schema"; +import { hinConfig } from "./config/hin.config"; +import { AgentEventListenerService } from "./svdx/agent-event-listener.service"; + +const validationSchema = Joi.object({ + agent: agentSchema, + auth: authSchema, + ledgers: ledgersSchema, + hin: hinSchema, +}); + +@Module({ + imports: [ + AskarDynamicModule.forRootAsync(), + ConfigModule.forRoot({ + isGlobal: true, + load: [agentConfig, authConfig, ledgersConfig, hinConfig], + validationSchema, + }), + ], + controllers: [], + providers: [AgentEventListenerService], +}) +export class AppModule {} diff --git a/apps/hin-agent/src/app/config/hin.config.interface.ts b/apps/hin-agent/src/app/config/hin.config.interface.ts new file mode 100644 index 00000000..60630030 --- /dev/null +++ b/apps/hin-agent/src/app/config/hin.config.interface.ts @@ -0,0 +1,7 @@ +export interface IConfHin { + hinOobGoals: Array<string>; + hinSVDXWebHook: string; + hinSVDXBasicUser: string; + hinSVDXBasicPass: string; + hinWebHook: string; +} diff --git a/apps/hin-agent/src/app/config/hin.config.ts b/apps/hin-agent/src/app/config/hin.config.ts new file mode 100644 index 00000000..704d35f7 --- /dev/null +++ b/apps/hin-agent/src/app/config/hin.config.ts @@ -0,0 +1,17 @@ +import { registerAs } from "@nestjs/config"; +import * as process from "process"; +import { IConfHin } from "./hin.config.interface"; + +export const hinConfig = registerAs( + "hin", + (): IConfHin => ({ + hinOobGoals: + typeof process.env["HIN_OOB_GOALS"] !== "undefined" + ? process.env["HIN_OOB_GOALS"]!.split(",") + : [], + hinSVDXWebHook: process.env["HIN_SVDX_WEBHOOK_URL"]!, + hinSVDXBasicUser: process.env["HIN_SVDX_BASIC_USER"]!, + hinSVDXBasicPass: process.env["HIN_SVDX_BASIC_PASS"]!, + hinWebHook: process.env["HIN_WEBHOOK_URL"]!, + }), +); diff --git a/apps/hin-agent/src/app/config/hin.schema.ts b/apps/hin-agent/src/app/config/hin.schema.ts new file mode 100644 index 00000000..a4c11e06 --- /dev/null +++ b/apps/hin-agent/src/app/config/hin.schema.ts @@ -0,0 +1,9 @@ +import Joi from "joi"; + +export const hinSchema = Joi.object({ + HIN_SVDX_WEBHOOK_URL: Joi.string().required(), + HIN_SVDX_BASIC_USER: Joi.string().required(), + HIN_SVDX_BASIC_PASS: Joi.string().required(), + HIN_OOB_GOALS: Joi.string().required(), + HIN_WEBHOOK_URL: Joi.string().required(), +}); diff --git a/apps/hin-agent/src/app/svdx/agent-event-listener.service.ts b/apps/hin-agent/src/app/svdx/agent-event-listener.service.ts new file mode 100644 index 00000000..05eab2d4 --- /dev/null +++ b/apps/hin-agent/src/app/svdx/agent-event-listener.service.ts @@ -0,0 +1,105 @@ +import { Injectable, Logger, OnModuleInit } from "@nestjs/common"; +import { AskarService } from "@ocm-engine/askar"; +import { + BasicMessageEventTypes, + TrustPingEventTypes, + BasicMessageRole, + BasicMessageStateChangedEvent, + ConnectionEventTypes, + ConnectionStateChangedEvent, + ProofEventTypes, + ProofStateChangedEvent, + TrustPingResponseReceivedEvent, +} from "@credo-ts/core"; +import { MessageRecordDto } from "@ocm-engine/dtos"; +import { ConfigService } from "@nestjs/config"; +import { + svdxConnectionStateChangeHandler, + svdxProofStateChangeHandler, + webHookHandler, +} from "./svdx.utils"; +import { IConfHin } from "../config/hin.config.interface"; + +@Injectable() +export class AgentEventListenerService implements OnModuleInit { + private hinConfig: IConfHin | undefined; + private readonly logger: Logger = new Logger(AgentEventListenerService.name); + + constructor( + private readonly askar: AskarService, + private readonly configService: ConfigService, + ) {} + + onModuleInit(): void { + this.logger.debug("Agent is listening for AFJ events"); + this.hinConfig = this.configService.get<IConfHin>("hin"); + + this.askar.agent.events.on( + ConnectionEventTypes.ConnectionStateChanged, + async (ev: ConnectionStateChangedEvent) => { + this.logger.log("connection state event received"); + this.logger.debug(JSON.stringify(ev, null, 2)); + return svdxConnectionStateChangeHandler( + ev, + this.askar.agent, + this.hinConfig, + ); + }, + ); + + this.askar.agent.events.on( + ProofEventTypes.ProofStateChanged, + async (ev: ProofStateChangedEvent) => { + this.logger.log("proof state event received"); + this.logger.debug(JSON.stringify(ev, null, 2)); + + return svdxProofStateChangeHandler( + ev, + this.askar.agent, + this.hinConfig, + ); + }, + ); + + this.askar.agent.events.on( + TrustPingEventTypes.TrustPingResponseReceivedEvent, + async (ev: TrustPingResponseReceivedEvent) => { + return webHookHandler(this.hinConfig?.hinWebHook, "ping", { + thid: ev.payload.message.threadId, + connectionId: ev.payload.connectionRecord.id, + }); + }, + ); + + this.askar.agent.events.on( + BasicMessageEventTypes.BasicMessageStateChanged, + async (ev: BasicMessageStateChangedEvent) => { + if (ev.payload.basicMessageRecord.role === BasicMessageRole.Receiver) { + this.logger.debug(JSON.stringify(ev, null, 2)); + + const messageRecord = ev.payload.basicMessageRecord; + + const connectionInfo = await this.askar.agent.connections.findById( + messageRecord.connectionId, + ); + const label = connectionInfo?.theirLabel || ""; + const dto = MessageRecordDto.fromJson({ + id: messageRecord.id, + createdAt: messageRecord.createdAt, + updatedAt: messageRecord.updatedAt, + connectionId: messageRecord.connectionId, + role: messageRecord.role, + content: messageRecord.content, + sentTime: messageRecord.sentTime, + from: messageRecord.role === BasicMessageRole.Receiver ? label : "", + to: messageRecord.role === BasicMessageRole.Sender ? label : "", + }); + + this.logger.debug( + "agent is configured as rest, webhook still not implemented", + ); + } + }, + ); + } +} diff --git a/apps/hin-agent/src/app/svdx/svdx.utils.ts b/apps/hin-agent/src/app/svdx/svdx.utils.ts new file mode 100644 index 00000000..ceed737f --- /dev/null +++ b/apps/hin-agent/src/app/svdx/svdx.utils.ts @@ -0,0 +1,163 @@ +import { + Agent, + ConnectionStateChangedEvent, + DidExchangeRole, + ProofState, + ProofStateChangedEvent, +} from "@credo-ts/core"; +import { AnonCredsProof } from "@credo-ts/anoncreds"; +import { IConfHin } from "../config/hin.config.interface"; +import axios, { AxiosResponse } from "axios"; + +export const svdxProofStateChangeHandler = async ( + ev: ProofStateChangedEvent, + agent: Agent, + hinConfig?: IConfHin, +) => { + if (ProofState.Done !== ev.payload.proofRecord.state) { + return; + } + + const presentationMessage = await agent.proofs.findPresentationMessage( + ev.payload.proofRecord.id, + ); + + console.log(JSON.stringify(presentationMessage, null, 2)); + if (!presentationMessage) { + console.log("No presentation message found"); + return; + } + + const attachmentId = presentationMessage.formats[0].attachmentId; + + const attachment = + presentationMessage.getPresentationAttachmentById(attachmentId); + + console.log(JSON.stringify(attachment, null, 2)); + if (!attachment) { + console.log("No attachment found"); + return; + } + + const email = + attachment.getDataAsJson<AnonCredsProof>()?.requested_proof.revealed_attrs[ + "email" + ].raw; + + try { + console.log( + `sending data to svdx ${email}, ${ev.payload.proofRecord.connectionId}`, + ); + await axios.post( + hinConfig?.hinSVDXWebHook, + { + email, + connectionId: ev.payload.proofRecord.connectionId, + }, + { + auth: { + username: hinConfig?.hinSVDXBasicUser, + password: hinConfig?.hinSVDXBasicPass, + }, + }, + ); + } catch (e) { + console.log(JSON.stringify(e, null, 2)); + } +}; + +export const svdxConnectionStateChangeHandler = async ( + ev: ConnectionStateChangedEvent, + agent: Agent, + hinConfig?: IConfHin, +) => { + if ( + ev.payload.connectionRecord.role === DidExchangeRole.Responder && + ev.payload.connectionRecord.state !== "completed" + ) { + return; + } + + const outOfBandId = ev.payload.connectionRecord.outOfBandId; + + if (typeof outOfBandId === "undefined") { + console.log(JSON.stringify(ev.payload, null, 2)); + console.log("Out of Band id not found, skipping"); + return; + } + + const outOfBandRecord = await agent.oob.findById(outOfBandId); + + if (!outOfBandRecord) { + console.log(JSON.stringify(ev.payload, null, 2)); + console.log("No out of band record found"); + return; + } + + if ( + !outOfBandRecord.outOfBandInvitation.goal || + !hinConfig?.hinOobGoals.includes(outOfBandRecord.outOfBandInvitation.goal) + ) { + console.log(JSON.stringify(ev.payload, null, 2)); + console.log("This connection does not have any goals"); + return; + } + + try { + console.log(`Sending proof request, to ${ev.payload.connectionRecord.id}`); + await agent.proofs.requestProof({ + protocolVersion: "v2", + connectionId: ev.payload.connectionRecord.id, + proofFormats: { + anoncreds: { + name: "proof-request", + version: "1.0", + requested_attributes: { + email: { + name: "email", + }, + }, + }, + }, + }); + } catch (e) { + console.log(JSON.stringify(e, null, 2)); + console.log("failed to offer credential"); + } +}; + +export const webHookHandler = async <T>( + addr: string, + webHookTopic: string, + payload: T, +) => { + const promises: Promise<AxiosResponse>[] = []; + + const tokenUrlPairs = addr.split(";"); + + for (const pair of tokenUrlPairs) { + const [token, url] = pair.split("@"); + + const promise = axios.post(`${url}/topic/${webHookTopic}`, payload, { + headers: { + "X-Api-Key": token, + }, + }); + + promises.push(promise); + } + + const promiseResults = await Promise.allSettled(promises); + for (let index = 0; index < promiseResults.length; index++) { + const promiseResult = promiseResults[index]; + const [_, url] = tokenUrlPairs[index].split("@"); + + if (promiseResult.status === "rejected") { + console.log( + `Failed to send web hook to ${url}/topic/${webHookTopic}. Reason ${promiseResult.reason}`, + ); + continue; + } + console.log(`Successfully sent web hook to ${url}/topic/${webHookTopic}`); + } +}; diff --git a/apps/hin-agent/src/main.ts b/apps/hin-agent/src/main.ts new file mode 100644 index 00000000..4a0dece5 --- /dev/null +++ b/apps/hin-agent/src/main.ts @@ -0,0 +1,52 @@ +/** + * This is not a production server yet! + * This is only a minimal backend to get started. + */ + +import { Logger } from "@nestjs/common"; +import { NestFactory } from "@nestjs/core"; + +import { AppModule } from "./app/app.module"; +import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"; +import { urlencoded, json } from "express"; +import * as fs from "fs"; + +async function bootstrap() { + const app = await NestFactory.create(AppModule); + + const origins = (process.env.ALLOWED_ORIGINS || "").split(","); + app.enableCors({ + origin: origins.length > 1 ? origins : origins[0] || "", + methods: "GET,HEAD,PUT,PATCH,POST,DELETE", + }); + app.use(json({ limit: "40mb" })); + app.use(urlencoded({ extended: true, limit: "40mb" })); + + const globalPrefix = "api"; + app.setGlobalPrefix(globalPrefix); + const port = process.env.AGENT_PORT || 3001; + app.enableShutdownHooks(); + + if (process.env.SWAGGER === "true") { + const config = new DocumentBuilder() + .setTitle("Agent") + .setDescription("Agent API") + .setVersion("1.0") + .addBearerAuth() + .addBasicAuth() + .build(); + + const document = SwaggerModule.createDocument(app, config); + fs.writeFileSync("./agent-swagger.json", JSON.stringify(document, null, 2)); + SwaggerModule.setup("api", app, document); + Logger.log(`Swagger file written`); + return process.kill(0); + } + + await app.listen(port, "0.0.0.0"); + Logger.log( + `🚀 Application is running on: http://0.0.0.0:${port}/${globalPrefix}`, + ); +} + +bootstrap(); diff --git a/apps/attestation-manager/tsconfig.app.json b/apps/hin-agent/tsconfig.app.json similarity index 100% rename from apps/attestation-manager/tsconfig.app.json rename to apps/hin-agent/tsconfig.app.json diff --git a/apps/attestation-manager/tsconfig.json b/apps/hin-agent/tsconfig.json similarity index 100% rename from apps/attestation-manager/tsconfig.json rename to apps/hin-agent/tsconfig.json diff --git a/apps/attestation-manager/tsconfig.spec.json b/apps/hin-agent/tsconfig.spec.json similarity index 100% rename from apps/attestation-manager/tsconfig.spec.json rename to apps/hin-agent/tsconfig.spec.json diff --git a/apps/attestation-manager/webpack.config.js b/apps/hin-agent/webpack.config.js similarity index 100% rename from apps/attestation-manager/webpack.config.js rename to apps/hin-agent/webpack.config.js diff --git a/apps/proof-manager/.eslintrc.json b/apps/proof-manager/.eslintrc.json deleted file mode 100644 index 9d9c0db5..00000000 --- a/apps/proof-manager/.eslintrc.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "extends": ["../../.eslintrc.json"], - "ignorePatterns": ["!**/*"], - "overrides": [ - { - "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], - "rules": {} - }, - { - "files": ["*.ts", "*.tsx"], - "rules": {} - }, - { - "files": ["*.js", "*.jsx"], - "rules": {} - } - ] -} diff --git a/apps/proof-manager/README.md b/apps/proof-manager/README.md deleted file mode 100644 index 1d633654..00000000 --- a/apps/proof-manager/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# OCM ENGINE - Proof Managert - -Internal service. - -Connection manager accepts requests for proofs, that are coming from @ocm-engine/gateway api, then converts them to events and pushes to a NATS stream with specific for the event subject. - -## Proof Manager setup - -### From the root of the project run: - -#### Install dependencies -``` -yarn install -``` -#### Copy .env.example to .env - -``` -cp .env.exampe .env -``` - -Do changes to the .env according to your needs. - -#### Start the agent locally: - -``` -yarn serve:pm -``` diff --git a/apps/proof-manager/deployment/ci-cd/Dockerfile b/apps/proof-manager/deployment/ci-cd/Dockerfile deleted file mode 100644 index cf7af2f5..00000000 --- a/apps/proof-manager/deployment/ci-cd/Dockerfile +++ /dev/null @@ -1,38 +0,0 @@ -FROM node:18.16.0-buster-slim - -# Argument handler -ARG API_TOKEN -ARG JOB_ID - -# Instal required software -RUN apt update -y && apt install python3 git make build-essential wget unzip -y - -# Set the working directory -WORKDIR app - -# Set the ENV variables -ENV GITLAB_BASE_URL=https://code.vereign.com/api/v4 -ENV GITLAB_PROJECT_ID=662 -ENV TOKEN=$API_TOKEN -ENV ID=$JOB_ID - -# Download the artifacts from the GitLab API -RUN wget --header "PRIVATE-TOKEN: $TOKEN" -O artifacts.zip "${GITLAB_BASE_URL}/projects/${GITLAB_PROJECT_ID}/jobs/${ID}/artifacts" - -# Unzip the artifacts (if needed) - adjust this command based on your artifact type -RUN unzip -q artifacts.zip && rm artifacts.zip - -# Fix locations -RUN cp ./dist/apps/proof-manager/main.js . -RUN cp ./dist/apps/proof-manager/main.js.map . -RUN cp -r ./dist/libs/config . -RUN cp -r ./dist/libs/dtos . -RUN cp -r ./dist/libs/nats . - -RUN yarn install - -# Expose required ports -EXPOSE 8882 - -# Command to run -CMD ["node", "main.js"] diff --git a/apps/proof-manager/deployment/ci-cd/helm/Chart.yaml b/apps/proof-manager/deployment/ci-cd/helm/Chart.yaml deleted file mode 100644 index a99d0e07..00000000 --- a/apps/proof-manager/deployment/ci-cd/helm/Chart.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: v1 -appVersion: build-654 -description: proof-manager deployment -name: proof-manager -version: 0.0.2 -icon: "https://www.vereign.com/wp-content/themes/vereign2020/images/vereign-logo.svg" diff --git a/apps/proof-manager/deployment/ci-cd/helm/templates/_helpers.tpl b/apps/proof-manager/deployment/ci-cd/helm/templates/_helpers.tpl deleted file mode 100644 index 6cba3ffc..00000000 --- a/apps/proof-manager/deployment/ci-cd/helm/templates/_helpers.tpl +++ /dev/null @@ -1,94 +0,0 @@ -{{/* vim: set filetype=mustache: */}} -{{/* -Expand the name of the chart. -*/}} -{{- define "app.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create a fully qualified app name. -We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). -*/}} -{{- define "app.fullname" -}} -{{- $name := default .Chart.Name .Values.nameOverride -}} -{{- printf "%s-%s" $name .Release.Namespace | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create instance name based on app version and short image sha. -*/}} -{{- define "app.revision" -}} -{{- default .Release.Name .Values.appRel | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Create chart name and version as used by the chart label. -*/}} -{{- define "app.chart" -}} -{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} -{{- end -}} - -{{/* -Common labels -*/}} -{{- define "app.labels" -}} -helm.sh/chart: {{ include "app.chart" . }} -{{ include "app.selectorLabels" . }} -app.kubernetes.io/version: {{ .Chart.AppVersion }} -app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- end -}} - -{{/* -Selector labels -*/}} -{{- define "app.selectorLabels" -}} -app.kubernetes.io/name: {{ include "app.name" . }} -app.kubernetes.io/component: {{ include "app.fullname" . }} -{{- end -}} - -{{/* -Metrics Annotations -*/}} -{{- define "app.metricsAnnotations" -}} -{{- if .Values.metrics.enabled -}} -prometheus.io/scrape: "true" -prometheus.io/port: "{{ .Values.metrics.port }}" -prometheus.io/path: {{ .Values.metrics.path | default "/metrics" | quote }} -{{- end -}} -{{- end -}} - -{{/* -Image string -*/}} -{{- define "app.image" -}} -{{- if .Values.image.sha -}} -{{ .Values.image.repository }}/{{ .Values.image.name }}@{{ .Values.image.sha }} -{{- else -}} -{{ .Values.image.repository }}/{{ .Values.image.name }}:{{ default .Chart.AppVersion .Values.image.tag }} -{{- end -}} -{{- end -}} - -{{/* -Security context -*/}} -{{- define "app.securitycontext" -}} -runAsNonRoot: {{ .Values.security.runAsNonRoot | default false }} -runAsGroup: {{ .Values.security.runAsGid | default 0 }} -runAsUser: {{ .Values.security.runAsUid | default 0 }} -fsGroup: {{ .Values.security.runAsGid | default 0 }} -{{- end -}} - -{{/* -PostgreSQL Connection string URI -*/}} -{{- define "app.postgresql.connectionstring" -}} -postgresql://{{ .Values.attestationManager.database.user }}:{{ .Values.attestationManager.database.password }}@{{ .Values.attestationManager.database.host }}:{{ .Values.attestationManager.database.port }}/{{ .Release.Namespace }}_{{ include "app.name" . | replace "-" "_" }}?schema={{ .Values.attestationManager.database.schema }} -{{- end -}} - -{{/* -Ingress custom path. -*/}} -{{- define "app.path" -}} -{{- default .Chart.Name .Values.ingress.pathOverride | replace "-manager" "" | trunc 63 | trimSuffix "-" -}} -{{- end -}} diff --git a/apps/proof-manager/deployment/ci-cd/helm/templates/deployment.yaml b/apps/proof-manager/deployment/ci-cd/helm/templates/deployment.yaml deleted file mode 100644 index 67b9487e..00000000 --- a/apps/proof-manager/deployment/ci-cd/helm/templates/deployment.yaml +++ /dev/null @@ -1,73 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: "{{ template "app.name" . }}" - namespace: {{ .Release.Namespace }} - labels: - {{- include "app.labels" . | nindent 4 }} - app.kubernetes.io/instance: {{ include "app.revision" . }} - app.kubernetes.io/part-of: rse -spec: - replicas: {{ .Values.replicaCount }} - strategy: - type: RollingUpdate - rollingUpdate: - maxSurge: 1 - maxUnavailable: 0 - selector: - matchLabels: - {{- include "app.selectorLabels" . | nindent 6 }} - template: - metadata: - labels: - {{- include "app.labels" . | nindent 8 }} - annotations: - {{- include "app.metricsAnnotations" . | nindent 8 }} -{{- if .Values.podAnnotations }} -{{ toYaml .Values.podAnnotations | indent 8 }} -{{- end }} - spec: - securityContext: -{{- include "app.securitycontext" . | nindent 8 }} - imagePullSecrets: - - name: {{ .Values.image.pullSecrets }} - containers: - - name: {{ template "app.name" . }} - image: "{{ .Values.image.repository }}/{{ .Values.image.name }}:{{ default .Chart.AppVersion .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy | quote }} - env: - {{- if eq .Release.Namespace "ocm" }} - - name: NATS_SERVERS - value: {{ .Values.ocm.nats.server | quote }} - - name: NATS_STREAM_NAME - value: {{ .Values.ocm.nats.name | quote }} - - name: NATS_SUBJECTS - value: {{ .Values.ocm.nats.subjects | quote }} - - name: PROOF_SERVICE_TCP_PORT - value: {{ .Values.ocm.proofManager.service.tcp.port | quote }} - - name: PROOF_SERVICE_HOST - value: {{ .Values.ocm.proofManager.service.host | quote }} - {{- else if eq .Release.Namespace "ocm-test" }} - - name: NATS_SERVERS - value: {{ .Values.ocmtest.nats.server | quote }} - - name: NATS_STREAM_NAME - value: {{ .Values.ocmtest.nats.name | quote }} - - name: NATS_SUBJECTS - value: {{ .Values.ocmtest.nats.subjects | quote }} - - name: PROOF_SERVICE_TCP_PORT - value: {{ .Values.ocmtest.proofManager.service.tcp.port | quote }} - - name: PROOF_SERVICE_HOST - value: {{ .Values.ocmtest.proofManager.service.host | quote }} - {{- end }} -{{- if .Values.extraVars }} -{{ toYaml .Values.extraVars | indent 8 }} -{{- end }} - ports: - {{- if .Values.metrics.enabled }} - - name: monitoring - containerPort: {{ .Values.metrics.port }} - {{- end }} - - name: http - containerPort: {{ .Values.service.port }} - resources: -{{ toYaml .Values.resources | indent 10 }} diff --git a/apps/proof-manager/deployment/ci-cd/helm/templates/hpa.yaml b/apps/proof-manager/deployment/ci-cd/helm/templates/hpa.yaml deleted file mode 100644 index fc5c29e7..00000000 --- a/apps/proof-manager/deployment/ci-cd/helm/templates/hpa.yaml +++ /dev/null @@ -1,27 +0,0 @@ -{{- if .Values.autoscaling.enabled }} -apiVersion: autoscaling/v2 -kind: HorizontalPodAutoscaler -metadata: - labels: - {{- include "app.labels" . | nindent 4 }} - name: {{ template "app.name" . }} - namespace: {{ .Release.Namespace }} -spec: - scaleTargetRef: - apiVersion: apps/v1 - kind: Deployment - name: {{ template "app.name" . }} - minReplicas: {{ .Values.autoscaling.minReplicas }} - maxReplicas: {{ .Values.autoscaling.maxReplicas }} - metrics: -{{- with .Values.autoscaling.targetCPUUtilizationPercentage }} - - type: Resource - resource: - name: cpu -{{- end }} -{{- with .Values.autoscaling.targetMemoryUtilizationPercentage }} - - type: Resource - resource: - name: memory -{{- end }} -{{- end }} \ No newline at end of file diff --git a/apps/proof-manager/deployment/ci-cd/helm/templates/service.yaml b/apps/proof-manager/deployment/ci-cd/helm/templates/service.yaml deleted file mode 100644 index 21c57ac8..00000000 --- a/apps/proof-manager/deployment/ci-cd/helm/templates/service.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ template "app.name" . }} - namespace: {{ .Release.Namespace }} - labels: - {{- include "app.labels" . | nindent 4 }} -spec: - clusterIP: None - ports: - - name: http - port: {{ .Values.service.port }} - targetPort: {{ .Values.service.port }} - selector: - {{- include "app.selectorLabels" . | nindent 4 }} - diff --git a/apps/proof-manager/deployment/ci-cd/helm/values.yaml b/apps/proof-manager/deployment/ci-cd/helm/values.yaml deleted file mode 100644 index 37593443..00000000 --- a/apps/proof-manager/deployment/ci-cd/helm/values.yaml +++ /dev/null @@ -1,112 +0,0 @@ -# -- Default number of instances to start -replicaCount: 1 -# -- Application name -name: proof-manager -# -- Ovverwrites application name -nameOverride: "" - -image: - repository: eu.gcr.io/vrgn-infra-prj - # -- Image name - name: gaiax/ocm/ocm-engine/proof-manager - # -- Image tag - # Uses .Chart.AppVersion if empty - tag: "" - # -- Image sha, usually generated by the CI - # Uses image.tag if empty - sha: "" - # -- Image pull policy - pullPolicy: IfNotPresent - # -- Image pull secret when internal image is used - pullSecrets: deployment-key-light - - -podAnnotations: {} -## -## Pass extra environment variables to the container. -## -# extraVars: -# - name: EXTRA_VAR_1 -# value: extra-var-value-1 -# - name: EXTRA_VAR_2 -# value: extra-var-value-2 -## -## Create new service when true, and use the specified uner name when set to the name specified -## - -resources: - requests: - cpu: 25m - memory: 64Mi - limits: - cpu: 150m - memory: 128Mi - -## Configure pod autoscaling -## - -autoscaling: - # -- Enable autoscaling - enabled: false - # -- Minimum replicas - minReplicas: 1 - # -- Maximum replicas - maxReplicas: 3 - # -- CPU target for autoscaling trigger - targetCPUUtilizationPercentage: 70 - # -- Memory target for autoscaling trigger - targetMemoryUtilizationPercentage: 70 -## -## Prometheus Exporter / Metrics -## - -metrics: - # -- Enable prometheus metrics - enabled: true - # -- Port for prometheus metrics - port: 2112 - -log: - level: "INFO" - encoding: json - -## -## Kubernetes [SecurityContext](https://kubernetes.io/docs/tasks/configure-pod-container/security-context/) object. -## - -security: - # -- by default, apps run as non-root - runAsNonRoot: false - # -- User used by the apps - runAsUid: 0 - # -- Group used by the apps - runAsGid: 0 -## -## -service: - port: 8884 - -ocm: - proofManager: - service: - tcp: - port: 8884 - host: "proof-manager.ocm" - nats: - server: "nats.ocm:4222" - name: "ssi_issuer_stream" - subjects: "connections.*,proofs.*,credentials.*,credentials.definition.*,credentials.offer.*,schemas.*,messages.*" - -ocmtest: - proofManager: - service: - tcp: - port: 8884 - host: "proof-manager.ocm-test" - nats: - server: "nats.ocm-test:4222" - name: "ssi_holder_stream" - subjects: "connections.*,proofs.*,credentials.*,credentials.definition.*,credentials.offer.*,schemas.*,messages.*" - -ingress: - enabled: false \ No newline at end of file diff --git a/apps/proof-manager/jest.config.ts b/apps/proof-manager/jest.config.ts deleted file mode 100644 index 946e79d2..00000000 --- a/apps/proof-manager/jest.config.ts +++ /dev/null @@ -1,11 +0,0 @@ -/* eslint-disable */ -export default { - displayName: "proof-manager", - preset: "../../jest.preset.js", - testEnvironment: "node", - transform: { - "^.+\\.[tj]s$": ["ts-jest", { tsconfig: "<rootDir>/tsconfig.spec.json" }], - }, - moduleFileExtensions: ["ts", "js", "html"], - coverageDirectory: "../../coverage/apps/proof-manager", -}; diff --git a/apps/proof-manager/project.json b/apps/proof-manager/project.json deleted file mode 100644 index 18af77b9..00000000 --- a/apps/proof-manager/project.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "name": "proof-manager", - "$schema": "../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "apps/proof-manager/src", - "projectType": "application", - "targets": { - "build": { - "executor": "@nx/webpack:webpack", - "outputs": ["{options.outputPath}"], - "defaultConfiguration": "production", - "options": { - "target": "node", - "compiler": "tsc", - "outputPath": "dist/apps/proof-manager", - "main": "apps/proof-manager/src/main.ts", - "tsConfig": "apps/proof-manager/tsconfig.app.json", - "isolatedConfig": true, - "webpackConfig": "apps/proof-manager/webpack.config.js" - }, - "configurations": { - "development": {}, - "production": {} - } - }, - "serve": { - "executor": "@nx/js:node", - "defaultConfiguration": "development", - "options": { - "buildTarget": "proof-manager:build" - }, - "configurations": { - "development": { - "buildTarget": "proof-manager:build:development" - }, - "production": { - "buildTarget": "proof-manager:build:production" - } - } - }, - "lint": { - "executor": "@nx/linter:eslint", - "outputs": ["{options.outputFile}"], - "options": { - "lintFilePatterns": ["apps/proof-manager/**/*.ts"] - } - }, - "test": { - "executor": "@nx/jest:jest", - "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], - "options": { - "jestConfig": "apps/proof-manager/jest.config.ts", - "passWithNoTests": true - }, - "configurations": { - "ci": { - "ci": true, - "codeCoverage": true - } - } - } - }, - "tags": [] -} diff --git a/apps/proof-manager/src/app/app.controller.ts b/apps/proof-manager/src/app/app.controller.ts deleted file mode 100644 index 889c4b14..00000000 --- a/apps/proof-manager/src/app/app.controller.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { Body, Controller, Logger } from "@nestjs/common"; - -import { ProducerService } from "@ocm-engine/nats"; -import { MessagePattern, RpcException } from "@nestjs/microservices"; -import { - AcceptProofDto, - IdReqDto, - CloudEventDto, - GatewayAcceptedResponseDto, - makeEvent, - ProofEvent, -} from "@ocm-engine/dtos"; - -@Controller() -export class AppController { - private readonly logger: Logger = new Logger(AppController.name); - - constructor(private readonly producerService: ProducerService) {} - - @MessagePattern("proofs") - async create( - @Body() - payload: { - data: null | AcceptProofDto | IdReqDto; - type: ProofEvent; - source: string; - }, - ): Promise<GatewayAcceptedResponseDto> { - this.logger.debug(JSON.stringify(payload, null, 2)); - - try { - const event = makeEvent(payload); - this.logger.debug(JSON.stringify(event, null, 2)); - - await this.producerService.publish<typeof payload.data>( - payload.type, - event as CloudEventDto<typeof payload.data>, - ); - - return GatewayAcceptedResponseDto.fromJson({ - id: event.id, - }); - } catch (e) { - this.logger.debug(JSON.stringify(e, null, 2)); - if (e instanceof Error) { - throw new RpcException(e.message); - } - - throw new RpcException("Internal server error"); - } - } -} diff --git a/apps/proof-manager/src/app/app.module.ts b/apps/proof-manager/src/app/app.module.ts deleted file mode 100644 index b3d4f05d..00000000 --- a/apps/proof-manager/src/app/app.module.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Module } from "@nestjs/common"; - -import { AppController } from "./app.controller"; -import Joi from "joi"; -import { natsConfig, natsSchema, pmConfig, pmSchema } from "@ocm-engine/config"; -import { ConfigModule } from "@nestjs/config"; -import { ProducerService } from "@ocm-engine/nats"; - -const validationSchema = Joi.object({ - nats: natsSchema, - pm: pmSchema, -}); - -@Module({ - imports: [ - ConfigModule.forRoot({ - isGlobal: true, - load: [natsConfig, pmConfig], - validationSchema, - }), - ], - controllers: [AppController], - providers: [ProducerService], -}) -export class AppModule {} diff --git a/apps/proof-manager/src/main.ts b/apps/proof-manager/src/main.ts deleted file mode 100644 index c963b203..00000000 --- a/apps/proof-manager/src/main.ts +++ /dev/null @@ -1,37 +0,0 @@ -/** - * This is not a production server yet! - * This is only a minimal backend to get started. - */ - -import { Logger } from "@nestjs/common"; -import { NestFactory } from "@nestjs/core"; - -import { AppModule } from "./app/app.module"; -import { ConfigService } from "@nestjs/config"; -import { MicroserviceOptions, Transport } from "@nestjs/microservices"; -import { IProofManagerConfig } from "@ocm-engine/config"; - -async function bootstrap() { - const app = await NestFactory.create(AppModule); - - const configService = app.get(ConfigService); - const pm = configService.get<IProofManagerConfig>("pm")!; - - app.enableShutdownHooks(); - - const microservice = app.connectMicroservice<MicroserviceOptions>({ - transport: Transport.TCP, - options: { - host: pm.host, - port: pm.port, - }, - }); - - await app.startAllMicroservices(); - - app.enableShutdownHooks(); - - Logger.log(`Application is running ${pm.host}:${pm.port}`); -} - -bootstrap(); diff --git a/apps/proof-manager/tsconfig.app.json b/apps/proof-manager/tsconfig.app.json deleted file mode 100644 index 954f3ad1..00000000 --- a/apps/proof-manager/tsconfig.app.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "../../dist/out-tsc", - "module": "commonjs", - "types": ["node"], - "emitDecoratorMetadata": true, - "target": "es2015" - }, - "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], - "include": ["src/**/*.ts"] -} diff --git a/apps/proof-manager/tsconfig.json b/apps/proof-manager/tsconfig.json deleted file mode 100644 index c1e2dd4e..00000000 --- a/apps/proof-manager/tsconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "files": [], - "include": [], - "references": [ - { - "path": "./tsconfig.app.json" - }, - { - "path": "./tsconfig.spec.json" - } - ], - "compilerOptions": { - "esModuleInterop": true - } -} diff --git a/apps/proof-manager/tsconfig.spec.json b/apps/proof-manager/tsconfig.spec.json deleted file mode 100644 index 9b2a121d..00000000 --- a/apps/proof-manager/tsconfig.spec.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "../../dist/out-tsc", - "module": "commonjs", - "types": ["jest", "node"] - }, - "include": [ - "jest.config.ts", - "src/**/*.test.ts", - "src/**/*.spec.ts", - "src/**/*.d.ts" - ] -} diff --git a/apps/proof-manager/webpack.config.js b/apps/proof-manager/webpack.config.js deleted file mode 100644 index 0ab513e8..00000000 --- a/apps/proof-manager/webpack.config.js +++ /dev/null @@ -1,8 +0,0 @@ -const { composePlugins, withNx } = require("@nx/webpack"); - -// Nx plugins for webpack. -module.exports = composePlugins(withNx(), (config) => { - // Update the webpack config as needed here. - // e.g. `config.plugins.push(new MyPlugin())` - return config; -}); diff --git a/compose/docker-compose.infra.yml b/compose/docker-compose.infra.yml index dcc23f57..cc0d7e03 100644 --- a/compose/docker-compose.infra.yml +++ b/compose/docker-compose.infra.yml @@ -11,13 +11,3 @@ services: volumes: - ./data/db/:/var/lib/postgresql/data/ - broker: - command: ["-js", "-sd", "/data", "-m","8222", "-D"] - container_name: broker - image: 'nats:latest' - ports: - - '4222:4222' #Nats server port - - '8222:8222' #Nats server Monitering port - volumes: - - ./data/nats/:/data/ - diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml index 3646983b..eb47ab59 100644 --- a/compose/docker-compose.yml +++ b/compose/docker-compose.yml @@ -2,26 +2,6 @@ version: '3.8' services: #===================== ISSUER =========================# - gateway-issuer: - profiles: - - issuer - container_name: gw-issuer - image: node:18.16.0 - volumes: - - ./data/node_modules:/app/node_modules - - ./data/dist/apps/gateway:/app/ - working_dir: /app - command: node main.js - ports: - - "8081:8081" - - "8881:8881" - env_file: - - ./env/issuer.env - depends_on: - builder: - condition: service_completed_successfully - cm-issuer: - condition: service_started agent-issuer: profiles: @@ -41,93 +21,8 @@ services: depends_on: builder: condition: service_completed_successfully - cm-issuer: - condition: service_started - - cm-issuer: - container_name: cm-issuer - image: node:18.16.0 - volumes: - - ./data/node_modules:/app/node_modules - - ./data/dist/apps/connection-manager:/app/ - working_dir: /app - command: node main.js - profiles: - - issuer - env_file: - - ./env/issuer.env - ports: - - "8882" - depends_on: - builder: - condition: service_completed_successfully - broker-issuer: - condition: service_started - - am-issuer: - container_name: am-issuer - image: node:18.16.0 - volumes: - - ./data/node_modules:/app/node_modules - - ./data/dist/apps/attestation-manager:/app/ - working_dir: /app - command: node main.js - profiles: - - issuer - env_file: - - ./env/issuer.env - ports: - - "8883" - depends_on: - builder: - condition: service_completed_successfully - broker-issuer: - condition: service_started - - - pm-issuer: - container_name: pm-issuer - image: node:18.16.0 - volumes: - - ./data/node_modules:/app/node_modules - - ./data/dist/apps/proof-manager:/app/ - working_dir: /app - command: node main.js - profiles: - - issuer - env_file: - - ./env/issuer.env - ports: - - "8884" - depends_on: - builder: - condition: service_completed_successfully - broker-issuer: - condition: service_started - #===================== holder =========================# - gateway-holder: - profiles: - - holder - container_name: gw-holder - image: node:18.16.0 - volumes: - - ./data/node_modules:/app/node_modules - - ./data/dist/apps/gateway:/app/ - working_dir: /app - command: node main.js - ports: - - "8091:8081" - - "8891:8881" - env_file: - - ./env/holder.env - depends_on: - builder: - condition: service_completed_successfully - cm-issuer: - condition: service_started - agent-holder: profiles: - holder @@ -146,69 +41,6 @@ services: depends_on: builder: condition: service_completed_successfully - cm-issuer: - condition: service_started - - cm-holder: - container_name: cm-holder - image: node:18.16.0 - volumes: - - ./data/node_modules:/app/node_modules - - ./data/dist/apps/connection-manager:/app/ - working_dir: /app - command: node main.js - profiles: - - holder - env_file: - - ./env/holder.env - ports: - - "8882" - depends_on: - builder: - condition: service_completed_successfully - broker-issuer: - condition: service_started - - am-holder: - container_name: am-holder - image: node:18.16.0 - volumes: - - ./data/node_modules:/app/node_modules - - ./data/dist/apps/attestation-manager:/app/ - working_dir: /app - command: node main.js - profiles: - - holder - env_file: - - ./env/holder.env - ports: - - "8883" - depends_on: - builder: - condition: service_completed_successfully - broker-issuer: - condition: service_started - - - pm-holder: - container_name: pm-holder - image: node:18.16.0 - volumes: - - ./data/node_modules:/app/node_modules - - ./data/dist/apps/proof-manager:/app/ - working_dir: /app - command: node main.js - profiles: - - holder - env_file: - - ./env/holder.env - ports: - - "8884" - depends_on: - builder: - condition: service_completed_successfully - broker-issuer: - condition: service_started #===================== INFRA =========================# builder: @@ -244,27 +76,3 @@ services: volumes: - ./data/db/:/var/lib/postgresql/data/ - broker-issuer: - profiles: - - issuer - command: ["-js", "-sd", "/data", "-m","8222", "-D"] - container_name: broker-issuer - image: 'nats:latest' - ports: - - '4222' #Nats server port - - '8222:8222' #Nats server Monitering port - volumes: - - ./data/issuer/nats/:/data/ - - broker-holder: - profiles: - - holder - command: ["-js", "-sd", "/data", "-m","8222", "-D"] - container_name: broker-holder - image: 'nats:latest' - ports: - - '4222' #Nats server port - - '8223:8222' #Nats server Monitering port - volumes: - - ./data/holder/nats/:/data/ - diff --git a/compose/env/holder.env b/compose/env/holder.env index f45841ee..364a9968 100644 --- a/compose/env/holder.env +++ b/compose/env/holder.env @@ -1,7 +1,8 @@ LEDGERS="BCOVRIN_TEST" IDUNION_KEY= +IDUNION_BASIC_USER= +IDUNION_BASIC_PASS= -AGENT_PEER_URL="http://agent-holder:6001" AGENT_NAME=DEV_AGENT_HOLDER_OCM_4 # this should be changed to company name AGENT_KEY=DEV_AGENT_HOLDER_OCM_4 #example random string AGENT_DID_SEED=2000000000000000CCA120000000TCuste21jsjs #did private key seed min lenght 32 @@ -9,28 +10,5 @@ AGENT_DB_HOST=pg_db:5432 AGENT_DB_USER=postgres AGENT_DB_PASS=postgres AGENT_PORT=8081 -AGENT_CONSUMER_NAME=agent_1 -AGENT_IS_REST=false -AGENT_MAX_MESSAGES=10 -AGENT_RETE_LIMIT=5 - +AGENT_PEER_URL="http://agent-holder:6001" AGENT_PEER_PORT=6001 -NATS_SUBJECTS="connections.,proofs.,credentials.,credentials.definition.,credentials.offer.,schemas.,messages.*" - -NATS_SERVERS=broker-holder:4222 -NATS_STREAM_NAME=ssi_holder_stream -NATS_SUBJECTS="connections.*,proofs.*,credentials.*,schemas.*,messages.*" - -GATEWAY_HTTP_PORT=8081 -GATEWAY_TCP_PORT=8881 -GATEWAY_MESSAGE_PATTERN=webhook -GATEWAY_HOST=gateway-holder - -CONNECTION_SERVICE_TCP_PORT=8882 -CONNECTION_SERVICE_HOST=cm-holder - -ATTESTATION_SERVICE_TCP_PORT=8883 -ATTESTATION_SERVICE_HOST=am-holder - -PROOF_SERVICE_TCP_PORT=8884 -PROOF_SERVICE_HOST=pm-holder diff --git a/compose/env/holder.simple.env b/compose/env/holder.simple.env index 6fb198c5..dd5bfe95 100644 --- a/compose/env/holder.simple.env +++ b/compose/env/holder.simple.env @@ -1,11 +1,8 @@ LEDGERS="BCOVRIN_TEST" - IDUNION_KEY= IDUNION_BASIC_USER= IDUNION_BASIC_PASS= -AGENT_PEER_URL=http://agent-holder-simple:6001 -AGENT_PEER_PORT=6001 AGENT_NAME=DEV_SIMPLE_AGENT_HOLDER_OCM_3919 # this should be changed to company name AGENT_KEY=DEV_SIMPLE_AGENT_HOLDER_OCM_3818 #example random string AGENT_DID_SEED=jhPctchKaUfyZ1ioz6Fjypoasdhjahjsiscdkd23ozxflxkaKD0RR4TICwx @@ -13,25 +10,5 @@ AGENT_DB_HOST=pg_db:5432 AGENT_DB_USER=postgres AGENT_DB_PASS=postgres AGENT_PORT=8080 -AGENT_CONSUMER_NAME=agent_1 -AGENT_IS_REST=true -AGENT_MAX_MESSAGES=10 -AGENT_RETE_LIMIT=5 - -NATS_SERVERS=broker-holder:4222 -NATS_STREAM_NAME=ssi_holder_stream -NATS_SUBJECTS="connections.*,proofs.*,credentials.*,schemas.*" - -GATEWAY_HTTP_PORT=8081 -GATEWAY_TCP_PORT=8881 -GATEWAY_MESSAGE_PATTERN=webhook -GATEWAY_HOST=gateway-holder - -CONNECTION_SERVICE_TCP_PORT=8882 -CONNECTION_SERVICE_HOST=cm-holder - -ATTESTATION_SERVICE_TCP_PORT=8883 -ATTESTATION_SERVICE_HOST=ap-holder - -PROOF_SERVICE_TCP_PORT=8884 -PROOF_SERVICE_HOST=pm-holder +AGENT_PEER_URL=http://agent-holder-simple:6001 +AGENT_PEER_PORT=6001 diff --git a/compose/env/issuer.env b/compose/env/issuer.env index d83cd989..4157e894 100644 --- a/compose/env/issuer.env +++ b/compose/env/issuer.env @@ -1,7 +1,8 @@ LEDGERS="BCOVRIN_TEST" IDUNION_KEY= +IDUNION_BASIC_USER= +IDUNION_BASIC_PASS= -AGENT_PEER_URL="http://agent-issuer:8001" AGENT_NAME=DEV_AGENT_ISSUER_OCM_4 # this should be changed to company name AGENT_KEY=DEV_AGENT_ISSUER_OCM_4 #example random string AGENT_DID_SEED=20000000000000000000000aca0xxaDTCuste21udhasjs #did private key seed min lenght 32 @@ -9,25 +10,5 @@ AGENT_DB_HOST=pg_db:5432 AGENT_DB_USER=postgres AGENT_DB_PASS=postgres AGENT_PORT=8081 -AGENT_CONSUMER_NAME=agent_1 -AGENT_IS_REST=false -AGENT_MAX_MESSAGES=10 -AGENT_RETE_LIMIT=5 - -NATS_SERVERS=broker-issuer:4222 -NATS_STREAM_NAME=ssi_issuer_stream -NATS_SUBJECTS="connections.*,proofs.*,credentials.*,credentials.definition.*,credentials.offer.*,schemas.*,messages.*" - -GATEWAY_HTTP_PORT=8081 -GATEWAY_TCP_PORT=8881 -GATEWAY_MESSAGE_PATTERN=webhook -GATEWAY_HOST=gateway-issuer - -CONNECTION_SERVICE_TCP_PORT=8882 -CONNECTION_SERVICE_HOST=cm-issuer - -ATTESTATION_SERVICE_TCP_PORT=8883 -ATTESTATION_SERVICE_HOST=am-issuer - -PROOF_SERVICE_TCP_PORT=8884 -PROOF_SERVICE_HOST=pm-issuer +AGENT_PEER_URL="http://agent-issuer:8001" +AGENT_PEER_PORT=8001 diff --git a/compose/env/issuer.simple.env b/compose/env/issuer.simple.env index 86e1d2bf..2a6493d2 100644 --- a/compose/env/issuer.simple.env +++ b/compose/env/issuer.simple.env @@ -1,11 +1,8 @@ LEDGERS="BCOVRIN_TEST" - IDUNION_KEY=6eb8859f-dd7f-445a-bc37-ba986145d3b6 IDUNION_BASIC_USER=idunion4ssi IDUNION_BASIC_PASS=7eDZ+LrUbV5bCRwe6Ki0Gw== -AGENT_PEER_URL=http://agent-issuer-simple:8001 -AGENT_PEER_PORT=8001 AGENT_NAME=DEV_SIMPLE_AGENT_ISSUER_OCM_45 # this should be changed to company name AGENT_KEY=DEV_SIMPLE_AGENT_ISSUER_OCM_45 #example random string AGENT_DID_SEED=Cd0VanW68R3HCaskjdakjsNpiuadscmsBBPP3DV6pMdwDFdHvPasdasdas @@ -13,25 +10,5 @@ AGENT_DB_HOST=pg_db:5432 AGENT_DB_USER=postgres AGENT_DB_PASS=postgres AGENT_PORT=8080 -AGENT_CONSUMER_NAME=agent_1 -AGENT_IS_REST=true -AGENT_MAX_MESSAGES=10 -AGENT_RETE_LIMIT=5 - -NATS_SERVERS=broker-issuer:4222 -NATS_STREAM_NAME=ssi_issuer_stream -NATS_SUBJECTS="connections.*,proofs.*,credentials.*,schemas.*" - -GATEWAY_HTTP_PORT=8081 -GATEWAY_TCP_PORT=8881 -GATEWAY_MESSAGE_PATTERN=webhook -GATEWAY_HOST=gateway-issuer - -CONNECTION_SERVICE_TCP_PORT=8882 -CONNECTION_SERVICE_HOST=cm-issuer - -ATTESTATION_SERVICE_TCP_PORT=8883 -ATTESTATION_SERVICE_HOST=ap-issuer - -PROOF_SERVICE_TCP_PORT=8884 -PROOF_SERVICE_HOST=pm-issuer +AGENT_PEER_URL=http://agent-issuer-simple:8001 +AGENT_PEER_PORT=8001 diff --git a/libs/askar/src/agent.utils.ts b/libs/askar/src/agent.utils.ts index 1f70543d..334d72da 100644 --- a/libs/askar/src/agent.utils.ts +++ b/libs/askar/src/agent.utils.ts @@ -4,13 +4,11 @@ import { AutoAcceptProof, BaseEvent, ConnectionsModule, - ConnectionStateChangedEvent, CredentialEventTypes, CredentialsModule, CredentialState, CredentialStateChangedEvent, DidDocument, - DidExchangeRole, DidsModule, EncryptedMessage, JsonTransformer, @@ -37,7 +35,6 @@ import { import { AnonCredsCredentialFormatService, AnonCredsModule, - AnonCredsProof, AnonCredsProofFormatService, } from "@credo-ts/anoncreds"; import { @@ -51,8 +48,6 @@ import { anoncreds } from "@hyperledger/anoncreds-nodejs"; import { AskarModule } from "@credo-ts/askar"; import { ariesAskar } from "@hyperledger/aries-askar-nodejs"; import { Key as AskarKey, KeyAlgs } from "@hyperledger/aries-askar-shared"; -import { IConfAgent } from "@ocm-engine/config"; -import axios, { AxiosResponse } from "axios"; import { catchError, filter, @@ -299,128 +294,6 @@ export const setupSubjectTransports = (agents: Agent[]) => { } }; -export const svdxProofStateChangeHandler = async ( - ev: ProofStateChangedEvent, - agent: Agent, - config?: IConfAgent, -) => { - if (ProofState.Done !== ev.payload.proofRecord.state) { - return; - } - - const presentationMessage = await agent.proofs.findPresentationMessage( - ev.payload.proofRecord.id, - ); - - console.log(JSON.stringify(presentationMessage, null, 2)); - if (!presentationMessage) { - console.log("No presentation message found"); - return; - } - - const attachmentId = presentationMessage.formats[0].attachmentId; - - const attachment = - presentationMessage.getPresentationAttachmentById(attachmentId); - - console.log(JSON.stringify(attachment, null, 2)); - if (!attachment) { - console.log("No attachment found"); - return; - } - - const email = - attachment.getDataAsJson<AnonCredsProof>()?.requested_proof.revealed_attrs[ - "email" - ].raw; - - if (!config?.agentSVDXWebHook) { - console.log("Agent SVDX web hook not set"); - return; - } - - try { - console.log( - `sending data to svdx ${email}, ${ev.payload.proofRecord.connectionId}`, - ); - await axios.post( - config?.agentSVDXWebHook, - { - email, - connectionId: ev.payload.proofRecord.connectionId, - }, - { - auth: { - username: config?.agentSVDXBasicUser, - password: config?.agentSVDXBasicPass, - }, - }, - ); - } catch (e) { - console.log(JSON.stringify(e, null, 2)); - } -}; - -export const svdxConnectionStateChangeHandler = async ( - ev: ConnectionStateChangedEvent, - agent: Agent, - config?: IConfAgent, -) => { - if ( - ev.payload.connectionRecord.role === DidExchangeRole.Responder && - ev.payload.connectionRecord.state !== "completed" - ) { - return; - } - - const outOfBandId = ev.payload.connectionRecord.outOfBandId; - - if (typeof outOfBandId === "undefined") { - console.log(JSON.stringify(ev.payload, null, 2)); - console.log("Out of Band id not found, skipping"); - return; - } - - const outOfBandRecord = await agent.oob.findById(outOfBandId); - - if (!outOfBandRecord) { - console.log(JSON.stringify(ev.payload, null, 2)); - console.log("No out of band record found"); - return; - } - - if ( - !outOfBandRecord.outOfBandInvitation.goal || - !config?.agentOobGoals.includes(outOfBandRecord.outOfBandInvitation.goal) - ) { - console.log(JSON.stringify(ev.payload, null, 2)); - console.log("This connection does not have any goals"); - return; - } - - try { - console.log(`Sending proof request, to ${ev.payload.connectionRecord.id}`); - await agent.proofs.requestProof({ - protocolVersion: "v2", - connectionId: ev.payload.connectionRecord.id, - proofFormats: { - anoncreds: { - name: "proof-request", - version: "1.0", - requested_attributes: { - email: { - name: "email", - }, - }, - }, - }, - }); - } catch (e) { - console.log(JSON.stringify(e, null, 2)); - console.log("failed to offer credential"); - } -}; - export const isProofStateChangedEvent = ( e: BaseEvent, ): e is ProofStateChangedEvent => e.type === ProofEventTypes.ProofStateChanged; @@ -602,41 +475,6 @@ export const attachDidWebHandler = ( } }); }; -export const webHookHandler = async <T>( - addr: string, - webHookTopic: string, - payload: T, -) => { - const promises: Promise<AxiosResponse>[] = []; - - const tokenUrlPairs = addr.split(";"); - - for (const pair of tokenUrlPairs) { - const [token, url] = pair.split("@"); - - const promise = axios.post(`${url}/topic/${webHookTopic}`, payload, { - headers: { - "X-Api-Key": token, - }, - }); - - promises.push(promise); - } - - const promiseResults = await Promise.allSettled(promises); - for (let index = 0; index < promiseResults.length; index++) { - const promiseResult = promiseResults[index]; - const [_, url] = tokenUrlPairs[index].split("@"); - - if (promiseResult.status === "rejected") { - console.log( - `Failed to send web hook to ${url}/topic/${webHookTopic}. Reason ${promiseResult.reason}`, - ); - continue; - } - console.log(`Successfully sent web hook to ${url}/topic/${webHookTopic}`); - } -}; export const getFirstDidWebRecord = async ( agent: Agent, diff --git a/libs/askar/src/askar-nats/agent.consumer.service.ts b/libs/askar/src/askar-nats/agent.consumer.service.ts deleted file mode 100644 index 0cd2b40e..00000000 --- a/libs/askar/src/askar-nats/agent.consumer.service.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { - Injectable, - Logger, - OnModuleDestroy, - OnModuleInit, -} from "@nestjs/common"; -import { ConsumerService } from "@ocm-engine/nats"; -import { ConfigService } from "@nestjs/config"; -import { IConfAgent } from "@ocm-engine/config"; -import { GatewayClient } from "@ocm-engine/clients"; -import { EventHandlerService } from "./event.handler.service"; - -@Injectable() -export class AgentConsumerService implements OnModuleInit, OnModuleDestroy { - private readonly logger = new Logger(AgentConsumerService.name); - constructor( - private readonly consumerService: ConsumerService, - private readonly configService: ConfigService, - private readonly gatewayClient: GatewayClient, - private readonly eventHandlerService: EventHandlerService, - ) {} - - async onModuleInit(): Promise<void> { - const config = this.configService.get<IConfAgent>("agent"); - - if (config?.agentIsRest) { - this.logger.log( - "Agent is configured as rest, there is no need for consumer!", - ); - return; - } - - await this.consumerService.subscribe(async (event) => { - this.logger.debug(JSON.stringify(event, null, 2)); - let ev; - - try { - ev = await this.eventHandlerService.handle<typeof event.data>(event); - this.logger.debug(JSON.stringify(ev)); - } catch (e) { - this.logger.debug({ e: JSON.stringify(e, null, 2) }); - event.data = e; - ev = event; - } - - this.gatewayClient.sendPayload(ev); - - return; - }); - } - - async onModuleDestroy(): Promise<void> { - this.logger.log("disconnecting from broker"); - await this.consumerService.disconnect(); - } -} diff --git a/libs/askar/src/askar-nats/askar.nats.module.ts b/libs/askar/src/askar-nats/askar.nats.module.ts deleted file mode 100644 index 49b79138..00000000 --- a/libs/askar/src/askar-nats/askar.nats.module.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { Module, ValidationPipe } from "@nestjs/common"; -import { ConfigModule } from "@nestjs/config"; -import { LedgersModule } from "@ocm-engine/ledgers"; -import { APP_PIPE } from "@nestjs/core"; -import { AgentConsumerService } from "./agent.consumer.service"; -import { AgentAnoncredsService } from "../askar/services/agent.anoncreds.service"; -import { AgentBasicMessagesService } from "../askar/services/agent.basicMessages.service"; -import { AgentConnectionsService } from "../askar/services/agent.connections.service"; -import { AgentCredentialsService } from "../askar/services/agent.credentials.service"; -import { AgentDidsService } from "../askar/services/agent.dids.service"; -import { AgentJsonldService } from "../askar/services/agent.jsonld.service"; -import { AgentOobService } from "../askar/services/agent.oob.service"; -import { AgentProofsService } from "../askar/services/agent.proofs.service"; -import { ConsumerService } from "@ocm-engine/nats"; -import { GatewayClient } from "@ocm-engine/clients"; -import { EventHandlerService } from "./event.handler.service"; - -@Module({ - imports: [ConfigModule, LedgersModule], - providers: [ - ConsumerService, - AgentConsumerService, - AgentAnoncredsService, - AgentBasicMessagesService, - AgentConnectionsService, - AgentCredentialsService, - AgentDidsService, - AgentJsonldService, - AgentOobService, - AgentProofsService, - GatewayClient, - EventHandlerService, - { - provide: APP_PIPE, - useValue: new ValidationPipe({ - transform: true, - }), - }, - ], - controllers: [], -}) -export class AskarNatsModule {} diff --git a/libs/askar/src/askar-nats/event.handler.service.ts b/libs/askar/src/askar-nats/event.handler.service.ts deleted file mode 100644 index aaff61b7..00000000 --- a/libs/askar/src/askar-nats/event.handler.service.ts +++ /dev/null @@ -1,208 +0,0 @@ -import { Injectable, Logger } from "@nestjs/common"; -import { AgentAnoncredsService } from "../askar/services/agent.anoncreds.service"; -import { AgentBasicMessagesService } from "../askar/services/agent.basicMessages.service"; -import { AgentConnectionsService } from "../askar/services/agent.connections.service"; -import { AgentCredentialsService } from "../askar/services/agent.credentials.service"; -import { AgentDidsService } from "../askar/services/agent.dids.service"; -import { AgentJsonldService } from "../askar/services/agent.jsonld.service"; -import { AgentOobService } from "../askar/services/agent.oob.service"; -import { AgentProofsService } from "../askar/services/agent.proofs.service"; -import { - AcceptProofDto, - CloudEventDto, - CONNECTION_ACCEPT, - CONNECTION_CREATE, - CONNECTION_GET, - CONNECTION_LIST, - CONNECTION_DELETE, - CreateCredentialDefinitionRequestDto, - CreateInvitationResponseDto, - CreateSchemaRequestDto, - CredentialFilterDto, - CRED_DEF_CREATE, - CRED_DEF_LIST, - CRED_DEF_GET, - CRED_SEND_OFFER, - CRED_LIST, - CRED_GET, - CRED_OFFER_ACCEPT, - CRED_OFFER_DECLINE, - CRED_DELETE, - OfferCredentialRequestDto, - RequestProofDto, - ProofFilterDto, - PROOF_ACCEPT, - PROOF_DECLINE, - PROOF_REQUEST, - PROOF_LIST, - PROOF_GET, - PROOF_DELETE, - SCHEMA_CREATE, - SCHEMA_GET, - SCHEMA_LIST, - MakeBasicMessageRequestDto, - MessageFilterDto, - MESSAGE_MAKE, - MESSAGE_LIST, - MESSAGE_DELETE, - IdReqDto, - AcceptCredentialDto, - AcceptInvitationRequestDto, -} from "@ocm-engine/dtos"; - -@Injectable() -export class EventHandlerService { - private readonly logger = new Logger(EventHandlerService.name); - - constructor( - private readonly agentAnoncredsService: AgentAnoncredsService, - private readonly agentBasicMessagesService: AgentBasicMessagesService, - private readonly agentConnectionsService: AgentConnectionsService, - private readonly agentCredentialsService: AgentCredentialsService, - private readonly agentDidsService: AgentDidsService, - private readonly agentJsonldService: AgentJsonldService, - private readonly agentOobService: AgentOobService, - private readonly agentProofsService: AgentProofsService, - ) {} - - async handle<T>(event: CloudEventDto<T>) { - let data: unknown; - let dto; - switch (event.type) { - case CONNECTION_CREATE: - data = await this.agentOobService.createInvitation(); - break; - - case CONNECTION_ACCEPT: - dto = event.data as AcceptInvitationRequestDto; - data = await this.agentOobService.acceptInvitation(dto.invitationUrl); - break; - - case CONNECTION_LIST: - data = await this.agentConnectionsService.fetchConnections(); - break; - - case CONNECTION_GET: - dto = event.data as IdReqDto; - data = await this.agentConnectionsService.getConnectionById(dto.id); - break; - - case CONNECTION_DELETE: - dto = event.data as IdReqDto; - data = await this.agentConnectionsService.deleteConnectionById(dto.id); - break; - - case SCHEMA_CREATE: - dto = event.data as CreateSchemaRequestDto; - data = await this.agentAnoncredsService.createSchema(dto); - break; - - case SCHEMA_LIST: - data = await this.agentAnoncredsService.fetchSchemas(); - break; - - case SCHEMA_GET: - dto = event.data as IdReqDto; - data = await this.agentAnoncredsService.getSchemaById(dto.id); - break; - - case CRED_DEF_CREATE: - data = await this.agentAnoncredsService.createCredentialDefinition( - event.data as CreateCredentialDefinitionRequestDto, - ); - break; - - case CRED_DEF_LIST: - data = await this.agentAnoncredsService.fetchCredentialDefinitions(); - break; - - case CRED_DEF_GET: - dto = event.data as IdReqDto; - data = await this.agentAnoncredsService.getCredentialDefinitionById( - dto.id, - ); - break; - - case CRED_SEND_OFFER: - data = await this.agentCredentialsService.offerCredential( - event.data as OfferCredentialRequestDto, - ); - break; - - case CRED_LIST: - dto = event.data as CredentialFilterDto; - data = await this.agentCredentialsService.fetchCredentials(dto); - break; - - case CRED_GET: - dto = event.data as IdReqDto; - data = await this.agentCredentialsService.getCredentialById(dto.id); - break; - - case CRED_OFFER_ACCEPT: - data = await this.agentCredentialsService.acceptCredential( - event.data as AcceptCredentialDto, - ); - break; - - case CRED_OFFER_DECLINE: - dto = event.data as IdReqDto; - data = await this.agentCredentialsService.declineCredential(dto.id); - break; - - case CRED_DELETE: - dto = event.data as IdReqDto; - data = await this.agentCredentialsService.deleteCredentialById(dto.id); - break; - - case PROOF_REQUEST: - dto = event.data as RequestProofDto; - data = await this.agentProofsService.requestProof(dto); - break; - - case PROOF_LIST: - dto = event.data as ProofFilterDto; - data = await this.agentProofsService.fetchProofs(dto); - break; - - case PROOF_GET: - dto = event.data as IdReqDto; - data = await this.agentProofsService.getProofById(dto.id); - break; - - case PROOF_ACCEPT: - data = await this.agentProofsService.acceptProof( - event.data as AcceptProofDto, - ); - break; - - case PROOF_DECLINE: - dto = event.data as IdReqDto; - data = await this.agentProofsService.declineProofRequest(dto.id); - break; - - case PROOF_DELETE: - dto = event.data as IdReqDto; - data = await this.agentProofsService.deleteProofById(dto.id); - break; - - case MESSAGE_MAKE: - dto = event.data as MakeBasicMessageRequestDto; - data = await this.agentBasicMessagesService.sendMessage(dto); - break; - - case MESSAGE_LIST: - dto = event.data as MessageFilterDto; - data = await this.agentBasicMessagesService.fetchBasicMessages(dto); - break; - - case MESSAGE_DELETE: - dto = event.data as IdReqDto; - data = await this.agentBasicMessagesService.deleteMessageById(dto.id); - break; - } - - event.data = data as T; - return event; - } -} diff --git a/libs/askar/src/askar-rest/auth/auth.guard.ts b/libs/askar/src/askar-rest/auth/auth.guard.ts index 1279878a..4d39ee63 100644 --- a/libs/askar/src/askar-rest/auth/auth.guard.ts +++ b/libs/askar/src/askar-rest/auth/auth.guard.ts @@ -8,7 +8,7 @@ import { import { JwtService } from "@nestjs/jwt"; import { Request } from "express"; import { ConfigService } from "@nestjs/config"; -import { IConfAgent } from "@ocm-engine/config"; +import { IConfAuth } from "@ocm-engine/config"; @Injectable() export class AuthGuard implements CanActivate { @@ -20,9 +20,9 @@ export class AuthGuard implements CanActivate { ) {} async canActivate(context: ExecutionContext): Promise<boolean> { - const config: IConfAgent = this.configService.get<IConfAgent>("agent")!; + const config: IConfAuth = this.configService.get<IConfAuth>("auth")!; - if (!(config.agentAuthBasicEnabled || config.agentAuthJwtEnabled)) { + if (!(config.authBasicEnabled || config.authJwtEnabled)) { return true; } // Auth enabled @@ -35,11 +35,11 @@ export class AuthGuard implements CanActivate { switch (type) { case "Bearer": - if (!config.agentAuthJwtEnabled) throw new UnauthorizedException(); + if (!config.authJwtEnabled) throw new UnauthorizedException(); await this.verifyBearerToken(token, config); break; case "Basic": - if (!config.agentAuthBasicEnabled) throw new UnauthorizedException(); + if (!config.authBasicEnabled) throw new UnauthorizedException(); await this.verifyBasicToken(token, config); break; default: @@ -49,10 +49,10 @@ export class AuthGuard implements CanActivate { return true; } - private async verifyBearerToken(token: string, config: IConfAgent) { + private async verifyBearerToken(token: string, config: IConfAuth) { try { await this.jwtService.verifyAsync(token, { - publicKey: config.agentAuthJwtPublicKey, + publicKey: config.authJwtPublicKey, }); } catch (e) { this.logger.log("Token verification Error"); @@ -61,14 +61,14 @@ export class AuthGuard implements CanActivate { } } - private async verifyBasicToken(token: string, config: IConfAgent) { + private async verifyBasicToken(token: string, config: IConfAuth) { const [username, password] = Buffer.from(token, "base64") .toString() .split(":"); if ( - username !== config.agentAuthBasicUser || - password !== config.agentAuthBasicPass + username !== config.authBasicUser || + password !== config.authBasicPass ) { throw new UnauthorizedException(); } diff --git a/libs/askar/src/askar.dynamic.module.ts b/libs/askar/src/askar.dynamic.module.ts index 1bb4e507..6aaab583 100644 --- a/libs/askar/src/askar.dynamic.module.ts +++ b/libs/askar/src/askar.dynamic.module.ts @@ -1,21 +1,16 @@ import { DynamicModule, Module } from "@nestjs/common"; import { ConfigModule } from "@nestjs/config"; import { AskarRestModule } from "./askar-rest/askar.rest.module"; -import { AskarNatsModule } from "./askar-nats/askar.nats.module"; import { AskarModule } from "./askar/askar.module"; -import * as process from "process"; @Module({}) export class AskarDynamicModule { static forRootAsync(): DynamicModule { - const isRest = process.env["AGENT_IS_REST"] === "true"; - - const module = isRest ? AskarRestModule : AskarNatsModule; - return { module: AskarDynamicModule, - imports: [ConfigModule, AskarModule, module], - providers: [module], + imports: [ConfigModule, AskarModule, AskarRestModule], + providers: [AskarRestModule], + exports: [AskarModule], }; } } diff --git a/libs/askar/src/askar/askar.module.ts b/libs/askar/src/askar/askar.module.ts index 44dc10a3..9631ba3b 100644 --- a/libs/askar/src/askar/askar.module.ts +++ b/libs/askar/src/askar/askar.module.ts @@ -10,8 +10,6 @@ import { AgentOobService } from "./services/agent.oob.service"; import { AgentProofsService } from "./services/agent.proofs.service"; import { ConfigModule } from "@nestjs/config"; import { LedgersModule } from "@ocm-engine/ledgers"; -import { AgentEventListenerService } from "./services/agent-event-listener.service"; -import { GatewayClient } from "@ocm-engine/clients"; @Global() @Module({ @@ -26,8 +24,6 @@ import { GatewayClient } from "@ocm-engine/clients"; AgentOobService, AgentProofsService, AskarService, - AgentEventListenerService, - GatewayClient, ], exports: [ AgentAnoncredsService, diff --git a/libs/askar/src/askar/services/agent-event-listener.service.ts b/libs/askar/src/askar/services/agent-event-listener.service.ts deleted file mode 100644 index cc596095..00000000 --- a/libs/askar/src/askar/services/agent-event-listener.service.ts +++ /dev/null @@ -1,128 +0,0 @@ -import { Injectable, Logger, OnModuleInit } from "@nestjs/common"; -import { GatewayClient } from "@ocm-engine/clients"; -import { AskarService } from "./askar.service"; -import { - BasicMessageEventTypes, - TrustPingEventTypes, - BasicMessageRole, - BasicMessageStateChangedEvent, - ConnectionEventTypes, - ConnectionStateChangedEvent, - ProofEventTypes, - ProofStateChangedEvent, - TrustPingResponseReceivedEvent, -} from "@credo-ts/core"; -import { MessageRecordDto, makeEvent, MESSAGE_MAKE } from "@ocm-engine/dtos"; -import { IConfAgent } from "@ocm-engine/config"; -import { ConfigService } from "@nestjs/config"; -import { - svdxConnectionStateChangeHandler, - svdxProofStateChangeHandler, - webHookHandler, -} from "../../agent.utils"; - -@Injectable() -export class AgentEventListenerService implements OnModuleInit { - private agentConfig: IConfAgent | undefined; - private readonly logger: Logger = new Logger(AgentEventListenerService.name); - - constructor( - private readonly gatewayClient: GatewayClient, - private readonly askar: AskarService, - private readonly configService: ConfigService, - ) {} - - onModuleInit(): void { - this.logger.debug("Agent is listening for AFJ events"); - this.agentConfig = this.configService.get<IConfAgent>("agent"); - - if (this.agentConfig?.agentIsSVDX && this.agentConfig?.agentIsRest) { - this.askar.agent.events.on( - ConnectionEventTypes.ConnectionStateChanged, - async (ev: ConnectionStateChangedEvent) => { - this.logger.log("connection state event received"); - this.logger.debug(JSON.stringify(ev, null, 2)); - return svdxConnectionStateChangeHandler( - ev, - this.askar.agent, - this.agentConfig, - ); - }, - ); - - this.askar.agent.events.on( - ProofEventTypes.ProofStateChanged, - async (ev: ProofStateChangedEvent) => { - this.logger.log("proof state event received"); - this.logger.debug(JSON.stringify(ev, null, 2)); - - return svdxProofStateChangeHandler( - ev, - this.askar.agent, - this.agentConfig, - ); - }, - ); - } - - if (this.agentConfig?.agentIsRest) { - this.askar.agent.events.on( - TrustPingEventTypes.TrustPingResponseReceivedEvent, - async (ev: TrustPingResponseReceivedEvent) => { - if (!this.agentConfig?.agentWebHook) { - throw new Error("Agent config is missing agentWebHook"); - } - - return webHookHandler(this.agentConfig?.agentWebHook, "ping", { - thid: ev.payload.message.threadId, - connectionId: ev.payload.connectionRecord.id, - }); - }, - ); - } - - this.askar.agent.events.on( - BasicMessageEventTypes.BasicMessageStateChanged, - async (ev: BasicMessageStateChangedEvent) => { - if (ev.payload.basicMessageRecord.role === BasicMessageRole.Receiver) { - this.logger.debug(JSON.stringify(ev, null, 2)); - - const messageRecord = ev.payload.basicMessageRecord; - - const connectionInfo = await this.askar.agent.connections.findById( - messageRecord.connectionId, - ); - const label = connectionInfo?.theirLabel || ""; - const dto = MessageRecordDto.fromJson({ - id: messageRecord.id, - createdAt: messageRecord.createdAt, - updatedAt: messageRecord.updatedAt, - connectionId: messageRecord.connectionId, - role: messageRecord.role, - content: messageRecord.content, - sentTime: messageRecord.sentTime, - from: messageRecord.role === BasicMessageRole.Receiver ? label : "", - to: messageRecord.role === BasicMessageRole.Sender ? label : "", - }); - - if (this.agentConfig?.agentIsRest) { - this.logger.debug( - "agent is configured as rest, webhook still not implemented", - ); - - return; - } - - const event = makeEvent({ - data: dto, - type: MESSAGE_MAKE, - source: "agent-basic-message-afj", - }); - - this.logger.debug("Sending message event to gateway"); - this.gatewayClient.sendPayload(event); - } - }, - ); - } -} diff --git a/libs/clients/src/backend.ts b/libs/clients/src/backend.ts deleted file mode 100644 index 59ca4687..00000000 --- a/libs/clients/src/backend.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from "./backend/gateway.client"; -export * from "./backend/connection.manager.client"; -export * from "./backend/attestation.manager.client"; -export * from "./backend/proof.manager.client"; diff --git a/libs/clients/src/backend/attestation.manager.client.ts b/libs/clients/src/backend/attestation.manager.client.ts deleted file mode 100644 index 0c063211..00000000 --- a/libs/clients/src/backend/attestation.manager.client.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { - Injectable, - InternalServerErrorException, - Logger, -} from "@nestjs/common"; -import { - ClientProxy, - ClientProxyFactory, - Transport, -} from "@nestjs/microservices"; -import { ConfigService } from "@nestjs/config"; -import { IAttestationManagerConfig } from "@ocm-engine/config"; -import { - GatewayAcceptedResponseDto, - CredentialEvent, - SchemaEvent, - BasicMessageEvent, -} from "@ocm-engine/dtos"; -import { lastValueFrom } from "rxjs"; - -@Injectable() -export class AttestationManagerClient { - private client: ClientProxy; - private amConfig: IAttestationManagerConfig; - private readonly logger: Logger = new Logger(AttestationManagerClient.name); - - constructor(configService: ConfigService) { - this.amConfig = configService.get<IAttestationManagerConfig>("am")!; - - this.client = ClientProxyFactory.create({ - transport: Transport.TCP, - options: { - host: this.amConfig.host, - port: this.amConfig.port, - }, - }); - } - - async sendPayload<T>({ - pattern, - payload, - }: { - pattern: string; - payload: { - data: T; - type: SchemaEvent | CredentialEvent | BasicMessageEvent; - source: string; - }; - }): Promise<GatewayAcceptedResponseDto> { - this.logger.debug( - `sending payload to attestation manager ${JSON.stringify( - payload, - null, - 2, - )}`, - ); - - return lastValueFrom(this.client.send(pattern, payload)).catch((e) => { - throw new InternalServerErrorException(e.message); - }); - } -} diff --git a/libs/clients/src/backend/connection.manager.client.ts b/libs/clients/src/backend/connection.manager.client.ts deleted file mode 100644 index 50d2cd1a..00000000 --- a/libs/clients/src/backend/connection.manager.client.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { - Injectable, - InternalServerErrorException, - Logger, -} from "@nestjs/common"; -import { - ClientProxy, - ClientProxyFactory, - Transport, -} from "@nestjs/microservices"; -import { ConfigService } from "@nestjs/config"; -import { IConnectionManagerConfig } from "@ocm-engine/config"; -import { GatewayAcceptedResponseDto, ConnectionEvent } from "@ocm-engine/dtos"; -import { lastValueFrom } from "rxjs"; - -@Injectable() -export class ConnectionManagerClient { - private client: ClientProxy; - private cmConfig: IConnectionManagerConfig; - private readonly logger: Logger = new Logger(ConnectionManagerClient.name); - - constructor(configService: ConfigService) { - this.cmConfig = configService.get<IConnectionManagerConfig>("cm")!; - - this.client = ClientProxyFactory.create({ - transport: Transport.TCP, - options: { - host: this.cmConfig.host, - port: this.cmConfig.port, - }, - }); - } - - async sendPayload<T>({ - pattern, - payload, - }: { - pattern: string; - payload: { - data: T; - type: ConnectionEvent; - source: string; - }; - }): Promise<GatewayAcceptedResponseDto> { - this.logger.debug( - `sending payload to connection manager ${JSON.stringify( - payload, - null, - 2, - )}`, - ); - - return lastValueFrom(this.client.send(pattern, payload)).catch((e) => { - throw new InternalServerErrorException(e.message); - }); - } -} diff --git a/libs/clients/src/backend/gateway.client.ts b/libs/clients/src/backend/gateway.client.ts deleted file mode 100644 index c7e9564d..00000000 --- a/libs/clients/src/backend/gateway.client.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { Injectable, Logger } from "@nestjs/common"; -import { - ClientProxy, - ClientProxyFactory, - Transport, -} from "@nestjs/microservices"; -import { ConfigService } from "@nestjs/config"; -import { CloudEventDto } from "@ocm-engine/dtos"; -import { IGateway } from "@ocm-engine/config"; - -@Injectable() -export class GatewayClient { - private client: ClientProxy; - private gatewayConf: IGateway; - private readonly logger: Logger = new Logger(GatewayClient.name); - - constructor(configService: ConfigService) { - this.gatewayConf = configService.get<IGateway>("gateway")!; - - this.client = ClientProxyFactory.create({ - transport: Transport.TCP, - options: { - host: this.gatewayConf.host, - port: this.gatewayConf.tcpPort, - }, - }); - } - - sendPayload<T>(payload: CloudEventDto<T>) { - this.logger.debug( - `sending payload to gateway ${JSON.stringify(payload, null, 2)}`, - ); - - return this.client.emit(this.gatewayConf.messagePattern, payload); - } -} diff --git a/libs/clients/src/backend/proof.manager.client.ts b/libs/clients/src/backend/proof.manager.client.ts deleted file mode 100644 index aa66d56b..00000000 --- a/libs/clients/src/backend/proof.manager.client.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { - Injectable, - InternalServerErrorException, - Logger, -} from "@nestjs/common"; -import { - ClientProxy, - ClientProxyFactory, - Transport, -} from "@nestjs/microservices"; -import { ConfigService } from "@nestjs/config"; -import { IProofManagerConfig } from "@ocm-engine/config"; -import { GatewayAcceptedResponseDto, ProofEvent } from "@ocm-engine/dtos"; -import { lastValueFrom } from "rxjs"; - -@Injectable() -export class ProofManagerClient { - private client: ClientProxy; - private pmConfig: IProofManagerConfig; - private readonly logger: Logger = new Logger(ProofManagerClient.name); - - constructor(configService: ConfigService) { - this.pmConfig = configService.get<IProofManagerConfig>("pm")!; - - this.client = ClientProxyFactory.create({ - transport: Transport.TCP, - options: { - host: this.pmConfig.host, - port: this.pmConfig.port, - }, - }); - } - - async sendPayload<T>({ - pattern, - payload, - }: { - pattern: string; - payload: { - data: T; - type: ProofEvent; - source: string; - }; - }): Promise<GatewayAcceptedResponseDto> { - this.logger.debug( - `sending payload to proof manager ${JSON.stringify(payload, null, 2)}`, - ); - - return lastValueFrom(this.client.send(pattern, payload)).catch((e) => { - throw new InternalServerErrorException(e.message); - }); - } -} diff --git a/libs/config/src/config/agent.config.ts b/libs/config/src/config/agent.config.ts index 57bbe5fc..0a36e19b 100644 --- a/libs/config/src/config/agent.config.ts +++ b/libs/config/src/config/agent.config.ts @@ -14,29 +14,9 @@ export const agentConfig = registerAs( agentDbHost: process.env["AGENT_DB_HOST"]!, agentDbUser: process.env["AGENT_DB_USER"]!, agentDbPass: process.env["AGENT_DB_PASS"]!, - agentIsRest: process.env["AGENT_IS_REST"] === "true", - agentConsumerName: process.env["AGENT_CONSUMER_NAME"]!, - agentConsumerMaxMessages: - parseInt(process.env["AGENT_MAX_MESSAGES"]!) || 10, - agentConsumerRateLimit: parseInt(process.env["AGENT_RETE_LIMIT"]!) || 5, agentPort: parseInt(process.env["AGENT_PORT"]!), - agentOobGoals: - typeof process.env["AGENT_OOB_GOALS"] !== "undefined" - ? process.env["AGENT_OOB_GOALS"]!.split(",") - : [], - agentIsSVDX: process.env["AGENT_IS_SVDX"] === "true", - agentSVDXWebHook: process.env["AGENT_SVDX_WEBHOOK_URL"]!, - agentSVDXBasicUser: process.env["AGENT_SVDX_BASIC_USER"]!, - agentSVDXBasicPass: process.env["AGENT_SVDX_BASIC_PASS"]!, + agentOobUrl: process.env["AGENT_OOB_URL"] || undefined, - agentAuthBasicEnabled: - !!process.env["AUTH_BASIC_USER"] && !!process.env["AUTH_BASIC_PASS"], - agentAuthBasicUser: process.env["AUTH_BASIC_USER"]!, - agentAuthBasicPass: process.env["AUTH_BASIC_PASS"]!, - agentAuthJwtEnabled: !!process.env["AUTH_JWT_PUBLIC_KEY"], - agentAuthJwtPublicKey: process.env["AUTH_JWT_PUBLIC_KEY"]!, logLevel: parseInt(process.env["LOG_LEVEL"]!) ?? LogLevel.error, - agentWebHook: process.env["AGENT_WEBHOOK_URL"]!, - agentOobUrl: process.env["AGENT_OOB_URL"] || undefined, }), ); diff --git a/libs/config/src/config/attestation.manager.ts b/libs/config/src/config/attestation.manager.ts deleted file mode 100644 index d7e28623..00000000 --- a/libs/config/src/config/attestation.manager.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { registerAs } from "@nestjs/config"; -import * as process from "process"; -import { IAttestationManagerConfig } from "../interfaces/attestation.manager.config.interface"; - -export const amConfig = registerAs( - "am", - (): IAttestationManagerConfig => ({ - host: process.env["ATTESTATION_SERVICE_HOST"]!, - port: parseInt(process.env["ATTESTATION_SERVICE_TCP_PORT"]!), - }), -); diff --git a/libs/config/src/config/auth.config.ts b/libs/config/src/config/auth.config.ts new file mode 100644 index 00000000..40475205 --- /dev/null +++ b/libs/config/src/config/auth.config.ts @@ -0,0 +1,15 @@ +import { registerAs } from "@nestjs/config"; +import * as process from "process"; +import { IConfAuth } from "../interfaces/auth.config.interface"; + +export const authConfig = registerAs( + "auth", + (): IConfAuth => ({ + authBasicEnabled: + !!process.env["AUTH_BASIC_USER"] && !!process.env["AUTH_BASIC_PASS"], + authBasicUser: process.env["AUTH_BASIC_USER"]!, + authBasicPass: process.env["AUTH_BASIC_PASS"]!, + authJwtEnabled: !!process.env["AUTH_JWT_PUBLIC_KEY"], + authJwtPublicKey: process.env["AUTH_JWT_PUBLIC_KEY"]!, + }), +); diff --git a/libs/config/src/config/connection.manager.config.ts b/libs/config/src/config/connection.manager.config.ts deleted file mode 100644 index 1ae947bd..00000000 --- a/libs/config/src/config/connection.manager.config.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { registerAs } from "@nestjs/config"; -import * as process from "process"; -import { IConnectionManagerConfig } from "../interfaces/connection.manager.config.interface"; - -export const cmConfig = registerAs( - "cm", - (): IConnectionManagerConfig => ({ - host: process.env["CONNECTION_SERVICE_HOST"]!, - port: parseInt(process.env["CONNECTION_SERVICE_TCP_PORT"]!), - }), -); diff --git a/libs/config/src/config/gateway.config.ts b/libs/config/src/config/gateway.config.ts deleted file mode 100644 index 73bc0dc5..00000000 --- a/libs/config/src/config/gateway.config.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { registerAs } from "@nestjs/config"; -import process from "process"; -import { IGateway } from "../interfaces/gateway.config.interface"; - -export const gatewayConfig = registerAs( - "gateway", - (): IGateway => ({ - httpPort: parseInt(process.env["GATEWAY_HTTP_PORT"]!), - tcpPort: parseInt(process.env["GATEWAY_TCP_PORT"]!), - messagePattern: process.env["GATEWAY_MESSAGE_PATTERN"]!, - host: process.env["GATEWAY_HOST"], - }), -); diff --git a/libs/config/src/config/nats.config.ts b/libs/config/src/config/nats.config.ts deleted file mode 100644 index 852221e2..00000000 --- a/libs/config/src/config/nats.config.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { registerAs } from "@nestjs/config"; -import * as process from "process"; -import { IConfNats } from "../interfaces/nats.config.interface"; - -export const natsConfig = registerAs( - "nats", - (): IConfNats => ({ - servers: - (process.env["NATS_SERVERS"] && - process.env["NATS_SERVERS"]!.split(",")) || - [], - streamName: process.env["NATS_STREAM_NAME"]! || "default-stream", - subjects: - (process.env["NATS_SUBJECTS"] && - process.env["NATS_SUBJECTS"]!.split(",")) || - [], - }), -); diff --git a/libs/config/src/config/proof.manager.ts b/libs/config/src/config/proof.manager.ts deleted file mode 100644 index 71b21783..00000000 --- a/libs/config/src/config/proof.manager.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { registerAs } from "@nestjs/config"; -import * as process from "process"; -import { IAttestationManagerConfig } from "../interfaces/attestation.manager.config.interface"; - -export const pmConfig = registerAs( - "pm", - (): IAttestationManagerConfig => ({ - host: process.env["PROOF_SERVICE_HOST"]!, - port: parseInt(process.env["PROOF_SERVICE_TCP_PORT"]!), - }), -); diff --git a/libs/config/src/index.ts b/libs/config/src/index.ts index 630047fd..4d1eb9c8 100644 --- a/libs/config/src/index.ts +++ b/libs/config/src/index.ts @@ -1,24 +1,11 @@ -export * from "./config/nats.config"; export * from "./config/agent.config"; +export * from "./config/auth.config"; export * from "./config/ledgers.config"; -export * from "./config/gateway.config"; -export * from "./config/connection.manager.config"; -export * from "./config/attestation.manager"; -export * from "./config/proof.manager"; -export * from "./interfaces/nats.config.interface"; export * from "./interfaces/agent.config.interface"; +export * from "./interfaces/auth.config.interface"; export * from "./interfaces/ledgers.config.interface"; -export * from "./interfaces/gateway.config.interface"; -export * from "./interfaces/connection.manager.config.interface"; -export * from "./interfaces/attestation.manager.config.interface"; -export * from "./interfaces/proof.manager.config.interface"; -export * from "./schemas/nats.schema"; export * from "./schemas/agent.schema"; export * from "./schemas/auth.schema"; export * from "./schemas/ledgers.schema"; -export * from "./schemas/gateway.schema"; -export * from "./schemas/connection.manager.schema"; -export * from "./schemas/attestation.manager.schema"; -export * from "./schemas/proof.manager.schema"; diff --git a/libs/config/src/interfaces/agent.config.interface.ts b/libs/config/src/interfaces/agent.config.interface.ts index eeabad51..1d180f2a 100644 --- a/libs/config/src/interfaces/agent.config.interface.ts +++ b/libs/config/src/interfaces/agent.config.interface.ts @@ -7,25 +7,9 @@ export interface IConfAgent { agentName: string; agentKey: string; agentDidSeed: string; - agentIsRest: boolean; - agentConsumerName: string; - agentConsumerMaxMessages: number; - agentConsumerRateLimit: number; - agentPort: number; - agentOobGoals: Array<string>; - - agentIsSVDX: boolean; - agentSVDXWebHook: string; - agentSVDXBasicUser: string; - agentSVDXBasicPass: string; - agentAuthBasicEnabled: boolean; - agentAuthBasicUser: string; - agentAuthBasicPass: string; - agentAuthJwtEnabled: boolean; - agentAuthJwtPublicKey: string; + agentPort: number; logLevel: number; - agentWebHook: string; agentOobUrl: string | undefined; } diff --git a/libs/config/src/interfaces/attestation.manager.config.interface.ts b/libs/config/src/interfaces/attestation.manager.config.interface.ts deleted file mode 100644 index 1ad4a74b..00000000 --- a/libs/config/src/interfaces/attestation.manager.config.interface.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface IAttestationManagerConfig { - host: string; - port: number; -} diff --git a/libs/config/src/interfaces/auth.config.interface.ts b/libs/config/src/interfaces/auth.config.interface.ts new file mode 100644 index 00000000..43e965ac --- /dev/null +++ b/libs/config/src/interfaces/auth.config.interface.ts @@ -0,0 +1,7 @@ +export interface IConfAuth { + authBasicEnabled: boolean; + authBasicUser: string; + authBasicPass: string; + authJwtEnabled: boolean; + authJwtPublicKey: string; +} diff --git a/libs/config/src/interfaces/connection.manager.config.interface.ts b/libs/config/src/interfaces/connection.manager.config.interface.ts deleted file mode 100644 index 51b1dfa8..00000000 --- a/libs/config/src/interfaces/connection.manager.config.interface.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface IConnectionManagerConfig { - host: string; - port: number; -} diff --git a/libs/config/src/interfaces/gateway.config.interface.ts b/libs/config/src/interfaces/gateway.config.interface.ts deleted file mode 100644 index fc944722..00000000 --- a/libs/config/src/interfaces/gateway.config.interface.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface IGateway { - httpPort: number; - tcpPort: number; - messagePattern: string; - host?: string; -} diff --git a/libs/config/src/interfaces/nats.config.interface.ts b/libs/config/src/interfaces/nats.config.interface.ts deleted file mode 100644 index f2de6759..00000000 --- a/libs/config/src/interfaces/nats.config.interface.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface IConfNats { - servers: Array<string>; - streamName: string; - subjects: Array<string>; -} diff --git a/libs/config/src/interfaces/proof.manager.config.interface.ts b/libs/config/src/interfaces/proof.manager.config.interface.ts deleted file mode 100644 index 81f9d92b..00000000 --- a/libs/config/src/interfaces/proof.manager.config.interface.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface IProofManagerConfig { - host: string; - port: number; -} diff --git a/libs/config/src/schemas/agent.schema.ts b/libs/config/src/schemas/agent.schema.ts index 364b4e3b..e25d7c77 100644 --- a/libs/config/src/schemas/agent.schema.ts +++ b/libs/config/src/schemas/agent.schema.ts @@ -2,17 +2,15 @@ import Joi from "joi"; export const agentSchema = Joi.object({ AGENT_PEER_URL: Joi.string().required(), + AGENT_PEER_PORT: Joi.string().optional(), AGENT_NAME: Joi.string().required(), AGENT_KEY: Joi.string().required(), AGENT_DID_SEED: Joi.string().required(), AGENT_DB_HOST: Joi.string().required(), AGENT_DB_USER: Joi.string().required(), AGENT_DB_PASS: Joi.string().required(), - AGENT_CONSUMER_NAME: Joi.string(), - AGENT_IS_REST: Joi.string().optional(), - AGENT_MAX_MESSAGES: Joi.string().required(), - AGENT_RETE_LIMIT: Joi.string().required(), + AGENT_PORT: Joi.string().required(), - AGENT_IS_SVDX: Joi.string().optional(), - AGENT_SVDX_WEBHOOK_URL: Joi.string().optional(), + + LOG_LEVEL: Joi.string().optional(), }); diff --git a/libs/config/src/schemas/attestation.manager.schema.ts b/libs/config/src/schemas/attestation.manager.schema.ts deleted file mode 100644 index da7bbf86..00000000 --- a/libs/config/src/schemas/attestation.manager.schema.ts +++ /dev/null @@ -1,6 +0,0 @@ -import Joi from "joi"; - -export const amSchema = Joi.object({ - ATTESTATION_SERVICE_TCP_PORT: Joi.string().required(), - ATTESTATION_SERVICE_HOST: Joi.string().required(), -}); diff --git a/libs/config/src/schemas/auth.schema.ts b/libs/config/src/schemas/auth.schema.ts index b8616bb4..ea356461 100644 --- a/libs/config/src/schemas/auth.schema.ts +++ b/libs/config/src/schemas/auth.schema.ts @@ -1,7 +1,7 @@ import Joi from "joi"; export const authSchema = Joi.object({ - AUTH_BASIC_USER: Joi.string(), - AUTH_BASIC_PASS: Joi.string(), - AUTH_JWT_PUBLIC_KEY: Joi.string(), + AUTH_BASIC_USER: Joi.string().optional(), + AUTH_BASIC_PASS: Joi.string().optional(), + AUTH_JWT_PUBLIC_KEY: Joi.string().optional(), }); diff --git a/libs/config/src/schemas/connection.manager.schema.ts b/libs/config/src/schemas/connection.manager.schema.ts deleted file mode 100644 index 7eef0df3..00000000 --- a/libs/config/src/schemas/connection.manager.schema.ts +++ /dev/null @@ -1,6 +0,0 @@ -import Joi from "joi"; - -export const cmSchema = Joi.object({ - CONNECTION_SERVICE_TCP_PORT: Joi.string().required(), - CONNECTION_SERVICE_HOST: Joi.string().required(), -}); diff --git a/libs/config/src/schemas/gateway.schema.ts b/libs/config/src/schemas/gateway.schema.ts deleted file mode 100644 index 55bc1c06..00000000 --- a/libs/config/src/schemas/gateway.schema.ts +++ /dev/null @@ -1,8 +0,0 @@ -import Joi from "joi"; - -export const gatewaySchema = Joi.object({ - GATEWAY_HTTP_PORT: Joi.string().required(), - GATEWAY_TCP_PORT: Joi.string().required(), - GATEWAY_MESSAGE_PATTERN: Joi.string().required(), - GATEWAY_HOST: Joi.string().required(), -}); diff --git a/libs/config/src/schemas/nats.schema.ts b/libs/config/src/schemas/nats.schema.ts deleted file mode 100644 index fa750741..00000000 --- a/libs/config/src/schemas/nats.schema.ts +++ /dev/null @@ -1,7 +0,0 @@ -import Joi from "joi"; - -export const natsSchema = Joi.object({ - NATS_SERVERS: Joi.string(), - NATS_STREAM_NAME: Joi.string(), - NATS_SUBJECTS: Joi.string(), -}); diff --git a/libs/config/src/schemas/proof.manager.schema.ts b/libs/config/src/schemas/proof.manager.schema.ts deleted file mode 100644 index 9ba61642..00000000 --- a/libs/config/src/schemas/proof.manager.schema.ts +++ /dev/null @@ -1,6 +0,0 @@ -import Joi from "joi"; - -export const pmSchema = Joi.object({ - PROOF_SERVICE_TCP_PORT: Joi.string().required(), - PROOF_SERVICE_HOST: Joi.string().required(), -}); diff --git a/libs/dtos/src/events/dtoToEventTransformer.ts b/libs/dtos/src/events/dtoToEventTransformer.ts deleted file mode 100644 index 4f6fc1ae..00000000 --- a/libs/dtos/src/events/dtoToEventTransformer.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { - ALL_EVENTS, - BasicMessageEvent, - ConnectionEvent, - CredentialEvent, - ProofEvent, - SchemaEvent, -} from "./types"; -import { CloudEventDto } from "./event"; -import { ConnectionUnsupportedTypeError } from "../errors/connection.unsupported.type.error"; -import { CreateCredentialDefinitionRequestDto } from "../dtos/requests/create.credential.definition.request.dto"; -import { CreateInvitationResponseDto } from "../dtos/responses/create.invitation.response.dto"; -import { CreateSchemaRequestDto } from "../dtos/requests/create.schema.request.dto"; -import { OfferCredentialRequestDto } from "../dtos/requests/offer.credential.request.dto"; -import { RequestProofDto } from "../dtos/requests/request.proof.dto"; -import { MessageRecordDto } from "../dtos/generics/message.record.dto"; -import { MakeBasicMessageRequestDto } from "../dtos/requests/make.basic.message.request.dto"; -import { AcceptProofDto } from "../dtos/requests/accept.proof.dto"; -import { ProofRecordDto } from "../dtos/generics/proof.record.dto"; -import { IdReqDto } from "../dtos/requests/id.req.dto"; - -export const makeEvent = (payload: { - data: - | null - | RequestProofDto - | CreateInvitationResponseDto - | CreateSchemaRequestDto - | AcceptProofDto - | IdReqDto - | CreateCredentialDefinitionRequestDto - | ProofRecordDto - | OfferCredentialRequestDto - | MessageRecordDto - | MakeBasicMessageRequestDto; - type: - | SchemaEvent - | CredentialEvent - | ProofEvent - | ConnectionEvent - | BasicMessageEvent; - source: string; -}) => { - if (!ALL_EVENTS.includes(payload.type)) { - throw new ConnectionUnsupportedTypeError(); - } - - const event = new CloudEventDto<typeof payload.data>(); - event.subject = payload.type; - event.source = payload.source; - event.type = payload.type; - event.data = payload.data; - - return event; -}; diff --git a/libs/dtos/src/events/event.ts b/libs/dtos/src/events/event.ts deleted file mode 100644 index 89f1032c..00000000 --- a/libs/dtos/src/events/event.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { - IsString, - IsNotEmpty, - IsOptional, - ValidateNested, - IsUUID, -} from "class-validator"; -import { CloudEventV1 } from "cloudevents"; -import { uuid } from "@credo-ts/core/build/utils/uuid"; - -export class CloudEventDto<T> implements CloudEventV1<T> { - @IsNotEmpty() - @IsUUID() - id: string = uuid(); - - @IsString() - @IsNotEmpty() - specversion = "V1"; - - @IsString() - @IsNotEmpty() - source: string; - - @IsString() - @IsNotEmpty() - type: string; - - @IsString() - @IsOptional() - dataschema?: string; - - @IsString() - @IsOptional() - datacontenttype?: string = "application/json"; - - @IsOptional() - @ValidateNested() - data?: T; - - @IsString() - @IsOptional() - subject?: string; - - @IsString() - @IsOptional() - time?: string; - - [key: string]: unknown; -} diff --git a/libs/dtos/src/events/types.ts b/libs/dtos/src/events/types.ts deleted file mode 100644 index b766032b..00000000 --- a/libs/dtos/src/events/types.ts +++ /dev/null @@ -1,115 +0,0 @@ -export const CONNECTION_CREATE = "connections.create"; -export const CONNECTION_ACCEPT = "connections.accept"; -export const CONNECTION_LIST = "connections.list"; -export const CONNECTION_GET = "connections.get"; -export const CONNECTION_DELETE = "connections.delete"; - -export type ConnectionEvent = - | typeof CONNECTION_CREATE - | typeof CONNECTION_ACCEPT - | typeof CONNECTION_LIST - | typeof CONNECTION_GET - | typeof CONNECTION_DELETE; - -export const CONNECTION_EVENTS: ConnectionEvent[] = [ - CONNECTION_CREATE, - CONNECTION_ACCEPT, - CONNECTION_LIST, - CONNECTION_GET, - CONNECTION_DELETE, -]; - -export const SCHEMA_CREATE = "schemas.create"; -export const SCHEMA_GET = "schemas.get"; -export const SCHEMA_LIST = "schemas.list"; - -export type SchemaEvent = - | typeof SCHEMA_CREATE - | typeof SCHEMA_GET - | typeof SCHEMA_LIST; - -export const SCHEMA_EVENTS: SchemaEvent[] = [ - SCHEMA_CREATE, - SCHEMA_LIST, - SCHEMA_GET, -]; - -export const CRED_DEF_CREATE = "credentials.definition.create"; -export const CRED_DEF_LIST = "credentials.definition.list"; -export const CRED_DEF_GET = "credentials.definition.get"; -export const CRED_SEND_OFFER = "credentials.send-offer"; -export const CRED_LIST = "credentials.list"; -export const CRED_OFFER_ACCEPT = "credentials.offer.accept"; -export const CRED_OFFER_DECLINE = "credentials.offer.decline"; -export const CRED_DELETE = "credentials.delete"; -export const CRED_GET = "credentials.get"; - -export type CredentialEvent = - | typeof CRED_DEF_CREATE - | typeof CRED_DEF_LIST - | typeof CRED_DEF_GET - | typeof CRED_SEND_OFFER - | typeof CRED_LIST - | typeof CRED_OFFER_ACCEPT - | typeof CRED_OFFER_DECLINE - | typeof CRED_DELETE - | typeof CRED_GET; - -export const CRED_EVENTS: CredentialEvent[] = [ - CRED_DEF_CREATE, - CRED_DEF_LIST, - CRED_DEF_GET, - CRED_SEND_OFFER, - CRED_LIST, - CRED_OFFER_ACCEPT, - CRED_OFFER_DECLINE, - CRED_DELETE, - CRED_GET, -]; - -export const PROOF_LIST = "proofs.list"; -export const PROOF_DELETE = "proofs.delete"; -export const PROOF_GET = "proofs.get"; -export const PROOF_ACCEPT = "proofs.accept"; -export const PROOF_REQUEST = "proofs.request"; -export const PROOF_DECLINE = "proofs.decline"; - -export type ProofEvent = - | typeof PROOF_LIST - | typeof PROOF_DELETE - | typeof PROOF_GET - | typeof PROOF_ACCEPT - | typeof PROOF_REQUEST - | typeof PROOF_DECLINE; - -export const PROOF_EVENTS: ProofEvent[] = [ - PROOF_LIST, - PROOF_DELETE, - PROOF_GET, - PROOF_ACCEPT, - PROOF_REQUEST, - PROOF_DECLINE, -]; - -export const MESSAGE_MAKE = "messages.make"; -export const MESSAGE_LIST = "messages.list"; -export const MESSAGE_DELETE = "messages.delete"; - -export type BasicMessageEvent = - | typeof MESSAGE_MAKE - | typeof MESSAGE_LIST - | typeof MESSAGE_DELETE; - -export const BASIC_MESSAGE_EVENTS: BasicMessageEvent[] = [ - MESSAGE_MAKE, - MESSAGE_LIST, - MESSAGE_DELETE, -]; - -export const ALL_EVENTS = [ - ...SCHEMA_EVENTS, - ...CRED_EVENTS, - ...PROOF_EVENTS, - ...CONNECTION_EVENTS, - ...BASIC_MESSAGE_EVENTS, -]; diff --git a/libs/dtos/src/index.ts b/libs/dtos/src/index.ts index 03062d4d..d57afd18 100644 --- a/libs/dtos/src/index.ts +++ b/libs/dtos/src/index.ts @@ -49,7 +49,3 @@ export * from "./errors/schema.not.created.error"; export * from "./errors/credential.not.created.error"; export * from "./errors/ledger.provider.fail.registration.error"; export * from "./errors/connection.unsupported.type.error"; - -export * from "./events/event"; -export * from "./events/types"; -export * from "./events/dtoToEventTransformer"; diff --git a/libs/nats/.eslintrc.json b/libs/nats/.eslintrc.json deleted file mode 100644 index 9d9c0db5..00000000 --- a/libs/nats/.eslintrc.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "extends": ["../../.eslintrc.json"], - "ignorePatterns": ["!**/*"], - "overrides": [ - { - "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], - "rules": {} - }, - { - "files": ["*.ts", "*.tsx"], - "rules": {} - }, - { - "files": ["*.js", "*.jsx"], - "rules": {} - } - ] -} diff --git a/libs/nats/README.md b/libs/nats/README.md deleted file mode 100644 index e69de29b..00000000 diff --git a/libs/nats/jest.config.ts b/libs/nats/jest.config.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/libs/nats/package.json b/libs/nats/package.json deleted file mode 100644 index 0d464787..00000000 --- a/libs/nats/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "@ocm-engine/nats", - "version": "0.0.1", - "type": "commonjs" -} diff --git a/libs/nats/project.json b/libs/nats/project.json deleted file mode 100644 index 5bf5c347..00000000 --- a/libs/nats/project.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "name": "nats", - "$schema": "../../node_modules/nx/schemas/project-schema.json", - "sourceRoot": "libs/nats/src", - "projectType": "library", - "targets": { - "build": { - "executor": "@nx/js:tsc", - "outputs": ["{options.outputPath}"], - "options": { - "outputPath": "dist/libs/nats", - "tsConfig": "libs/nats/tsconfig.lib.json", - "packageJson": "libs/nats/package.json", - "main": "libs/nats/src/index.ts", - "assets": ["libs/nats/*.md"] - } - }, - "lint": { - "executor": "@nx/linter:eslint", - "outputs": ["{options.outputFile}"], - "options": { - "lintFilePatterns": ["libs/nats/**/*.ts"] - } - }, - "test": { - "executor": "@nx/jest:jest", - "outputs": ["{workspaceRoot}/coverage/{projectRoot}"], - "options": { - "jestConfig": "libs/nats/jest.config.ts", - "passWithNoTests": true - }, - "configurations": { - "ci": { - "ci": true, - "codeCoverage": true - } - } - } - }, - "tags": [] -} diff --git a/libs/nats/src/base.nats.service.ts b/libs/nats/src/base.nats.service.ts deleted file mode 100644 index 3621a265..00000000 --- a/libs/nats/src/base.nats.service.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { Injectable, Logger } from "@nestjs/common"; -import { ConfigService } from "@nestjs/config"; -import { - connect, - DiscardPolicy, - JetStreamClient, - JetStreamManager, - JSONCodec, - NatsConnection, - NatsError, - RetentionPolicy, - StorageType, - StreamConfig, -} from "nats"; -import asyncRetry from "async-retry"; -import { IConfAgent, IConfNats } from "@ocm-engine/config"; - -@Injectable() -export class NatsBaseService { - protected config: IConfNats; - protected jsonCodec = JSONCodec(); - protected client: NatsConnection; - protected jsClient: JetStreamClient; - protected jsm: JetStreamManager; - protected readonly logger: Logger = new Logger(NatsBaseService.name); - protected streamConfig: StreamConfig; - - constructor(private configService: ConfigService) { - const agentConfig = this.configService.get<IConfAgent>("agent"); - if (agentConfig?.agentIsRest) { - return; - } - - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.config = configService.get<IConfNats>("nats")!; - - //TODO: What part should be configured by env vars ? - this.streamConfig = { - first_seq: 0, - allow_direct: false, - allow_rollup_hdrs: false, - deny_delete: false, - deny_purge: false, - discard: DiscardPolicy.Old, - discard_new_per_subject: false, - duplicate_window: 0, - max_bytes: -1, - max_msg_size: -1, - max_msgs: -1, - mirror_direct: false, - num_replicas: 0, - name: this.config.streamName, - max_consumers: 1, - subjects: this.config.subjects, - retention: RetentionPolicy.Workqueue, - sealed: false, - storage: StorageType.File, - max_msgs_per_subject: 10, - max_age: 86400000000000, - }; - this.connectToNats(); - } - - private async connectToNats() { - await asyncRetry( - async () => { - this.client = await connect({ servers: this.config.servers }); - this.jsClient = this.client.jetstream(); - this.jsm = await this.client.jetstreamManager(); - - await this.registerStream(this.streamConfig); - }, - { - retries: 5, - onRetry: (error) => { - this.logger.log(JSON.stringify(error, null, 2)); - this.logger.error( - `Failed to connect to NATS, retrying...${error.message}`, - ); - }, - }, - ); - - this.logger.log("Connected to Nats"); - } - - disconnect = () => { - return this.client.close(); - }; - - private registerStream = async (sconfig: StreamConfig) => { - try { - return await this.jsm.streams.add(sconfig); - } catch (e) { - this.logger.log(JSON.stringify(e, null, 2)); - - if ( - (e instanceof NatsError && e.api_error?.err_code === 10058) || - (e instanceof NatsError && e.api_error?.err_code === 10065) - ) { - this.logger.log(`Trying to update ${sconfig.name} stream`); - return await this.jsm.streams.update(sconfig.name, sconfig); - } - - throw new Error(`RegisterStream failed.`); - } - }; -} diff --git a/libs/nats/src/consumer.nats.service.ts b/libs/nats/src/consumer.nats.service.ts deleted file mode 100644 index a3ffc541..00000000 --- a/libs/nats/src/consumer.nats.service.ts +++ /dev/null @@ -1,102 +0,0 @@ -import { Injectable } from "@nestjs/common"; -import { - AckPolicy, - ConsumerConfig, - DeliverPolicy, - NatsError, - ReplayPolicy, -} from "nats"; -import { NatsBaseService } from "./base.nats.service"; -import { ConfigService } from "@nestjs/config"; -import { CloudEventDto, OcmError } from "@ocm-engine/dtos"; -import { SimpleMutex } from "nats/lib/nats-base-client/util"; -import { IConfAgent } from "@ocm-engine/config"; - -@Injectable() -export class ConsumerService extends NatsBaseService { - //eslint-disable-next-line - private readonly agentConfig: IConfAgent; - constructor(configService: ConfigService) { - super(configService); - - //TODO: no like ! move config, interfaces to seperate lib - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.agentConfig = configService.get<IConfAgent>("agent")!; - } - - private registerConsumer = (stream: string) => { - const consumerConfig: ConsumerConfig = { - max_deliver: 5, - ack_wait: 60 * 1000_000_000, // increase wait time to 1 minute - name: this.agentConfig.agentConsumerName, - ack_policy: AckPolicy.Explicit, - deliver_policy: DeliverPolicy.All, - replay_policy: ReplayPolicy.Original, - }; - - try { - this.jsm.consumers.add(stream, consumerConfig); - - return this.jsClient.consumers.get(stream, consumerConfig.name); - } catch (error) { - if (error instanceof NatsError && error.code === "409") { - this.logger.log("Consumer already exists"); - return this.jsClient.consumers.get(stream, consumerConfig.name); - } - - throw new Error( - `register consumer fail ${JSON.stringify(error, null, 2)}`, - ); - } - }; - - async subscribe<T>( - handler: (event: CloudEventDto<T>) => Promise<void>, - ): Promise<void> { - const consumer = await this.registerConsumer(this.streamConfig.name); - - const messages = await consumer.consume({ - max_messages: this.agentConfig.agentConsumerMaxMessages, - }); - - for await (const message of messages) { - const event = this.jsonCodec.decode(message.data) as CloudEventDto<T>; - - this.logger.log("event received, processing..."); - this.logger.debug(JSON.stringify(event, null, 2)); - - // if this is "await" it will create a head-of-line blocking - // i.e. no other message will be consumed - - // if I remove "await" this may lead to large number - // of async operations which may exceed the limits of the runtime - // we will need to introduce rate limiter and etc. - - // https://github.com/nats-io/nats.deno/blob/main/examples/jetstream/07_consume_jobs.ts - // Can the agent handle the concurency of working with two things for example - creating schema and creating cred def ?? - // I guess load tests need to be done (I'm pretty sure the wallet cant handle such thing, as the ledgers are extremely slow) - - const rl = new SimpleMutex(this.agentConfig.agentConsumerRateLimit); - rl.lock(); - - handler(event) - .then(() => message.ack()) - .catch((e) => { - if (e instanceof OcmError) { - this.logger.log( - `OCM error occurred during event consumption: ${e.message}`, - ); - return message.ack(); - } - if (e instanceof Error) { - this.logger.log( - `Could not handle consuming event with reason, ${e.message}`, - ); - } - //TODO: we should implement dead letter queue - return message.nak(); - }) - .finally(() => rl.unlock()); - } - } -} diff --git a/libs/nats/src/index.ts b/libs/nats/src/index.ts deleted file mode 100644 index f84ed630..00000000 --- a/libs/nats/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./nats.module"; -export * from "./consumer.nats.service"; -export * from "./producer.nats.service"; diff --git a/libs/nats/src/nats.module.ts b/libs/nats/src/nats.module.ts deleted file mode 100644 index b8ba1f28..00000000 --- a/libs/nats/src/nats.module.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Module } from "@nestjs/common"; -import { ConfigModule } from "@nestjs/config"; -import { ProducerService } from "./producer.nats.service"; -import { ConsumerService } from "./consumer.nats.service"; - -@Module({ - imports: [ConfigModule], - controllers: [], - providers: [ProducerService, ConsumerService], - exports: [ProducerService, ConsumerService], -}) -export class NatsModule {} diff --git a/libs/nats/src/producer.nats.service.ts b/libs/nats/src/producer.nats.service.ts deleted file mode 100644 index 7f9e2509..00000000 --- a/libs/nats/src/producer.nats.service.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { Injectable } from "@nestjs/common"; -import { PubAck, JetStreamPublishOptions } from "nats"; -import { NatsBaseService } from "./base.nats.service"; -import { ConfigService } from "@nestjs/config"; -import { CloudEventDto } from "@ocm-engine/dtos"; - -@Injectable() -export class ProducerService extends NatsBaseService { - constructor(configService: ConfigService) { - super(configService); - } - - async publish<T>( - subject: string, - event: CloudEventDto<T>, - opts?: JetStreamPublishOptions, - ): Promise<PubAck> { - const payload = this.jsonCodec.encode(event); - return this.jsClient.publish(subject, payload, opts); - } -} diff --git a/libs/nats/tsconfig.json b/libs/nats/tsconfig.json deleted file mode 100644 index f5b85657..00000000 --- a/libs/nats/tsconfig.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "compilerOptions": { - "module": "commonjs", - "forceConsistentCasingInFileNames": true, - "strict": true, - "noImplicitOverride": true, - "noPropertyAccessFromIndexSignature": true, - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true - }, - "files": [], - "include": [], - "references": [ - { - "path": "./tsconfig.lib.json" - }, - { - "path": "./tsconfig.spec.json" - } - ] -} diff --git a/libs/nats/tsconfig.lib.json b/libs/nats/tsconfig.lib.json deleted file mode 100644 index 1eb40b58..00000000 --- a/libs/nats/tsconfig.lib.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "../../dist/out-tsc", - "declaration": true, - "types": ["node"], - "target": "es6", - "strictNullChecks": true, - "noImplicitAny": true, - "strictBindCallApply": true, - "forceConsistentCasingInFileNames": true, - "noFallthroughCasesInSwitch": true - }, - "include": ["src/**/*.ts"], - "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"] -} diff --git a/libs/nats/tsconfig.spec.json b/libs/nats/tsconfig.spec.json deleted file mode 100644 index 9b2a121d..00000000 --- a/libs/nats/tsconfig.spec.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "outDir": "../../dist/out-tsc", - "module": "commonjs", - "types": ["jest", "node"] - }, - "include": [ - "jest.config.ts", - "src/**/*.test.ts", - "src/**/*.spec.ts", - "src/**/*.d.ts" - ] -} diff --git a/package.json b/package.json index 0791fbfd..7f3dc438 100644 --- a/package.json +++ b/package.json @@ -3,25 +3,16 @@ "version": "0.1.0", "license": "Apache-2.0", "scripts": { - "build:all": "yarn build:agent && yarn build:cm && yarn build:am && yarn build:pm && yarn build:gw && yarn build:dashboard", + "build:all": "yarn build:agent && yarn build:hin-agent && yarn build:dashboard", "build:agent": "nx run agent:build:development --parallel=3", "build:agent:production": "nx run agent:build:production", - "build:cm": "nx run connection-manager:build:development --parallel=3", - "build:cm:production": "nx run connection-manager:build:production", - "build:am": "nx run attestation-manager:build:development --parallel=3", - "build:am:production": "nx run attestation-manager:build:production", - "build:pm": "nx run proof-manager:build:development --parallel=3", - "build:pm:production": "nx run proof-manager:build:production", - "build:gw": "nx run gateway:build:development --parallel=3", - "build:gw:production": "nx run gateway:build:production", + "build:hin-agent": "nx run hin-agent:build:development --parallel=3", + "build:hin-agent:production": "nx run hin-agent:build:production", "build:dashboard": "nx run dashboard:build:development --parallel=3", "build:dashboard:production": "nx run dashboard:build:production", - "serve:all": "concurrently \"yarn serve:agent\" \"yarn serve:cm\" \"yarn serve:am\" \"yarn serve:pm\" \"yarn serve:gw\" \"yarn serve:dashboard\"", + "serve:all": "concurrently \"yarn serve:agent\" \"yarn serve:hin-agent\" \"yarn serve:dashboard\"", "serve:agent": "nx run agent:serve:development", - "serve:cm": "nx run connection-manager:serve:development", - "serve:am": "nx run attestation-manager:serve:development", - "serve:pm": "nx run proof-manager:serve:development", - "serve:gw": "nx run gateway:serve:development", + "serve:hin-agent": "nx run hin-agent:serve:development", "serve:dashboard": "nx run dashboard:serve:development", "infra": "cd compose && docker-compose --profile issuer --profile holder up -d --build", "infra:down": "cd compose && docker-compose --profile issuer --profile holder down", @@ -63,12 +54,10 @@ "class-transformer": "^0.5.1", "class-validator": "^0.14.0", "classnames": "^2.3.2", - "cloudevents": "^7.0.0", "date-fns": "^2.30.0", "joi": "^17.9.2", "mobx": "^6.10.2", "mobx-react": "^9.0.1", - "nats": "^2.14.0", "normalize.css": "^8.0.1", "passport": "^0.6.0", "passport-http": "^0.3.0", diff --git a/tsconfig.base.json b/tsconfig.base.json index d59b4c94..07a9a736 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -26,8 +26,7 @@ "@ocm-engine/clients": ["libs/clients/src/backend.ts"], "@ocm-engine/config": ["libs/config/src/index.ts"], "@ocm-engine/dtos": ["libs/dtos/src/index.ts"], - "@ocm-engine/ledgers": ["libs/ledgers/src/index.ts"], - "@ocm-engine/nats": ["libs/nats/src/index.ts"] + "@ocm-engine/ledgers": ["libs/ledgers/src/index.ts"] } }, "exclude": ["node_modules", "tmp"] diff --git a/yarn.lock b/yarn.lock index 425d21d6..2c01739f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4349,7 +4349,7 @@ ajv-keywords@^5.1.0: dependencies: fast-deep-equal "^3.1.3" -ajv@8.12.0, ajv@^8.0.0, ajv@^8.11.0, ajv@^8.12.0, ajv@^8.9.0: +ajv@8.12.0, ajv@^8.0.0, ajv@^8.12.0, ajv@^8.9.0: version "8.12.0" resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.12.0.tgz#d1a0527323e22f53562c567c00991577dfbe19d1" integrity sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA== @@ -5495,18 +5495,6 @@ clone@^1.0.2: resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e" integrity sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg== -cloudevents@^7.0.0: - version "7.0.2" - resolved "https://registry.yarnpkg.com/cloudevents/-/cloudevents-7.0.2.tgz#367b22bb6399ab15a6b18347e6ce5ccecdc87849" - integrity sha512-WiOqWsNkMZmMMZ6xa3kzx/MA+8+V+c5eGkStZIcik+Px2xCobmzcacw1EOGyfhODaQKkIv8TxXOOLzV69oXFqA== - dependencies: - ajv "^8.11.0" - ajv-formats "^2.1.1" - json-bigint "^1.0.0" - process "^0.11.10" - util "^0.12.4" - uuid "^8.3.2" - clsx@^1.1.1: version "1.2.1" resolved "https://registry.yarnpkg.com/clsx/-/clsx-1.2.1.tgz#0ddc4a20a549b59c93a4116bb26f5294ca17dc12" @@ -8646,7 +8634,7 @@ ipaddr.js@^2.0.1: resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-2.1.0.tgz#2119bc447ff8c257753b196fc5f1ce08a4cdf39f" integrity sha512-LlbxQ7xKzfBusov6UMi4MFpEg0m+mAm9xyNGEduwXMEDuf4WfzB/RZwMVYEd7IKGvh4IUkEXYxtAVu9T3OelJQ== -is-arguments@^1.0.4, is-arguments@^1.1.1: +is-arguments@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/is-arguments/-/is-arguments-1.1.1.tgz#15b3f88fda01f2a97fec84ca761a560f123efa9b" integrity sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA== @@ -8742,13 +8730,6 @@ is-generator-fn@^2.0.0: resolved "https://registry.yarnpkg.com/is-generator-fn/-/is-generator-fn-2.1.0.tgz#7d140adc389aaf3011a8f2a2a4cfa6faadffb118" integrity sha512-cTIB4yPYL/Grw0EaSzASzg6bBy9gqCofvWN8okThAYIxKJZC+udlRAmGbM0XLeniEJSs8uEgHPGuHSe1XsOLSQ== -is-generator-function@^1.0.7: - version "1.0.10" - resolved "https://registry.yarnpkg.com/is-generator-function/-/is-generator-function-1.0.10.tgz#f1558baf1ac17e0deea7c0415c438351ff2b3c72" - integrity sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A== - dependencies: - has-tostringtag "^1.0.0" - is-glob@^4.0.0, is-glob@^4.0.1, is-glob@^4.0.3, is-glob@~4.0.1: version "4.0.3" resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084" @@ -8871,7 +8852,7 @@ is-text-path@^2.0.0: dependencies: text-extensions "^2.0.0" -is-typed-array@^1.1.13, is-typed-array@^1.1.3: +is-typed-array@^1.1.13: version "1.1.13" resolved "https://registry.yarnpkg.com/is-typed-array/-/is-typed-array-1.1.13.tgz#d6c5ca56df62334959322d7d7dd1cca50debe229" integrity sha512-uZ25/bUAlUY5fR4OKT4rZQEBrzQWYV9ZJYGGsUmEJ6thodVJ1HX64ePQ6Z0qPWP+m+Uq6e9UugrE38jeYsDSMw== @@ -9510,13 +9491,6 @@ jsesc@~0.5.0: resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" integrity sha512-uZz5UnB7u4T9LvwmFqXii7pZSouaRPorGs5who1Ip7VO0wxanFvBL7GkM6dTHlgX+jhBApRetaWpnDabOeTcnA== -json-bigint@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/json-bigint/-/json-bigint-1.0.0.tgz#ae547823ac0cad8398667f8cd9ef4730f5b01ff1" - integrity sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ== - dependencies: - bignumber.js "^9.0.0" - json-buffer@3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.1.tgz#9338802a30d3b6605fbe0613e094008ca8c05a13" @@ -10632,13 +10606,6 @@ nanoid@^3.3.7: resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.7.tgz#d0c301a691bc8d54efa0a2226ccf3fe2fd656bd8" integrity sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g== -nats@^2.14.0: - version "2.19.0" - resolved "https://registry.yarnpkg.com/nats/-/nats-2.19.0.tgz#3772b5bc4ae9506f4c686d4b86e413a6ceeb967c" - integrity sha512-TuOAqPljCRpfHPo2o3midezchqYJUOOnK/YLmYf9rdoshzlYN1xvCd9dAKveVB6Bfubp/m63eN3l3ukfn43JOg== - dependencies: - nkeys.js "1.0.5" - natural-compare-lite@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz#17b09581988979fddafe0201e931ba933c96cbb4" @@ -10677,13 +10644,6 @@ next-tick@^1.1.0: resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.1.0.tgz#1836ee30ad56d67ef281b22bd199f709449b35eb" integrity sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ== -nkeys.js@1.0.5: - version "1.0.5" - resolved "https://registry.yarnpkg.com/nkeys.js/-/nkeys.js-1.0.5.tgz#3024bde671eb33be0316ff2d5abe8b8cec960158" - integrity sha512-u25YnRPHiGVsNzwyHnn+PT90sgAhnS8jUJ1nxmkHMFYCJ6+Ic0lv291w7uhRBpJVJ3PH2GWbYqA151lGCRrB5g== - dependencies: - tweetnacl "1.0.3" - no-case@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/no-case/-/no-case-3.0.4.tgz#d361fd5c9800f558551a8369fc0dcd4662b6124d" @@ -12078,11 +12038,6 @@ process-nextick-args@~2.0.0: resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2" integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag== -process@^0.11.10: - version "0.11.10" - resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182" - integrity sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A== - promise-all-reject-late@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/promise-all-reject-late/-/promise-all-reject-late-1.0.1.tgz#f8ebf13483e5ca91ad809ccc2fcf25f26f8643c2" @@ -13764,7 +13719,16 @@ string-length@^4.0.1: char-regex "^1.0.2" strip-ansi "^6.0.0" -"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0": + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -13839,7 +13803,14 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -14356,11 +14327,6 @@ tuf-js@^1.1.7: debug "^4.3.4" make-fetch-happen "^11.1.1" -tweetnacl@1.0.3: - version "1.0.3" - resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.3.tgz#ac0af71680458d8a6378d0d0d050ab1407d35596" - integrity sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw== - type-check@^0.4.0, type-check@~0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1" @@ -14683,17 +14649,6 @@ util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1: resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw== -util@^0.12.4: - version "0.12.5" - resolved "https://registry.yarnpkg.com/util/-/util-0.12.5.tgz#5f17a6059b73db61a875668781a1c2b136bd6fbc" - integrity sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA== - dependencies: - inherits "^2.0.3" - is-arguments "^1.0.4" - is-generator-function "^1.0.7" - is-typed-array "^1.1.3" - which-typed-array "^1.1.2" - utils-merge@1.0.1, utils-merge@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713" @@ -15010,7 +14965,7 @@ which-collection@^1.0.1: is-weakmap "^2.0.2" is-weakset "^2.0.3" -which-typed-array@^1.1.13, which-typed-array@^1.1.14, which-typed-array@^1.1.15, which-typed-array@^1.1.2: +which-typed-array@^1.1.13, which-typed-array@^1.1.14, which-typed-array@^1.1.15: version "1.1.15" resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.15.tgz#264859e9b11a649b388bfaaf4f767df1f779b38d" integrity sha512-oV0jmFtUky6CXfkqehVvBP/LSWJ2sy4vWMioiENyJLePrBO/yKyV9OyJySfAKosh+RYkIl5zJCNZ8/4JncrpdA== @@ -15059,7 +15014,16 @@ wordwrap@^1.0.0: resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + +wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== -- GitLab