trustgraph/docs/apis/api-config.md
cybermaggedon cc224e97f6
Update docs for API/CLI changes in 1.0 (#420)
* Update some API basics for the 0.23/1.0 API change
2025-07-03 14:58:29 +01:00

4.5 KiB

TrustGraph Config API

This API provides centralized configuration management for TrustGraph components. Configuration data is organized hierarchically by type and key, with support for persistent storage and push notifications.

Request/response

Request

The request contains the following fields:

  • operation: The operation to perform (get, list, getvalues, put, delete, config)
  • keys: Array of ConfigKey objects (for get, delete operations)
  • type: Configuration type (for list, getvalues operations)
  • values: Array of ConfigValue objects (for put operation)

Response

The response contains the following fields:

  • version: Version number for tracking changes
  • values: Array of ConfigValue objects returned by operations
  • directory: Array of key names returned by list operation
  • config: Full configuration map returned by config operation
  • error: Error information if operation fails

Operations

PUT - Store Configuration Values

Request:

{
    "operation": "put",
    "values": [
        {
            "type": "test",
            "key": "key1",
            "value": "value1"
        }
    ]
}

Response:

{
    "version": 123
}

GET - Retrieve Configuration Values

Request:

{
    "operation": "get",
    "keys": [
        {
            "type": "test",
            "key": "key1"
        }
    ]
}

Response:

{
    "version": 123,
    "values": [
        {
            "type": "test",
            "key": "key1",
            "value": "value1"
        }
    ]
}

LIST - List Keys by Type

Request:

{
    "operation": "list",
    "type": "test"
}

Response:

{
    "version": 123,
    "directory": ["key1", "key2", "key3"]
}

GETVALUES - Get All Values by Type

Request:

{
    "operation": "getvalues",
    "type": "test"
}

Response:

{
    "version": 123,
    "values": [
        {
            "type": "test",
            "key": "key1",
            "value": "value1"
        },
        {
            "type": "test",
            "key": "key2",
            "value": "value2"
        }
    ]
}

CONFIG - Get Entire Configuration

Request:

{
    "operation": "config"
}

Response:

{
    "version": 123,
    "config": {
        "test": {
            "key1": "value1",
            "key2": "value2"
        }
    }
}

DELETE - Remove Configuration Values

Request:

{
    "operation": "delete",
    "keys": [
        {
            "type": "test",
            "key": "key1"
        }
    ]
}

Response:

{
    "version": 124
}

REST service

The REST service is available at /api/v1/config and accepts the above request formats.

Websocket

Requests have a request object containing the operation fields. Responses have a response object containing the response fields.

Request:

{
    "id": "unique-request-id",
    "service": "config",
    "request": {
        "operation": "get",
        "keys": [
            {
                "type": "test",
                "key": "key1"
            }
        ]
    }
}

Response:

{
    "id": "unique-request-id",
    "response": {
        "version": 123,
        "values": [
            {
                "type": "test",
                "key": "key1",
                "value": "value1"
            }
        ]
    },
    "complete": true
}

Pulsar

The Pulsar schema for the Config API is defined in Python code here:

https://github.com/trustgraph-ai/trustgraph/blob/master/trustgraph-base/trustgraph/schema/config.py

Default request queue: non-persistent://tg/request/config

Default response queue: non-persistent://tg/response/config

Request schema: trustgraph.schema.ConfigRequest

Response schema: trustgraph.schema.ConfigResponse

Python SDK

The Python SDK provides convenient access to the Config API:

from trustgraph.api.config import ConfigClient

client = ConfigClient()

# Put a value
await client.put("test", "key1", "value1")

# Get a value
value = await client.get("test", "key1")

# List keys
keys = await client.list("test")

# Get all values for a type
values = await client.get_values("test")

Features

  • Hierarchical Organization: Configuration organized by type and key
  • Versioning: Each operation returns a version number for change tracking
  • Persistent Storage: Data stored in Cassandra for persistence
  • Push Notifications: Configuration changes pushed to subscribers
  • Multiple Access Methods: Available via Pulsar, REST, WebSocket, and Python SDK