banshee is under active development: collectors will keep changing, and a version you publish will likely need adjustments. For stable use, wait for version 1.0.0.

Examples

banshee/examples-collection/examples/api/

consul-key

Example: url.encode and base64.decode; the value of a key of Consul.

  • example
  • api
  • consul
  • base64
  • encoding
  • http

by banshee1 installation1 version

v1Latest

Published on October 27, 2026. First version in this collection.

Keen 1.0.0 · 33 lines
// A key of the key/value store of Consul: its name goes into the address, each part written by
// url.encode; its value comes back in base64, read by base64.decode.
need('protocol:http');

$base = variable('example:consul:url', 'text', array(
    'label' => 'Address of Consul',
    'help'  => 'For example https://consul.example:8501.',
));
$key = variable('example:consul:key', 'text', array(
    'label' => 'Key',
    'help'  => 'For example maintenance/web front.',
));

output('value', 'text', array('label' => 'Value of the key'));

watch.expect('flag', 'Unexpected value', 'value', array('warning' => array('off')));

// "maintenance/web front" becomes "maintenance/web%20front": each part encoded, the / kept between them.
$parts = array();
foreach (text.split($key, '/') as $part) {
    $parts = list.add($parts, url.encode($part));
}
$answer = http.get($base . '/v1/kv/' . text.join($parts, '/'));
if ($answer['status'] == 404) {
    fail('misconfigured', 'No key ' . $key . ' in Consul');
}
if ($answer['status'] != 200) {
    fail('unreachable', 'Consul answers ' . $answer['status']);
}

// [{"Key": "maintenance/web front", "Value": "b2Zm", ...}]: a list of one entry, its value in base64.
$entries = json.read($answer['body']);
value('value', base64.decode($entries[0]['Value']));