Skip to main content

Contexts

✨New in wash v0.7.0

wash communicates to a wasmCloud host over 2 different NATS connections: the remote procedure call (RPC) connection and the control interface connection.

As of wasmCloud v0.50.2, a host configuration file is written to $HOME/.wash/host_config.json with the last values used to configure and run a host on your machine. wash uses that file by default to create a host_config context that is managed for you. The end result of this is that wash is automatically configured to connect to your recently-launched wasmCloud host with no configuration changes needed.

Using the host_config context

Let's take a look at a context. If you haven't already, try going through the installation page through the end so that you've launched a wasmCloud host. Once you've completed that, a host_config.json file is created in the folder that you ran the host. Keep track of this file as we'll make a modification to it later.

Next, run this command:

wash ctx list

You'll get output like the following:

== Contexts found in /home/YOUR_NAME/.wash/contexts ==
host_config (default)

Let's take a look at that context. You can use the built-in wash ctx edit command to interactively select the context and open it in your editor of choice, but to make it look a little nicer we'll read it and use a JSON formatter. You may need to install jq if you're on a Unix machine.

cat $HOME/.wash/contexts/host_config.json | jq
{
"name": "host_config",
"cluster_seed": "SCAAXUXZNTS6SG5EMMR6WRTLQ3HU5A6RQH67YI7WGS3WCZYYYFWHM45WG4",
"ctl_host": "127.0.0.1",
"ctl_port": 4222,
"ctl_jwt": "",
"ctl_seed": "",
"ctl_credsfile": null,
"ctl_timeout": 2,
"ctl_lattice_prefix": "default",
"rpc_host": "127.0.0.1",
"rpc_port": 4222,
"rpc_jwt": "",
"rpc_seed": "",
"rpc_credsfile": null,
"rpc_timeout": 2000,
"rpc_lattice_prefix": "default"
}
caution

The cluster_seed value here is a secret key and should not be shared. For development purposes this is an autogenerated key and is generally discarded, but keep this in mind when configuring your hosts and editing contexts.

This context contains our reasonable-defaults values of connecting to NATS locally, over the default lattice prefix, with anonymous authentication. Whenever you change the configuration that you use to launch a host, whether it's connecting to a different port for NATS or introducing authentication with a user seed; the host_config file is written to $HOME/.wash/host_config.json and automatically changes the host_config context in wash during your next control interface command or remote procedure call.

Creating your own context

If you'd like to use contexts to manage connections to multiple local lattices, you can create your own context. You can do that in one of two ways:

# Create a context with specified name and default values
wash ctx new ctx_tutorial
# Create a context interactively with terminal prompts
wash ctx new --interactive

Once created, you can use the edit subcommand to easily edit those contexts. wash attempts to use the terminal editor defined in your environment as EDITOR, but will also accept an argument for your favorite terminal editor.

wash ctx edit --editor vim ctx_tutorial

We specified a context above, but if you omit that argument then you'll be interactively prompted to select a context. You can go ahead and edit your context to change any connection parameters, or perhaps a cluster seed, and once you're finished editing you can save and quit your editor (hopefully we aren't locking you into vim here if this is your first time. :wq writes and quits.) After you're finished editing, use wash ctx default to change the default context to your new context, and wash will automatically use that context's values for your next control interface command or remote procedure call.