Contexts
Save the URL and API key of each Spica instance as a named context, and switch between local, staging and production.
A context is a named connection: the API URL of an instance and the API key the CLI uses for it. Every command that talks to an instance (fetch, plan, apply, dev, bucket orm, function orm, asset) uses the current context.
Create a key for the CLI
In the panel, open Access Management → API Keys, create a key, and attach the full-access policies of the modules you manage with the CLI: BucketFullAccess, FunctionFullAccess, PolicyFullAccess, EnvVarFullAccess and SecretFullAccess.
Add and select a context
spica context set --name local --url http://localhost:4500/api --apikey <key>
spica context switch localContext has been changed to "local".context set creates or updates a context. It doesn't select it, so run context switch afterwards.
| Option | Description |
|---|---|
--name | Name of the context. |
--url | Required. Public URL of the API, including /api when the API is served under that path. |
-a, --apikey | Required. The API key. |
List and remove contexts
spica context lsNAME URL AUTHORIZATION
local http://localhost:4500/api * * * * * * * * * *
production https://api.example.com/api * * * * * * * * * *spica context remove productionWhere contexts are stored
Contexts are saved in ~/.spicactx as JSON, with the key in plain text:
{"local": {"url": "http://localhost:4500/api", "authorization": "APIKEY 4yVYTsoIdIBETPoFn2jXoDY72i46L5I6"}}Keep that file private. In CI, create the context from secrets at the start of the job:
spica context set --name ci --url "$SPICA_URL" --apikey "$SPICA_API_KEY"
spica context switch ciGuarding production
To avoid running plan or apply from the wrong folder, restrict them with a guard.