External variables and TLAs see history edit this page

Talks about: , , and

JaaS feeds two kinds of input into an evaluation: external variables, set by the process owner at startup, and top-level arguments, supplied per request through the URL query string.

External variables

External variables come from two sources. The environment mechanism reads every variable prefixed with JAAS_EXT_VAR_ — the suffix is the variable name:

JAAS_EXT_VAR_name=Alice \
JAAS_EXT_VAR_key=secret \
  ./jaas --snippet-directory examples/snippets/dashboards

The --ext-var KEY=VALUE flag does the same and is repeatable. On a key conflict, the flag takes precedence over the environment value:

./jaas \
  --snippet-directory examples/snippets/dashboards \
  --ext-var name=Alice \
  --ext-var key=secret

A snippet reads a variable with std.extVar:

{
  person1: {
    name: std.extVar('name'),
    external: std.extVar('key'),
  },
}

Fetching example1 with those variables set produces:

curl http://127.0.0.1:8080/jsonnet/example1
{
  "person1": {
    "external": "secret",
    "name": "Alice",
    "welcome": "Hello Alice!"
  }
}

External variables are fixed at startup. Callers cannot set them per request — that is what top-level arguments are for.

Top-level arguments

A snippet that evaluates to a function receives top-level arguments (TLAs) from the URL query string. The tla-example snippet is such a function:

function(something="value", other="more", required)
  {
    person1: {
      welcome: 'Hello ' + something + '!',
      key: other,
      required: std.parseJson(required),
    },
  }

Each query parameter sets a TLA. A single value becomes a string:

curl 'http://127.0.0.1:8080/jsonnet/tla-example?something=Ada&required=42'
# {"person1":{"key":"more","required":42,"welcome":"Hello Ada!"},...}

A repeated parameter becomes a list. The multi-tla snippet joins whatever it receives:

function(tags=["default"])
  {
    count: std.length(tags),
    list: tags,
    joined: std.join(", ", tags),
  }
curl 'http://127.0.0.1:8080/jsonnet/multi-tla?tags=blue&tags=green'
# {"count":2,"joined":"blue, green","list":["blue","green"]}

A bare parameter with no value sets the TLA to an empty string:

curl 'http://127.0.0.1:8080/jsonnet/tla-example?something&required=0'

For the request and response shape these examples ride on, see the rendering endpoint .