Skip to content

Environment-based Configuration¤


In addition to using configuration files, cmemc can also be widely configured and parameterized with environment variables.

Typical use cases for when you may want to do this include:

  • set a default connection (see below)
  • enable session-wide debugging output
  • control cmemc with variables from a calling process
  • avoid having client and user credentials lying around in a file

There are two major categories of environment variables you can use.

Environment variables for configuration¤

For these variables the rules are simple: You can use any variable from the config file in the same way as an environment variable.

The following commands provide the same result as given in the basic example for a config file:

$ export CMEM_BASE_URI=http://localhost/
$ export OAUTH_GRANT_TYPE=client_credentials
$ export OAUTH_CLIENT_ID=cmem-service-account


When you combine file-based and environment-based configuration, the config file always overwrites the environment.

Environment variables for parameters or options¤

The general pattern for parameter and option settings via environment variables is:

  • all variables start with the prefix CMEMC_
  • command group and command follow the prefix in uppercase and separated by _
  • the option is in uppercase at the end.
  • The naming scheme is: CMEM[_<COMMAND-GROUP>_<COMMAND>][_<OPTION>]

The next sections demonstrate this pattern with examples.

Example: Set a default connection¤

We first run a cmemc command via command line parameter:

$ cmemc --config-file cmemc.ini --connection mycmem graph list --raw
    "iri": "urn:elds-backend-access-conditions-graph",
... more JSON output ...

As a next step, we replace all connection parameters with environment variables:

$ export CMEMC_CONFIG_FILE=cmemc.ini
$ export CMEMC_CONNECTION=mycmem

This alone allows us to save a lot of typing for a series of commands on the same Corporate Memory instance.

$ cmemc graph list --raw
[... same output as above ...]

However, you can also pre-define command options in the same way:

$ export CMEMC_GRAPH_LIST_RAW=true

Again, the same command but --raw is set per default.

$ cmemc graph list
[... same output as above ...]

Example: enable session wide debugging output¤

Since there is a top level --debug option, the corresponding variable name is CMEMC_DEBUG:

$ export CMEMC_DEBUG=true

Configuration environment export from the config file¤

Beginning with v21.11, cmemc can export a configuration environment from a configuration file to set up an environment for later use with the config eval command.

$ cmemc -c config eval
export CMEM_BASE_URI=""
export OAUTH_CLIENT_ID="cmem-service-account"
export OAUTH_GRANT_TYPE="client_credentials"
export REQUESTS_CA_BUNDLE=".../certifi/cacert.pem"
export SSL_VERIFY="True"

This can be used to export a full config.env or to eval it in an environment for other processes:

$ cmemc -c config eval > config.env
$ eval $(cmemc -c config eval)

Please note that the following command has the same effect but needs the cmemc.ini for evaluating the config values for the config section