cmemc can be widely configured and parameterised with environment variables.

Typical use cases why you should want this include:

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

There are two major categories of exploitable environment variables.

Variables which replace and set everything which can be added to a cmemc config file

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

The following commands provide the same result as given in the basic example here:

user@ubuntu:/home/user/$ export CMEM_BASE_URI=http://localhost/
user@ubuntu:/home/user/$ export OAUTH_GRANT_TYPE=client_credentials
user@ubuntu:/home/user/$ export OAUTH_CLIENT_ID=cmem-service-account
user@ubuntu:/home/user/$ export OAUTH_CLIENT_SECRET=c9c12831-000c-464b-9b1d-2d8b7e20df6a

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

Variables which set / change or replace values, which can be otherwise given as parameter or options

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

  • all variables start with the prefix CMEMC_ ,
  • eventually, command group and command follow the prefix uppercased and separated by _ ,
  • finally, the option is uppercased 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

To give an example, we first run a cmemc command via command line parameter:

This command gets the named graph information from the API and outputs the raw JSON.

user@ubuntu:/home/user/$ cmemc --config-file cmemc.ini --connection mycmem graph list --raw
[{u'writeable': True, u'iri': u''}, more JSON output]

As a next step, we exchange all connection parameter with environment variables:

user@ubuntu:/home/user/$ export CMEMC_CONFIG_FILE=cmemc.ini
user@ubuntu:/home/user/$ 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.

Same command but uses environment variables for the connection and the config location.

user@ubuntu:/home/user/$ cmemc graph list --raw
[... same output as above ...]

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

user@ubuntu:/home/user/$ export CMEMC_GRAPH_LIST_RAW=true

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

user@ubuntu:/home/user/$ cmemc graph list
[... same output as above ...]

Example: enable session wide debugging output

Since there is a –debug option, the corresponding variable name is CMEMC_DEBUG:

user@ubuntu:/home/user/$ export CMEMC_DEBUG=true