Validation API client reference

Inside validate(block, context), context.client.get(path, query) reads InfraBuffet records. It is not an HTTP client. It needs no API token, and it can only read the routes listed below.

The client does not check the permissions of the user who saves the block. Inside the current infrastructure it can read everything in the tables below. It can also read any scope by ID, including that scope’s Terraform state. Treat validator code as trusted with that access.

Make a call

var answer = context.client.get("/api/infras/" + block.infra.id + "/providers", {
  name: "random-default",
  size: 1
});
if (!answer.ok) {
  return "Cannot read providers: " + answer.data.detail;
}
if (answer.data.items.length === 0) {
  return "The infrastructure owner must configure random-default";
}
  • The path must start with /api/. A query string written into the path is ignored, so use the second argument.
  • The second argument is an object. An array becomes repeated query values, for example values__environment: ["development", "staging"]. It may be omitted.

Response

PropertyMeaning
oktrue when the read succeeded. Check it before reading anything else.
statusThe status code. A successful read returns 200.
dataThe record, a list, or an error.

A list has data.items, data.total, and data.last_page. An error has data.code, data.category, and data.detail.

Properties use the same snake_case names as the REST API, for example id and last_page.

Routes

All paths start with /api. Infrastructure-scoped routes accept only the infrastructure the validator belongs to.

RouteReach
/infras
/infras/{id}
Any infrastructure.
/scopes
/scopes/{id}
Any scope, in any infrastructure. The detail includes the scope’s Terraform state.
/infras/{id}/providertypes
/providertypes/{id}
Current infrastructure.
/infras/{id}/providers
/providers/{id}
Current infrastructure. Secret fields are omitted.
/infras/{id}/blocktemplates
/blocktemplates/{id}
Current infrastructure.
/infras/{id}/blocks
/blocks/{id}
Current infrastructure, every scope. Secret values are omitted.

Only GET is supported. The client cannot read users, teams, jobs, data sources, or saved filters.

Query parameters

List routes take the same parameters as their REST endpoints: q, sort, page, size (default 50), and the filters below.

Block lists accept:

  • scope, scope__in, block_template, block_template__in
  • name, name__regex
  • status: new, applied, or changed
  • owner_managed
  • values__<field>: matches a top-level stored value as text. Use values__vlan: "100" or values__enabled: "false". It does not match outputs or defaults.

Limits and errors

  • At most 20 calls per validation. Calls that fail still count. After that, calls return status 429.
  • Status 400 means a malformed path or query. Status 404 means an unsupported route. Status 403 means the record is outside the boundaries above.
  • Do not accept a block because a check failed. Return a message instead.

Reads see saved records only. They do not reserve a value, so concurrent saves can both pass a uniqueness check.