Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

The whole instance as code

Everything an instance is can be exported into one rustybin.yaml (version 2) that is committed, diffed and reviewed; applied to an instance with a dry run first; loaded at startup; and kept in a git repository from the console (see Source control). The mocks-only file of earlier releases (Configuration as code for mocks) is a version 1 document, still loaded and still exported by the mocks routes; a version 2 document holds the mocks sections plus the rest of the instance.

The document

version: 2
instance:
  title: Payments team mocks        # the setting console.title
  console: { user: payments }       # console.user; the password is never here
settings:                           # stored, non-secret settings by dotted key
  agents.default_ceiling: manage
  portal.enabled: "on"
secrets:                            # references only, never values
  assist.openai_key: ${RUSTYBIN_ASSIST_OPENAI_KEY}
  leads.webhook_token: secret:stored
mocks:                              # as in a version 1 file
  - name: orders
    spec: specs/orders.yaml         # next to the document (a bundle), or spec_inline
    responses: { mode: examples }
registry:
  servers: [...]                    # server.json documents of the mock MCP registry
portal:
  items: [{ id: "mock:orders", title: Orders API, tags: [payments], access: closed }]
harness:
  scenarios:                        # saved scenarios (harness mode)
    - { name: smoke, scenario: { ... } }               # inline, or
    - { name: checkout, file: scenarios/checkout.yaml } # in a file next to the document
tests:                              # saved tests: a request and its assertions
  - name: order-1
    request: { path: /mock/orders/orders/1, headers: { x-api-key: "{{X_API_KEY}}" } }
    assert: [{ status: 200 }, { json: $.id, equals: 1 }]
test_schedules:                     # saved tests on a schedule, a webhook for failures
  - name: nightly
    at: "02:30"                     # or every: 15m (5m to 24h)
    prefix: order-                  # or names: [order-1], or neither: every test
    webhook: https://hooks.example.com/rustybin
storyboards:                        # demo storyboards: steps with a talk track, an action, a reset
  - name: upstream-down
    steps:
      - { title: Break the upstream, action: { type: set_health, healthy: false }, reset: { type: set_health, healthy: true } }
agents:
  default_ceiling: traffic
  rules:
    - { match: { name: "ci-*" }, ceiling: read-only }
    - { match: { role: admin }, ceiling: editor }   # an admin's agents build, never administer
roles:                              # custom roles (the five built-in ones never change)
  - name: catalog-reader
    description: Reads mocks and traffic
    permissions: [mocks.read, traffic.read]
users:                              # never a password: a new user is invited
  - name: alice
    display_name: Alice Doe
    email: alice@example.com
    roles: [editor, catalog-reader]
health:
  initial: healthy                  # the /health toggle
