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¶
- 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,KEYto start with; matched anywhere in the name, any case). To add one, pressTabuntil the patterns table is focused,a, type it (e.g.SECRET$),Enter;ddeletes the highlighted one. -
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. -
Import the variables:
4(Environment variables),i, the same path,Enter. Now the secret names are left out (a secret pattern). A changed variable showsold → new; to keep its current value, highlight it and pressspaceto untick it. Press Import.
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;ereplaces it with a new one.
- 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¶
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).
- Config tab,
4(Environment variables), pressS. The scope line shows Platform in bold, and the status linestate cfg.env on <context>. -
Add a variable:
a, typeREGIONandeu,Enter. A protected context asks once (Set platform variable REGION). -
Add a secret:
5(Secrets),S,a, type the key (alpaca-paper-key: letters, digits,.,_,-) and the value (typed hidden),Enter. - Import a
.envfile: on either page in the Platform scope,iand the path, as for your own entries. On Secrets a key that exists shows as changed withvalue not readable, ticked to be replaced; untick it to keep the current value. The import is one write (Import 3 platform secrets). - 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. - Delete: highlight the row and
d, or mark several (space) andd: 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
setand 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¶
- Config tab,
6(Contexts), pressi, type the path of a TOML file in the contexts.toml format,Enter. -
Read the preview: new contexts, changed ones (with their new endpoint; ticked,
spaceto keep yours), unchanged ones, and Problems: entries withoutname,api_hostorapi_port(left out). -
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_keykeeps 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). - 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.