Skip to content

Manage environment variables and secrets; import contexts

Goal: keep the settings and keys your scripts need in the TUI (from a .env file or one by one), set the platform variables and secrets a context's workers use, and add contexts from a contexts.toml someone gave you.

Prerequisites

  • Nothing on a context: these pages are your own files and work without an active context. Variables go to ~/.config/virtufin/tui/env.toml, secrets to ~/.config/virtufin/tui/secrets.toml, contexts to ~/.config/virtufin/api/contexts.toml (each owner read and write only).
  • For an import: the file's path on this machine (~ works).

These are your personal entries, for your scripts. For the active context's platform entries, which workers use, see Set platform variables and secrets.

Import a .env file

  1. Check the secret patterns: Config tab, 5 (Secrets). The Secret patterns table under the secrets lists the regular expressions that make a name a secret (TOKEN, KEY to start with; matched anywhere in the name, any case). To add one, press Tab until the patterns table is focused, a, type it (e.g. SECRET$), Enter; d deletes the highlighted one.
  2. Import the secrets: still on Secrets, press i, type the path (~/project/.env), Enter. The preview lists the names matching a pattern as new, changed or unchanged, names only, and the others as left out (not a secret pattern). Press Import.

    The import preview on Secrets: two new secrets, the other names left out

  3. Import the variables: 4 (Environment variables), i, the same path, Enter. Now the secret names are left out (a secret pattern). A changed variable shows old → new; to keep its current value, highlight it and press space to untick it. Press Import.

    The import preview on Environment variables: the secret names left out

What you should see

  • Environment variables: each name with its value.
  • Secrets: each name with … and its last four characters, and when it was set. The value itself is never shown again; e replaces it with a new one.

Secrets after the import: each with its last four characters

  • A toast Imported N variables, kept M (or secrets).

Add, edit and delete one by one

Do Keys
Add a, type the name and the value, Enter
Change a value highlight the row, e, type the new value, Enter
Delete one highlight it, d, Confirm
Delete several space on each (or b for all), then d (or m › Delete), confirm once

A name is one kind only: adding a variable BINANCE_KEY while a secret BINANCE_KEY exists is refused (BINANCE_KEY is already a secret).

Use them in a script

from virtufin_tui import vf

region = vf.env("REGION")
key = vf.secret("BINANCE_KEY")

See Scripts.

Set platform variables and secrets

Prerequisites: an active context, and being an admin of it (on a protected context each change asks first).

  1. Config tab, 4 (Environment variables), press S. The scope line shows Platform in bold, and the status line state cfg.env on <context>.
  2. Add a variable: a, type REGION and eu, Enter. A protected context asks once (Set platform variable REGION).

    The Platform scope of Environment variables: adding a variable

  3. Add a secret: 5 (Secrets), S, a, type the key (alpaca-paper-key: letters, digits, ., _, -) and the value (typed hidden), Enter.

  4. Import a .env file: on either page in the Platform scope, i and the path, as for your own entries. On Secrets a key that exists shows as changed with value not readable, ticked to be replaced; untick it to keep the current value. The import is one write (Import 3 platform secrets).
  5. Use them in a worker: the New Worker form (Infra › Workers, a) asks for each secret and platform variable reference the worker type declares; enter the key or the name, never the value.
  6. Delete: highlight the row and d, or mark several (space) and d: one write. A platform secret asks you to type its key (for several, their number) before it is deleted: its value cannot be read back and every worker that uses it fails.

What you should see

  • Environment variables (Platform): each name with its value.
  • Secrets (Platform): each key with set and when it was set, never the value.
  • Changes (Infra): one entry per change, naming the keys.

A worker gets a changed variable at its next start (stop and start it); a changed secret on its next event.

Import contexts

  1. Config tab, 6 (Contexts), press i, type the path of a TOML file in the contexts.toml format, Enter.
  2. Read the preview: new contexts, changed ones (with their new endpoint; ticked, space to keep yours), unchanged ones, and Problems: entries without name, api_host or api_port (left out).

    The contexts import preview: one new context

  3. Press Import. New contexts are added after yours, a changed one is updated in place, and the file keeps its comments. An imported context without api_key keeps the key you have. The table shows the result at once, with each context's status glyph (● its api answers, ✖ it does not, with why).

  4. To use one, highlight it and press Enter (Switch context).

Troubleshooting

Symptom Cause and fix
API_KEY on lines 1 and 3 The .env file gives a name twice: remove one and import again.
(unclosed is not a regular expression: ... A secret pattern must be a valid regular expression; fix it and add it again.
A name you expected is left out as not a valid name Names are letters, digits and _, not starting with a digit.
... is in use: switch to another first The active context cannot be deleted; switch, then delete it.
not valid TOML The contexts file does not parse; the toast names the line.
the gateway does not know the Secrets service yet; try again in a few minutes The WorkManager was just upgraded and the gateway still caches its old descriptors (up to an hour). Press S twice later to read again.
The Platform scope needs an active context Switch to a context first (Switch context).
... is already a secret: a name is one kind only A platform variable and a platform secret cannot share a name.

Reference: Views › Config tab.