In addition to using configuration files, cmemc can be widely configured and parameterised with environment variables.
Typical use cases why you should want this includes:
- 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 laying around in a file,
There are two major categories of exploitable environment variables.
Environment variables for configuration¤
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:
When you combine file based and environment based configuration, the config file always overwrite the environment.
Environment variables for parameter or options¤
The general pattern for parameter and option settings via environment variables is:
- all variables start with the prefix
- command group and command follow the prefix uppercased and separated by
- finally, the option is uppercased at the end.
- The naming scheme is:
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:
As a next step, we exchange all connection parameter with environment variables:
This alone allows us to save a lot of typing for a series of commands on the same Corporate Memory instance.
But you also can pre-define command options in the same way:
Again, the same command but –raw is set default.
Example: enable session wide debugging output¤
Since there is a top level
--debug option, the corresponding variable name is
Configuration environment export from the config file¤
Beginning with v21.11, cmemc can export a configuration environment from a configuration file to setup an environment for later use with the
config eval command.
$ cmemc -c my-cmem.example.org config eval export CMEM_BASE_URI="https://my-cmem.example.org" export DI_API_ENDPOINT="https://my-cmem.example.org/dataintegration" export DP_API_ENDPOINT="https://my-cmem.example.org/dataplatform" unset OAUTH_ACCESS_TOKEN export OAUTH_CLIENT_ID="cmem-service-account" export OAUTH_CLIENT_SECRET="..." export OAUTH_GRANT_TYPE="client_credentials" unset OAUTH_PASSWORD export OAUTH_TOKEN_URI="https://my-cmem.example.org/auth/realms/cmem/protocol/openid-connect/token" unset OAUTH_USER 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:
Please note that the following command has the same effect but needs the cmemc.ini for evaluating the config values for the config section my-cmem.example.org: