API Keys¶
Squirrel connects to a Canopy server, and every request it makes carries an API key. The key decides what you can do: a key with read access can browse snapshots and PVs, and one with write access can also save snapshots, restore them, and change PVs and tags.
Keys are created by whoever runs Canopy; see API keys in the Canopy documentation. A key used by Squirrel must be allowed to use the squirrel and hare modules, and elog to post to the e-log; see E-log Access.
Setting Your API Key¶
In the desktop app, each user enters a key once per instance:
- When the app has no key, a banner at the top says NO API KEY CONFIGURED.
- Click Set API Key.
- Paste the key and click Save.
The key is stored for your account only, and is kept across app updates. To change it later, use the same banner, or ask your administrator for a shared key (below).
E-log Access¶
Post to Elog (on a snapshot's detail page) is served by Canopy's elog module, which posts to the
e-log with Squirrel's own application token, so no e-log credentials ever reach the app. The key Squirrel
uses must be allowed to use that module. On the Canopy server this means the key's entry lists elog
alongside squirrel, with write access for posting, for example
<token>:read+write@squirrel+elog.
If the key lacks the elog scope, the button still appears but the dialog reports
"This API key isn't allowed to use the e-log module." Ask the Canopy administrator to add the
scope. If the button is missing altogether, the server reports e-log as disabled for Squirrel (no provider
configured, or no token for Squirrel); the reason is written to the app's console.
Shared Key for the Desktop App¶
By default, the desktop (Tauri) app stores the API key it uses per OS user, so
every account on a shared machine has to enter a key once. To provision a
single key for all users, an administrator can add an apiKey field to the
instance entry in config.json:
{
"instances": {
"group-a": {
"apiUrl": "http://group-a.example.edu:8080",
"apiKey": "<shared key>"
}
}
}
With a key provisioned this way, users are not prompted for a key on first
launch. A key entered manually in the app's settings is stored per-user and
takes precedence over the config.json key for that user.
Site config location¶
The app looks for config.json in two places, in order:
- The file named by the
SQUIRREL_CONFIGenvironment variable — the recommended location for deployed installations. Each site keeps its own file at a stable, admin-owned path and points the variable at it from its launch script, e.g.:
Because this file lives outside the versioned application directory, it survives application upgrades and re-deploys unchanged. SLAC's deployment and site config are documented internally.
- The
config.jsonbundled with the application (in the app's resource directory, alongside the executable). Release builds bundle a neutral config that lists onlycanopy-local(http://localhost:8080), and it is replaced on every deploy, so a deployed site needs its own site config.
Note — the config file is readable by every account that can read its path. Only provision a shared key where that is acceptable; use file permissions (e.g.
chmod 640with a shared group) to narrow the audience if needed.
API Key Error Banner¶
In the desktop app, a banner appears at the top of the page when there is a problem with your key:
- NO API KEY CONFIGURED — No key has been entered for this instance, and none is provided by the site config.
- API KEY INVALID OR EXPIRED — The server rejected a request: the key is unknown, deactivated, or doesn't allow what you tried to do.
Click Set API Key to enter a different key. Saving it reconnects straight away; you don't need to restart the app.
In a Web Browser¶
When Squirrel runs in a web browser instead of the desktop app, there is no banner and no way to enter a key in the app (#227). The key comes from wherever the page is served:
- In development, the Vite dev server adds the key from
API_KEYin.env.localto every request; see Local Setup. - Otherwise, from the instance's
apiKeyin aconfig.jsonserved alongside the page, if there is one.
If the key is missing or rejected, requests fail and pages show an error such as Error: API key is missing or invalid. Fix the key at its source and reload the page.