Skip to content

Commit

Permalink
feat: externalize env (#153)
Browse files Browse the repository at this point in the history
Signed-off-by: Krishna Waske <[email protected]>
  • Loading branch information
GHkrishna committed Sep 11, 2024
1 parent 90bdbe2 commit 0901772
Show file tree
Hide file tree
Showing 45 changed files with 6,003 additions and 7,488 deletions.
50 changes: 37 additions & 13 deletions src/utils/util.ts → .env.sample

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ WORKDIR /app
# Copy package.json and yarn.lock files
COPY package.json yarn.lock ./

# Install dependencies
RUN yarn install --frozen-lockfile

# Copy the rest of the application code
COPY . .

# Install dependencies
RUN yarn install --frozen-lockfile

RUN yarn global add patch-package

# Build the application
Expand Down
4 changes: 2 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import base from './jest.config.base'

const config: Config.InitialOptions = {
...base,
name: 'afj-controller',
displayName: 'afj-controller',
name: 'credo-controller',
displayName: 'credo-controller',
testTimeout: 120000,
}

Expand Down
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@aries-framework/rest",
"name": "credo-controller",
"main": "build/index",
"types": "build/index",
"version": "0.9.4",
Expand Down Expand Up @@ -28,6 +28,8 @@
"tsoa": "tsoa spec-and-routes",
"dev": "tsoa spec-and-routes && tsnd --respawn samples/sampleWithApp.ts",
"build": "yarn run clean && yarn run compile",
"prestart:dev": "yarn run clean && yarn run compile",
"start:dev": "./bin/afj-rest.js --config ./samples/cliConfig.json",
"clean": "rimraf -rf ./build",
"compile": "tsoa spec-and-routes && tsc -p tsconfig.build.json",
"prepublishOnly": "yarn run build",
Expand All @@ -37,7 +39,7 @@
"validate": "yarn lint && yarn check-types && yarn check-format"
},
"dependencies": {
"@ayanworks/credo-polygon-w3c-module": "0.0.2-alpha.10",
"@ayanworks/credo-polygon-w3c-module": "1.0.0",
"@credo-ts/anoncreds": "0.5.3",
"@credo-ts/askar": "0.5.3",
"@credo-ts/core": "0.5.3",
Expand All @@ -57,6 +59,7 @@
"axios": "^1.4.0",
"body-parser": "^1.20.0",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.18.1",
"express-rate-limit": "^7.1.5",
"joi": "^17.12.3",
Expand Down Expand Up @@ -94,15 +97,15 @@
"eslint-import-resolver-typescript": "^3.5.5",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^27.3.1",
"jest": "^29.7.0",
"ngrok": "^4.3.1",
"prettier": "^2.8.8",
"supertest": "^6.2.3",
"ts-jest": "^27.0.7",
"ts-jest": "^29.1.2",
"ts-node-dev": "^2.0.0",
"typescript": "^5.3.3"
},
"engines": {
"node": ">=18"
"node": "18.19.0"
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/@credo-ts/core/build/modules/credentials/formats/jsonld/JsonLdCredentialFormat.d.ts b/node_modules/@credo-ts/core/build/modules/credentials/formats/jsonld/JsonLdCredentialFormat.d.ts
index d12468b..ae70f36 100644
--- a/node_modules/@credo-ts/core/build/modules/credentials/formats/jsonld/JsonLdCredentialFormat.d.ts
+++ b/node_modules/@credo-ts/core/build/modules/credentials/formats/jsonld/JsonLdCredentialFormat.d.ts
@@ -10,6 +10,8 @@ export interface JsonCredential {
issuanceDate: string;
expirationDate?: string;
credentialSubject: SingleOrArray<JsonObject>;
+ //TODO change type
+ prettyVc?: any;
[key: string]: unknown;
}
/**
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/node_modules/@credo-ts/core/build/modules/proofs/formats/dif-presentation-exchange/DifPresentationExchangeProofFormatService.js b/node_modules/@credo-ts/core/build/modules/proofs/formats/dif-presentation-exchange/DifPresentationExchangeProofFormatService.js
index 006d870..da56801 100644
--- a/node_modules/@credo-ts/core/build/modules/proofs/formats/dif-presentation-exchange/DifPresentationExchangeProofFormatService.js
+++ b/node_modules/@credo-ts/core/build/modules/proofs/formats/dif-presentation-exchange/DifPresentationExchangeProofFormatService.js
@@ -170,7 +170,8 @@ class DifPresentationExchangeProofFormatService {
try {
ps.validatePresentationDefinition(request.presentation_definition);
ps.validatePresentationSubmission(jsonPresentation.presentation_submission);
- ps.validatePresentation(request.presentation_definition, parsedPresentation);
+ // FIXME: Commenting validatePresentation() for now due to intermittent abandoned issue
+ //ps.validatePresentation(request.presentation_definition, parsedPresentation);
let verificationResult;
// FIXME: for some reason it won't accept the input if it doesn't know
// whether it's a JWT or JSON-LD VP even though the input is the same.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/node_modules/@credo-ts/core/build/modules/credentials/protocol/v2/V2CredentialProtocol.js b/node_modules/@credo-ts/core/build/modules/credentials/protocol/v2/V2CredentialProtocol.js
index fb1fb9d..b519694 100644
--- a/node_modules/@credo-ts/core/build/modules/credentials/protocol/v2/V2CredentialProtocol.js
+++ b/node_modules/@credo-ts/core/build/modules/credentials/protocol/v2/V2CredentialProtocol.js
@@ -97,7 +97,6 @@ class V2CredentialProtocol extends BaseCredentialProtocol_1.BaseCredentialProtoc
let credentialRecord = await this.findByProperties(messageContext.agentContext, {
threadId: proposalMessage.threadId,
role: models_1.CredentialRole.Issuer,
- connectionId: connection === null || connection === void 0 ? void 0 : connection.id,
});
const formatServices = this.getFormatServicesFromMessage(proposalMessage.formats);
if (formatServices.length === 0) {
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
diff --git a/node_modules/@credo-ts/tenants/build/context/TenantAgentContextProvider.d.ts b/node_modules/@credo-ts/tenants/build/context/TenantAgentContextProvider.d.ts
index 91bb8f4..b4dae61 100644
--- a/node_modules/@credo-ts/tenants/build/context/TenantAgentContextProvider.d.ts
+++ b/node_modules/@credo-ts/tenants/build/context/TenantAgentContextProvider.d.ts
@@ -1,5 +1,5 @@
import type { TenantRecord } from '../repository';
-import type { AgentContextProvider, UpdateAssistantUpdateOptions } from '@credo-ts/core';
+import type { AgentContextProvider, UpdateAssistantUpdateOptions , CacheModule, InMemoryLruCache } from '@credo-ts/core';
import { AgentContext, EventEmitter, Logger } from '@credo-ts/core';
import { TenantRecordService } from '../services';
import { TenantSessionCoordinator } from './TenantSessionCoordinator';
@@ -9,7 +9,9 @@ export declare class TenantAgentContextProvider implements AgentContextProvider
private eventEmitter;
private logger;
private tenantSessionCoordinator;
- constructor(tenantRecordService: TenantRecordService, rootAgentContext: AgentContext, eventEmitter: EventEmitter, tenantSessionCoordinator: TenantSessionCoordinator, logger: Logger);
+ private cacheModule;
+ private inMemoryLruCache;
+ constructor(tenantRecordService: TenantRecordService, rootAgentContext: AgentContext, eventEmitter: EventEmitter, tenantSessionCoordinator: TenantSessionCoordinator, logger: Logger, cache: InMemoryLruCache);
getAgentContextForContextCorrelationId(contextCorrelationId: string): Promise<AgentContext>;
getContextForInboundMessage(inboundMessage: unknown, options?: {
contextCorrelationId?: string;
diff --git a/node_modules/@credo-ts/tenants/build/context/TenantAgentContextProvider.js b/node_modules/@credo-ts/tenants/build/context/TenantAgentContextProvider.js
index d491d4e..d60ec79 100644
--- a/node_modules/@credo-ts/tenants/build/context/TenantAgentContextProvider.js
+++ b/node_modules/@credo-ts/tenants/build/context/TenantAgentContextProvider.js
@@ -24,16 +24,28 @@ let TenantAgentContextProvider = class TenantAgentContextProvider {
this.eventEmitter = eventEmitter;
this.tenantSessionCoordinator = tenantSessionCoordinator;
this.logger = logger;
+ this.cache = new core_1.CacheModule({
+ cache: new core_1.InMemoryLruCache({ limit: 100 }),
+ });
// Start listener for newly created routing keys, so we can register a mapping for each new key for the tenant
this.listenForRoutingKeyCreatedEvents();
}
async getAgentContextForContextCorrelationId(contextCorrelationId) {
+ this.logger.debug('debug ========= Inside getAgentContextForContextCorrelationId')
// It could be that the root agent context is requested, in that case we return the root agent context
if (contextCorrelationId === this.rootAgentContext.contextCorrelationId) {
return this.rootAgentContext;
}
// TODO: maybe we can look at not having to retrieve the tenant record if there's already a context available.
- const tenantRecord = await this.tenantRecordService.getTenantById(this.rootAgentContext, contextCorrelationId);
+ this.logger.debug('debug ========= Get tenantRecord from cache')
+ let tenantRecord = await this.cache.config.cache.get(this.rootAgentContext, `contextCorrelationId-${contextCorrelationId}`)
+ if(!tenantRecord) {
+ // TODO: maybe we can look at not having to retrieve the tenant record if there's already a context available.
+ this.logger.debug('debug ========= TenantRecord not found in cache')
+ tenantRecord = await this.tenantRecordService.getTenantById(this.rootAgentContext, contextCorrelationId)
+ await this.cache.config.cache.set(this.rootAgentContext,`contextCorrelationId-${contextCorrelationId}`,tenantRecord)
+ this.logger.debug(`debug ========= Cached tenant agent context for tenant '${contextCorrelationId}'`)
+ }
const shouldUpdate = !(0, core_1.isStorageUpToDate)(tenantRecord.storageVersion);
// If the tenant storage is not up to date, and autoUpdate is disabled we throw an error
if (shouldUpdate && !this.rootAgentContext.config.autoUpdateStorageOnStartup) {
19 changes: 9 additions & 10 deletions samples/cliConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"walletPassword": "postgres",
"walletAdminAccount": "postgres",
"walletAdminPassword": "postgres",
"walletScheme": "DatabasePerWallet",
"walletScheme": "ProfilePerWallet",
"indyLedger": [
{
"genesisTransactions": "https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_testnet_genesis",
Expand All @@ -19,29 +19,28 @@
"indyNamespace": "indicio:demonet"
},
{
"genesisTransactions": "http://test.bcovrin.vonx.io/genesis",
"genesisTransactions": "https://raw.githubusercontent.com/bcgov/von-network/main/BCovrin/genesis_test",
"indyNamespace": "bcovrin:testnet"
}
],
"endpoint": ["http://localhost:4002"],
"autoAcceptConnections": true,
"autoAcceptCredentials": "contentApproved",
"autoAcceptCredentials": "always",
"autoAcceptProofs": "contentApproved",
"useLegacyDidSovPrefix": true,
"logLevel": 5,
"logLevel": 2,
"inboundTransport": [
{
"transport": "http",
"port": 4002
}
],
"outboundTransport": ["http"],
"autoAcceptMediationRequests": false,
"adminPort": 4001,
"tenancy": true,
"didRegistryContractAddress": "0x1adeA199dCf07E17232415Cb232442BE52517Add",
"schemaManagerContractAddress": "0x289c7Bd4C7d38cC54bff370d6f9f01b74Df51b11",
"schemaFileServerURL": "https://schema.credebl.id/schemas/",
"didRegistryContractAddress": "0xcB80F37eDD2bE3570c6C9D5B0888614E04E1e49E",
"schemaManagerContractAddress": "0x4742d43C2dFCa5a1d4238240Afa8547Daf87Ee7a",
"rpcUrl": "https://rpc-amoy.polygon.technology",
"fileServerUrl": "https://schema.credebl.id/",
"fileServerUrl": "https://schema.credebl.id",
"fileServerToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJBeWFuV29ya3MiLCJpZCI6ImNhZDI3ZjhjLTMyNWYtNDRmZC04ZmZkLWExNGNhZTY3NTMyMSJ9.I3IR7abjWbfStnxzn1BhxhV0OEzt1x3mULjDdUcgWHk"
}
}
66 changes: 66 additions & 0 deletions scripts/taskdef/credo-ecs-taskdef.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"family": "${FAMILY}",
"containerDefinitions": [
{
"name": "Platform-admin",
"image": "%REPOSITORY_URI%:CREDO_v_%BUILD_NUMBER%",
"cpu": 154,
"memory": 307,
"portMappings": [
{
"containerPort": 8001,
"hostPort": 8001,
"protocol": "tcp"
},
{
"containerPort": 9001,
"hostPort": 9001,
"protocol": "tcp"
}
],
"essential": true,
"command": [
"--auto-accept-connections",
"--config",
"/config.json"
],
"environment": [
{
"name": "AFJ_REST_LOG_LEVEL",
"value": "1"
}
],
"environmentFiles": [
{
"value": "${S3_ARN}",
"type": "s3"
}
],
"mountPoints": [
{
"sourceVolume": "config",
"containerPath": "/config.json",
"readOnly": true
}
],
"volumesFrom": [],
"ulimits": []
}

],
"executionRoleArn": "arn:aws:iam::${ACCOUNT_ID}:role/ecsTaskExecutionRole",
"placementConstraints": [],
"requiresCompatibilities": [
"EC2"
],
"cpu": "154",
"memory": "307",
"volumes": [
{
"name": "config",
"host": {
"sourcePath": "${SourcePath}"
}
}
]
}
76 changes: 76 additions & 0 deletions scripts/taskdef/credo-fargate-taskdef.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"family": "${FAMILY}",
"containerDefinitions": [
{
"name": "Platform-admin",
"image": "%REPOSITORY_URI%:CREDO_v_%BUILD_NUMBER%",
"cpu": 0,
"portMappings": [
{
"containerPort": 8004,
"hostPort": 8004,
"protocol": "tcp"
},
{
"containerPort": 9004,
"hostPort": 9004,
"protocol": "tcp"
}
],
"essential": true,
"command": [
"--auto-accept-connections",
"--config",
"/config/${CONFIG_FILE}"
],
"environment": [
{
"name": "AFJ_REST_LOG_LEVEL",
"value": "1"
}
],
"environmentFiles": [
{
"value": "${S3_ARN}",
"type": "s3"
}
],
"mountPoints": [
{
"sourceVolume": "config",
"containerPath": "/config",
"readOnly": false
}
],
"volumesFrom": [],
"ulimits": [],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/${FAMILY}",
"awslogs-create-group": "true",
"awslogs-region": "ap-south-1",
"awslogs-stream-prefix": "ecs"
}
}
}

],
"executionRoleArn": "arn:aws:iam::${ACCOUNT_ID}:role/ecsTaskExecutionRole",
"networkMode": "awsvpc",
"placementConstraints": [],
"requiresCompatibilities": [
"FARGATE"
],
"cpu": "1024",
"memory": "2048",
"volumes": [
{
"name": "config",
"efsVolumeConfiguration": {
"fileSystemId": "${EFS}",
"rootDirectory": "/"
}
}
]
}
Loading

0 comments on commit 0901772

Please sign in to comment.