diff --git a/docs/env.md b/docs/env.md index 2b74ad8c9..be728fb95 100644 --- a/docs/env.md +++ b/docs/env.md @@ -35,6 +35,7 @@ Environmental variables are also tracked in `ENVIRONMENT_VARIABLES` within `src/ - `AUTHORIZED_PUBLISHERS_LIST`: AccessList contract addresses (per chain). If present, Node will only index assets published by the accounts present on the given access lists. Example: `"{ \"8996\": [\"0x967da4048cD07aB37855c090aAF366e4ce1b9F48\",\"0x388C818CA8B9251b393131C08a736A67ccB19297\"] }"` - `VALIDATE_UNSIGNED_DDO`: If set to `false`, the node will not validate unsigned DDOs and will request a signed message with the publisher address, nonce and signature. Default is `true`. Example: `false` - `JWT_SECRET`: Secret used to sign JWT tokens. Default is `ocean-node-secret`. Example: `"my-secret-jwt-token"` +- `NODE_OWNER_INFO`: Optional JSON object returned by the root endpoint as `ownerInfo`. Example: `"{\"imprint\":{\"legalName\":\"Example Ocean Services GmbH\"},\"termsAndConditions\":{\"url\":\"https://example.com/terms\"},\"anyCustomSection\":{\"foo\":\"bar\"}}"` ## Database diff --git a/src/components/httpRoutes/rootEndpoint.ts b/src/components/httpRoutes/rootEndpoint.ts index 4f3a60684..c67a2f6a3 100644 --- a/src/components/httpRoutes/rootEndpoint.ts +++ b/src/components/httpRoutes/rootEndpoint.ts @@ -2,6 +2,7 @@ import express from 'express' import { HTTP_LOGGER } from '../../utils/logging/common.js' import { getConfiguration } from '../../utils/index.js' import { getAllServiceEndpoints } from './index.js' +import { getNodeOwnerInfo } from './utils.js' export const rootEndpointRoutes = express.Router() rootEndpointRoutes.get('/', async (req, res) => { @@ -10,12 +11,21 @@ rootEndpointRoutes.get('/', async (req, res) => { HTTP_LOGGER.warn(`Supported networks not defined`) } const keyManager = req.oceanNode.getKeyManager() - res.json({ + const rootResponse: Record = { nodeId: keyManager.getPeerId().toString(), chainIds: config.supportedNetworks ? Object.keys(config.supportedNetworks) : [], providerAddress: keyManager.getEthAddress(), serviceEndpoints: getAllServiceEndpoints(), software: 'Ocean-Node', version: '0.0.1' - }) + } + + const ownerInfo = getNodeOwnerInfo() + if (ownerInfo) { + rootResponse.ownerInfo = ownerInfo + } else { + HTTP_LOGGER.warn('NODE_OWNER_INFO not present or invalid') + } + + res.json(rootResponse) }) diff --git a/src/components/httpRoutes/utils.ts b/src/components/httpRoutes/utils.ts new file mode 100644 index 000000000..80ea9ebcf --- /dev/null +++ b/src/components/httpRoutes/utils.ts @@ -0,0 +1,26 @@ +const OWNER_INFO_ENV_KEY = 'NODE_OWNER_INFO' + +function parseObj(envValue: string): Record | null { + if (!envValue) { + return null + } + + try { + const parsedValue = JSON.parse(envValue) + if ( + typeof parsedValue === 'object' && + parsedValue !== null && + !Array.isArray(parsedValue) + ) { + return parsedValue as Record + } + } catch { + return null + } + + return null +} + +export function getNodeOwnerInfo(): Record | null { + return parseObj(process.env[OWNER_INFO_ENV_KEY]) +}