SectionWhat it holdsApplied through
instancetitle (the console.title setting) and console.user (in password mode a document never changes the user name: a different one is a problem)the settings store
settingsNon-secret settings by dotted key, as GET /_rustybin/settings lists them; null unsets the stored valuethe settings store
secretsSecret settings as references: ${VAR} reads the variable from the environment when the document is loaded or applied, secret:stored keeps what the instance holds, null unsets it; a value that resolves to nothing is kept as it is and reportedthe settings store
mocksThe mocks, each with its spec inline (spec_inline) or as a file next to the document (spec), exactly the version 1 entriesthe mock store, as POST /_rustybin/mocks/apply
registryservers: server.json documents of the mock MCP registrythe registry's file copy (entries published through the API that the document names move into it)
portalitems: what the dev portal publishesthe portal (a mock the item names must exist; a mock: item of a visitor is skipped)
harnessscenarios: the saved scenarios, each inline (scenario) or as a file next to the document (file, see A scenario in a file), validated against the node's capsthe harness (a problem when harness mode is off)
testsThe saved tests, with {{variables}} for credentials (never values); a test that fails validation is a problem and is kept, never prunedthe saved tests (<state>/tests.json)
test_schedulesThe test schedules, without their status (a replaced schedule keeps its own); one that fails validation is a problem and is kept, never prunedthe schedules (<state>/test-schedules.json)
storyboardsThe demo storyboards, with {{variables}} for credentials (never values); applying one runs nothing; one that fails validation is a problem and is kept, never prunedthe storyboards (<state>/storyboards.json)
agentsThe default ceiling and the rules of AI agentsthe agents policy
rolesThe custom roles: name, description, permissionsthe user store; a prune never deletes a role somebody holds
usersThe users (password sign-in only): name, display name, email, roles, disabled; never a password or a hash (a document with one does not load the section). A user the document creates is invited, and the apply answers the link (results.users.invitations); sso: true is a single sign-on user (no link; roles are the pinned ones, the provider's groups give the rest), and a document never changes how an existing user signs inthe user store, with the API's rules: nobody changes their own roles, a caller grants only what it holds; a prune never deletes the first admin, the applying user or the last enabled admin
projectsThe projects: name, description and members ({user, roles}, the user by sign-in name); written by an export only when the instance has projects. A mock or a saved test names its project with project:the user store, before the mocks (so project: finds a project the document creates) and, for the members, after the users; a prune deletes only a project that holds nothing
healthinitial: healthy or unhealthythe /health toggle

Two rules make a document safe to apply:

  • A section that is absent is left alone. A document with only health changes nothing else. An export always writes every section (empty lists where there is nothing), so an export is the whole instance.
  • With prune, a present section is the whole truth for its part of the instance. API-created mocks, published portal items, published registry entries, saved scenarios, saved tests, test schedules and stored settings or secrets that the section does not name are removed. Without prune, applying only adds and updates. The git.* settings are never exported nor pruned: where an instance keeps its configuration is the deployment's business. A mock the document names but cannot load (an entry that does not parse, a spec that cannot be read, does not parse or does not compile) is a problem in the answer and is kept as it is: it is never pruned, and the dry run's would_delete says the same. A prune of mocks deletes only the instance's own API mocks: never a visitor's or an API key's mock (self-service), nor a running gateway scenario's mock, which is not exported either. The harness and registry sections prune only what the document does not name at all (an entry that fails validation is a problem, and its saved copy stays).

Mocks applied through the API or a repository are origin: api (saved in the mocks state directory, as console changes are); the ones a RUSTYBIN_CONFIG_FILE declares stay origin: file. The built-in petstore sample and visitors' self-service mocks are never exported, nor is the audit log (its audit.retention_days and audit.max_bytes settings are, under settings:). The mocks' demo credentials (API keys, basic users, bearer tokens) are part of the mocks and exported with them unless secrets=omit is asked; a secret of the instance (an AI key, a webhook token, a password hash) never is.

The JSON Schema of the document is GET /_rustybin/config/schema (and the management MCP resource rustybin://config.schema.json):

GET {{secured_url}}/_rustybin/config/schema
Authorization: Bearer {{admin_token}}
HTTP 200
[Asserts]
jsonpath "$.properties.version.enum" contains 2
jsonpath "$.properties.secrets.description" contains "never values"

A scenario in a file

A saved scenario may live in a file of its own, the one rustybin harness run takes, with the document naming it: file: instead of scenario:. It is read the way a mock's spec: file is:

Where the document comes fromA scenario's file:
A file given to RUSTYBIN_CONFIG_FILEA path relative to the document, or an absolute one
The configuration repository (a pull, the startup, the webhook)A path inside the repository, read from the commit: no .., no absolute path, no link
The API, a tool, rustybin config applyNot read: the entry is a problem that says to send scenario inline

The file is YAML or JSON, at most 256 KiB, and is not expanded for ${VAR} (a spec file is not either). An entry whose file cannot be read is a problem and its saved scenario, if there is one, stays: a prune never deletes what the document names. An export writes every scenario inline, so an instance that commits its own configuration (git.auto: push_on_change) records what it holds, not the layout it was loaded from.

# The scenario in its own file (the one `rustybin harness run` takes), and a
# document that names it instead of holding it.
mkdir scenarios
cat > scenarios/checkout.yaml <<'YAML'
name: checkout
description: A steady trickle through the gateway's checkout route.
target: http://127.0.0.1:8080
source:
  request:
    method: GET
    path: /status/200
pattern:
  type: constant
  rate: 5
  for: 10s
YAML
cat > rustybin.yaml <<'YAML'
version: 2
harness:
  scenarios:
    - name: checkout
      file: scenarios/checkout.yaml
YAML
RUSTYBIN_HTTP_PORT=$PORT RUSTYBIN_HTTPS_PORT=0 RUSTYBIN_GRPC_PORT=0 RUSTYBIN_HOST=127.0.0.1 \
  RUSTYBIN_LOG_LEVEL=warn RUSTYBIN_CONTROL_AUTH=open RUSTYBIN_ADMIN_TOKEN=$ADMIN \
  RUSTYBIN_HARNESS=on RUSTYBIN_HARNESS_TARGETS=127.0.0.1 \
  RUSTYBIN_CONFIG_FILE="$work/rustybin.yaml" \
  "$BIN" &
# The scenario is saved under the entry's name, read from its file.
curl -s -H "Authorization: Bearer $ADMIN" "$A/_rustybin/harness/scenarios/checkout"
# A document sent to the API never makes the server read a path: the entry is
# a problem that says to send the scenario inline, as a mock's spec: is.
curl -s -X POST -H "Authorization: Bearer $ADMIN" -H "Content-Type: application/json" \
  -d '{"document": "version: 2\nharness:\n  scenarios:\n    - name: checkout\n      file: scenarios/checkout.yaml\n", "dry_run": true}' \
  "$A/_rustybin/config/apply"

Projects

projects:
  - name: payments
    description: The payments team
    members:
      - { user: pia, roles: [editor] }
mocks:
  - name: payments-api
    project: payments
    spec: specs/payments-api.yaml
tests:
  - name: list-payments
    project: payments
    request: { path: /mock/payments-api/payments }
    assert: [{ status: 200 }]

projects: needs users.manage (a member's roles are a grant), and the rules of PUT /_rustybin/projects/{name} hold: the applying caller gives only roles it holds in the project and never changes its own. A project: naming a project the instance does not have (nor the document creates) is a problem, and the resource stays where it is (a new one is the instance's). A document from the configuration repository creates projects and changes their descriptions, but never changes their members, never prunes a project and never moves an existing mock or test to another project (each is reported in problems and kept as it is).

Export

GET /_rustybin/config/export (admin) answers the instance as YAML. ?format=json gives the same document as JSON; ?secrets=omit leaves the secrets section out and redacts the mocks' demo credentials.

GET {{secured_url}}/_rustybin/config/export
Authorization: Bearer {{admin_token}}
HTTP 200
[Asserts]
header "Content-Type" startsWith "application/yaml"
body contains "version: 2"
body contains "health:"
GET {{secured_url}}/_rustybin/config/export?format=json&secrets=omit
Authorization: Bearer {{admin_token}}
HTTP 200
[Asserts]
jsonpath "$.version" == 2
jsonpath "$.secrets" not exists
jsonpath "$.health.initial" == "healthy"

?format=bundle answers a gzipped tar: rustybin-config/rustybin.yaml with every spec as a file under rustybin-config/specs/ (spec: specs/orders.json), the shape a repository holds and a reviewer diffs. Unpacked, the directory loads with RUSTYBIN_CONFIG_FILE=rustybin-config/rustybin.yaml.

In the console, Management, Export shows the document with Copy, Download and Bundle, the differences since the last export seen in that browser, and Apply a document below.

Apply, with a dry run first

POST /_rustybin/config/apply (admin) takes {document, prune, dry_run}: the document as YAML or JSON text, or as a JSON object. The answer carries the diff computed before anything changed (changes, and summary as lines such as mocks.orders: spec changed (1 operation(s) added), disabled), each section's result under results, and problems (an entry that could not be applied never stops the others; ok is false when there were any).

A dry run answers the same and changes nothing. It validates with the apply's rules: setting kinds and checks, locked settings, secret references, every mock compiled, the portal's metadata, and the instance's capacities, so a document the apply would refuse has ok: false in its preview too. An apply is not one transaction: sections are applied in order (settings, secrets, mocks, registry, portal, harness, tests, test schedules, agents, health), and an entry that fails is reported while the others go ahead, so preview first. An apply (and its dry run) runs on the compile pool, as mock edits do: when the pool stays busy the answer is 503 with Retry-After.

A document pulled from a repository is applied with stricter rules (it cannot repoint outbound requests, the sign-in, a test's gateway or a schedule's webhook); Source control lists them.

POST {{secured_url}}/_rustybin/config/apply
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{
  "document": "version: 2\nhealth: {initial: unhealthy}\nsettings: {agents.default_ceiling: read-only}\n",
  "dry_run": true
}
HTTP 200
[Asserts]
jsonpath "$.dry_run" == true
jsonpath "$.summary" contains "health.initial: changed from \"healthy\" to \"unhealthy\""
jsonpath "$.summary" contains "settings.agents.default_ceiling: added (read-only)"
jsonpath "$.results.settings.set" contains "agents.default_ceiling"

GET {{secured_url}}/health
HTTP 200

Then the same document, applied:

POST {{secured_url}}/_rustybin/config/apply
Authorization: Bearer {{admin_token}}
Content-Type: application/json
{
  "document": "version: 2\nhealth: {initial: unhealthy}\nsettings: {agents.default_ceiling: read-only}\n",
  "prune": false
}
HTTP 200
[Asserts]
jsonpath "$.ok" == true
jsonpath "$.results.health.initial" == "unhealthy"
jsonpath "$.results.settings.changed" contains "agents.default_ceiling"

GET {{secured_url}}/health
HTTP 503

Spec file paths (spec:) are only read next to a local file (RUSTYBIN_CONFIG_FILE, a repository's working copy): a document sent to the API must inline its specs (spec_inline), as rustybin mock push does.

POST /_rustybin/mocks/apply still accepts a version 2 document and applies its mocks section only.

At startup and on reload

RUSTYBIN_CONFIG_FILE loads a version 1 or 2 document before the instance serves its first request and again on SIGHUP or POST /_rustybin/mocks/reload. The mocks, registry entries, portal items and agent rules are the file's (origin: file, the file is the truth for those sections and a reload prunes what it no longer names); the instance, settings, secrets, scenarios and health are applied without pruning. ${VAR} references in the file are expanded from the environment when it is read, so a secret reference becomes the value and is stored sealed. Problems never stop the server: they are logged and listed in GET /_rustybin/mocks (load_errors).

The registry and agents sections applied through the API or a repository are kept in <state>/config.json (with RUSTYBIN_STATE_DIR) and loaded at startup, before the config file, which wins for the sections it carries.

Source control connects an instance to a git repository: commit and push the export, pull and apply the repository's version, and start from the repository with RUSTYBIN_CONFIG_GIT.

On every surface

The same job from the API, the console, the command line, an agent and the configuration document.

SurfaceWhere
APIGET /_rustybin/config/export, POST /_rustybin/config/apply (dry_run, prune), GET /_rustybin/config/schema
ConsoleManagement, Export: the document, copy, download, the bundle, the diff, apply with a dry run
CLIrustybin config export, apply, diff, schema, check (reference)
Management MCPexport_config, diff_config, apply_config; the resource rustybin://config.schema.json; the prompt build_instance ends with an export (agent page)
rustybin.yamlThis page: the document is the surface
EnvironmentRUSTYBIN_CONFIG_FILE (loaded at startup and on reload), RUSTYBIN_STATE_DIR (where applied state persists), RUSTYBIN_SETTINGS_LOCK (configuration)