Environment Variables
The command-line client and the client bindings use a set of environment variables in order to communicate with the API server and to store state on the current default project and directory. These settings are usually set when you run dx login and can be later changed through other dx commands. To display the currently used settings in human-readable format, you can use the dx env command:
1
$ dx env
2
Auth token used adLTkSNkjxoAerREqbB1dVkspQzCOuug
3
API server protocol https
4
API server host api.dnanexus.com
5
API server port 443
6
Current workspace project-9zVpbQf4Zg2641v5BGY00001
7
Current workspace name "Scratch Project"
8
Current folder /
9
Current user alice
Copied!
To print the bash commands for setting the environment variables to match what dx is using, you can run the same command with the --bash flag.
1
$ dx env --bash
2
export DX_SECURITY_CONTEXT='{"auth_token_type": "bearer", "auth_token": "adLTkSNkjxoAerREqbB1dVkspQzCOuug"}'
3
export DX_APISERVER_PROTOCOL=https
4
export DX_APISERVER_HOST=api.dnanexus.com
5
export DX_APISERVER_PORT=443
6
export DX_PROJECT_CONTEXT_ID=project-9zVpbQf4Zg2641v5BGY00001
Copied!
Running a dx command from the command-line will not (and cannot) overwrite your shell's environment variables, so it stores them in a file at ~/.dnanexus_config/environment.

Configuration File Prioritization

The following is an ordered list of which DNAnexus utilities load values from configuration sources:
    1.
    Command line options (if available)
    2.
    Environment variables already set in the shell
    3.
    ~/.dnanexus_config/environment.json (dx configuration file)
    4.
    Hardcoded defaults

Overriding the dx Configuration File

Note that the dx command will always prioritize the environment variables that are currently set in the shell. This means that if you have set your environment variable for DX_SECURITY_CONTEXT and subsequently use dx login to log in as a different user, it will still use the original environment variable. If not run in a script, it will print a warning to stderr whenever the environment variables and its stored state have a mismatch. To get out of this situation, the best approach is often to run source ~/.dnanexus_config/unsetenv. Setting environment variables is generally an approach within a shell script or part of a job environment in the cloud.
In the interaction below, environment variables have already been set, but the user then uses dx to log in which is still overridden by the shell's environment variables.
1
$ dx ls -l
2
Project: Sample Project (project-9zVpbQf4Zg2641v5BGY00001)
3
Folder : /
4
<Contents of Sample Project>
5
$ dx login
6
Acquiring credentials from https://auth.dnanexus.com
7
Username: alice
8
Password:
9
10
Note: Use "dx select --level VIEW" or "dx select --public" to select from
11
projects for which you only have VIEW permissions.
12
13
Available projects:
14
0) SAM importer test (CONTRIBUTE)
15
1) Scratch Project (ADMINISTER)
16
2) Mouse (ADMINISTER)
17
18
Pick a numbered choice [1]: 2
19
Setting current project to: Mouse
20
$ dx ls
21
WARNING: The following environment variables were found to be different than the
22
values last stored by dx: DX_SECURITY_CONTEXT, DX_PROJECT_CONTEXT_ID
23
To use the values stored by dx, unset the environment variables in your shell by
24
running "source ~/.dnanexus_config/unsetenv". To clear the dx-stored values,
25
run "dx clearenv".
26
Project: Sample Project (project-9zVpbQf4Zg2641v5BGY00001)
27
Folder : /
28
<Contents of Sample Project>
29
$ source ~/.dnanexus_config/unsetenv
30
$ dx ls -l
31
Project: Mouse (project-9zVpbQf4Zg2641v5BGY00001)
32
Folder : /
33
<Contents of Mouse>
Copied!

Clearing dx-set variables

If you instead want to discard the values which dx has stored, the command dx clearenv removes the dx-generated configuration file ~/.dnanexus_config/environment.json for you.

Command line options

Most dx commands have the following additional flags to temporarily override the values of the respective variables.
1
$ dx --env-help
2
usage: dx command ... [--apiserver-host APISERVER_HOST]
3
[--apiserver-port APISERVER_PORT]
4
[--apiserver-protocol APISERVER_PROTOCOL]
5
[--project-context-id PROJECT_CONTEXT_ID]
6
[--workspace-id WORKSPACE_ID]
7
[--security-context SECURITY_CONTEXT]
8
[--auth-token AUTH_TOKEN]
9
10
optional arguments:
11
--apiserver-host APISERVER_HOST
12
API server host
13
--apiserver-port APISERVER_PORT
14
API server port
15
--apiserver-protocol APISERVER_PROTOCOL
16
API server protocol (http or https)
17
--project-context-id PROJECT_CONTEXT_ID
18
Default project or project context ID
19
--workspace-id WORKSPACE_ID
20
Workspace ID (for jobs only)
21
--security-context SECURITY_CONTEXT
22
JSON string of security context
23
--auth-token AUTH_TOKEN
24
Authentication token
Copied!
For example, you can temporarily override the current default project used:
1
$ dx env --project-context-id project-B0VK6F6gpqG6z7JGkbqQ000Q
2
Auth token used R54BN6Ws6Zl3Y0VqBA9o1qweUswYW5o4
3
API server protocol https
4
API server host api.dnanexus.com
5
API server port 443
6
Current workspace project-B0VK6F6gpqG6z7JGkbqQ000Q
7
Current folder /
Copied!
Last modified 2yr ago