Inso CLI configuration

Inso CLI can be configured with a configuration file, allowing you to specify options and scripts. For example, when running in a CI environment, you may choose to specify the steps as scripts in a configuration file, so that the same commands can be run both locally and in CI.

Inso CLI uses cosmiconfig for configuration file management. This automatically uses any of the following items from the working tree:

  • inso property in package.json
  • .insorc file in JSON or YAML format
  • .insorc.json file
  • .insorc.yaml, .insorc.yml, or .insorc.js file
  • inso.configuration.js file exporting a JS object

You can also use the --configuration $FILE global option to specify the file to use.

Inso CLI options

The options field in the configuration file can be used to define global options. You can use any of the global flags in this field. Flags without arguments should be configured as booleans in the configuration file. For example, you can use the following configuration to show additional logs when running all commands:

options:
  verbose: true

Any options specified in this file will apply to all scripts and manual commands. You can override these options by specifying them explicitly when invoking a script or command. The priority order works as follows:

  1. Command options
  2. Configuration file options
  3. Default options

The configuration file doesn’t accept the encryption key. Pass it with an environment variable or a command option instead. For more information, see Encryption key.

Encryption key

v13.5+ Insomnia encrypts sensitive fields, such as passwords, tokens, cookie values, and client certificate secrets, in its local database. Inso CLI needs the Insomnia local encryption key to read these values when both of these conditions are met:

  • Inso CLI reads the Insomnia app’s local database files. These are the .db files in the Insomnia data folder, which Inso CLI uses by default when you don’t set --workingDir.
  • The command uses encrypted values. In practice, this means inso run collection or inso run test on requests that use authentication, cookies, or client certificates.

Most CI/CD pipelines use a Git Sync repository or an exported file, so they don’t need the key. The following table summarizes the cases where Inso needs the encryption key or not:

Data source

Key needed?

Exported file (YAML or JSON) No. Exported files don’t contain encrypted values.
Git Sync repository or .insomnia folder No. Git Sync files don’t contain encrypted values.
inso lint spec or inso export spec No. These commands only read API specs.
inso run collection or inso run test on the Insomnia local database files Yes, if the requests use encrypted values.

Get the key

In Insomnia, go to Preferences > General > Security > Local Encryption Key, then click Copy Key or Export Key. Inso CLI accepts both forms: the text from Copy Key, or the contents of the JSON file from Export Key. For the full steps, see Local encryption key.

Pass the key to Inso CLI

Pass the key with the INSOMNIA_ENCRYPTION_KEY environment variable or the --encryption-key option:

export INSOMNIA_ENCRYPTION_KEY="<copied-key>"
inso run collection wrk_123

To read the key directly from the exported file:

INSOMNIA_ENCRYPTION_KEY="$(cat insomnia-encryption-key.json)" inso run collection wrk_123

To use the option instead:

inso run collection wrk_123 --encryption-key "<copied-key>"

Replace <copied-key> with your key and wrk_123 with your collection ID or name.

Missing or wrong keys

The following table describes how Inso CLI behaves when the key is missing or doesn’t match:

Situation

Behavior

No key, and the database contains encrypted values Inso CLI prints a warning and continues. Requests that need an encrypted value fail, for example with a 401 response, because Inso CLI sends the encrypted text instead of the real value.
Wrong key Inso CLI stops with an error that lists the affected fields, without their values, and exits with a non-zero exit code.
Text that isn’t a valid key Inso CLI stops with an Invalid encryption key error. The error doesn’t include the key text.
Key exported on another machine Inso CLI prints a warning that names both machines before it changes any file, then continues.

Best practices

  • Use the key only on the machine it came from. When Inso CLI has a key, it encrypts any values in the database files that aren’t encrypted yet. If the key belongs to another machine, the Insomnia app on this machine can’t read those values anymore.
  • Treat the key like a password. Anyone with the key can decrypt the values stored in the local database. Don’t commit it to a repository or paste it into shared logs.
  • Close Insomnia before you run Inso CLI on its database files. Inso CLI rewrites the database files it reads, so a change that you save in Insomnia at the same time can be lost.

Request timeout

Use requestTimeout to control how long Inso CLI waits before failing a network request during collection and test execution:

Set the timeout for an individual command:

inso run collection wrk_123 --request-timeout 30000

Configuration file

Inso CLI loads configuration from several supported files. The most common is the .insorc file. Set a default timeout for all Inso CLI commands by adding the timeout option to your .insorc file.

Configuration keys in .insorc follow a simple rule:
start with the flag name, remove --, then convert kebab-case to camelCase.

For the --request-timeout flag, the configuration key becomes requestTimeout:

# .insorc.yaml
options:
  requestTimeout: 30000

Inso CLI scripts

Scripts in the Inso CLI configuration file can have any name and can be nested. Scripts must be prefixed with inso.

Inso CLI configuration example

The following example shows how you can format your Inso CLI configuration file with options and scripts:

# .insorc.yaml

options:
  ci: false
scripts:
  test-spec: inso run test Demo --env DemoEnv --reporter progress
  test-spec:200s: inso testSpec --testNamePattern 200
  test-spec:404s: inso testSpec --testNamePattern 404

  test-math-suites: inso run test uts_8783c30a24b24e9a851d96cce48bd1f2 --env DemoEnv 
  test-request-suite: inso run test uts_bce4af --env DemoEnv --bail

  lint: inso lint spec Demo # must be invoked as `inso script lint`

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!