Skip to content

ContextHandling

Alexis Lucattini edited this page Mar 29, 2023 · 6 revisions

Local contexts

The icav2 cli binary uses the ~/.icav2/.session.ica.yaml file to handle project contexts by setting the 'project-id' key.

This can cause conflicts for users working in multiple contexts in separate terminal sessions.

With the icav2 cli plugin we can work around this by masking icav2 projects enter as a function instead.

Help page

Usage: icav2 projects enter [projectname] [--global] [--help]
This command sets the project context for future commands by updating
the ICAV2_PROJECT_ID env var.  If you wish to set the project id globally, please
use the --global parameter

Example:
  icav2 projects enter playground_v2

Parameters:
  -g, --global set project id globally
  -h, --help   help for enter

Enter a context locally

Use the following code to enter a context in your current terminal

icav2 projects enter <project_name>

Enter a context globally

You can still enter contexts globally, as one would with the original icav2 projects enter command.

Use the -g option to enter the context in all terminals.

Note this will NOT affect existing terminals with the env var ICAV2_PROJECT_ID set.

icav2 projects enter -g <project_name>

Autocompletion

You can press <tab> to produce a list of available project contexts

GIF Example

enter_project

Multi Tenancy handling

Tenants Init

Register a tenant with the icav2 cli plugins.

icav2 tenants init <tenant_name>

This command will ask for an api key for the given tenant This stores an api-key under a user-access-only folder in the plugins repository.

This api key is used to generate tokens for this tenant.

Tenants List

List registered tenants

icav2 tenants list

Tenants Enter

Enter a tenant in your terminal.

This will update the ICAV2_ACCESS_TOKEN env var for your terminal.

Use the -g option to enter the context in all terminals and future terminals.

Note this will NOT affect existing terminals with the env var ICAV2_ACCESS_TOKEN set.

icav2 tenants enter <tenant_name>

Tenants Set Default Project

Set the default project to enter when entering a tenant

This will add the project-id key to your tenant folder .session.ica.yaml file.

This will also mean the ICAV2_PROJECT_ID env var is updated when running icav2 tenants enter.

icav2 tenants set-default-project <tenant_name> --project-name <project_name>

Tenants Set Default Tenant

Set the default tenant.

This will overwrite the values in $HOME/.icav2/config.yaml.

This will not affect any existing terminals with the ICAV2_ACCESS_TOKEN env var set.

icav2 tenants set-default-tenant <tenant_name>