Skip to content

Template store

The template store holds custom specification formats. Each template documents a format (its fields and rules) and links to a policy that validates specs in that format and converts them into the Parser's internal representation. This lets a network offer simpler or organization-specific spec formats on top of the built-in one.

At a glance

Runs on: the management cluster, as templates-registry-svc (NodePort 30106).
How templates are used: see How the Parser works: writing a custom spec parser.

Schema

@dataclass
class TemplateObject:
    templateUri: str = ''
    templatePolicyRuleUri: str = ''
    templateMetadata: Dict[str, str] = field(default_factory=dict)
    templateName: str = ''
    templateDescription: str = ''
    templateVersion: Dict[str, str] = field(
        default_factory=lambda: {"templateVersion": "", "tag": ""})
    templateTags: List[str] = field(default_factory=list)
    templateData: str = ''
Field Type Description
templateUri str Unique ID, generated as {templateName}:{templateVersion}-{tag}. Specs reference it in header.templateUri.
templatePolicyRuleUri str The policy that validates and converts specs in this format.
templateMetadata dict Extra details: author, creation date, related policies and so on.
templateName str Name of the template.
templateDescription str What the template is for.
templateVersion dict templateVersion (number) and tag (for example stable).
templateTags list Tags, for search.
templateData str A description of the format's fields, as a string (JSON, YAML or text). It uses the same attributes as component protocols.

APIs

Endpoint Method What it does
/template POST Create a template.
/template/<templateUri> GET Get a template.
/template/<templateUri> PUT Update a template.
/template/<templateUri> DELETE Delete a template.
/templates POST Search templates (MongoDB syntax: $eq, $ne, $in, $regex, ...).
/template/execute POST Run a template's policy on some input (see below).
# Create
curl -X POST http://<server-url>/template \
     -H "Content-Type: application/json" \
     -d '{
          "templateName": "ExampleTemplate",
          "templateDescription": "This is a sample template.",
          "templateVersion": {"templateVersion": "1.0", "tag": "stable"},
          "templateTags": ["config", "example"],
          "templateMetadata": {"author": "John Doe", "created": "2025-03-26"},
          "templateData": "{\"key\": \"value\"}"
      }'

# Get
curl -X GET http://<server-url>/template/ExampleTemplate:1.0-stable

# Update
curl -X PUT http://<server-url>/template/ExampleTemplate:1.0-stable \
     -H "Content-Type: application/json" \
     -d '{
          "templateDescription": "Updated description for the template.",
          "templateTags": ["config", "updated"],
          "templateMetadata": {"modifiedBy": "Jane Doe", "modifiedAt": "2025-03-26"},
          "templateData": "{\"key\": \"newValue\"}"
      }'

# Delete
curl -X DELETE http://<server-url>/template/ExampleTemplate:1.0-stable

# Search
curl -X POST http://<server-url>/templates \
     -H "Content-Type: application/json" \
     -d '{
          "templateMetadata.author": { "$eq": "User X" },
          "templateTags": { "$in": ["config", "stable"] }
      }'

More search examples

// Templates by a given author
{ "templateMetadata.author": { "$eq": "User X" } }

// Templates tagged "config" or "stable"
{ "templateTags": { "$in": ["config", "stable"] } }

// Templates whose name starts with "Example" (case-insensitive)
{ "templateName": { "$regex": "^Example", "$options": "i" } }

Running a template's policy

A template's templatePolicyRuleUri must point to a policy registered in the Policies System. That policy both validates input in the template's format and converts it into the Parser's internal representation.

You can run it directly, which is useful for testing a new format:

POST /template/execute

curl -X POST http://<server-url>/template/execute \
     -H "Content-Type: application/json" \
     -d '{
          "template_uri": "example-template:1.0-stable",
          "input_data": {},
          "parameters": {}
      }'
Field Type Required Description
template_uri string Yes The template whose policy to run.
input_data dict Yes The input to process.
parameters dict No Extra parameters for the policy.