Logo

Autoschematic

GitHub
Cluster Login

Resource Bodies and filter()

Once you've designed your address space, you need to decide how you'll store resource bodies on-disk. In the case of the Grafana connnector, we use JSON. Most Rust connectors use RON, with custom internal types that #[derive(Serialize, Deserialize)]. In Python, you might use json.dumps(...).

The Grafana connector explicitly strips fields that are not user-editable:

DATASOURCE_TRANSIENT_FIELDS = {"id", "orgId", "uid", "typeLogoUrl", "readOnly"}
DASHBOARD_TRANSIENT_FIELDS = {"id", "version"}

In _get_datasource() and _get_dashboard(), those fields are removed before the connector returns resource_definition=json.dumps(...).encode().

Keep address data out of the resource body. A datasource's name is already in grafana/datasources/[name].json, so it isn't stored in the resource definition on-disk.

Connector.filter(addr): declaring the address space to the host

filter() is where a connector declares which files it manages. The Grafana connector, like many connectors keeps this simple: if decode_addr() recognizes the path, filter returns FilterResponse.RESOURCE, else FilterResponse.NONE.

async def filter(self, addr: str) -> FilterResponse:
    if decode_addr(addr) is not None:
        return FilterResponse.RESOURCE
    return FilterResponse.NONE

Reference files:

Next: Read Methods (get() and list())