diff --git a/README.md b/README.md index cfc3ac9..4982518 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ Copy `dvconfig.py.sample` to `dvconfig.py` (see the `cp` command below) and add cp dvconfig.py.sample dvconfig.py vi dvconfig.py +Note that the environment variable `$API_TOKEN` will override `api_token` in `dvconfig.py`. + ## Adding sample data Assuming you have already run the `source` and `cd` commands above, you should be able to run the following command to create sample data. diff --git a/create_sample_data.py b/create_sample_data.py index 6664171..d0dce43 100644 --- a/create_sample_data.py +++ b/create_sample_data.py @@ -7,6 +7,11 @@ from io import StringIO base_url = dvconfig.base_url api_token = dvconfig.api_token +try: + api_token=os.environ['API_TOKEN'] + print("Using API token from $API_TOKEN.") +except: + print("Using API token from config file.") paths = dvconfig.sample_data api = Api(base_url, api_token) print(api.status) diff --git a/destroy_all_dvobjects.py b/destroy_all_dvobjects.py index 6094e30..29631f6 100644 --- a/destroy_all_dvobjects.py +++ b/destroy_all_dvobjects.py @@ -2,8 +2,14 @@ import json import dvconfig import requests +import os base_url = dvconfig.base_url api_token = dvconfig.api_token +try: + api_token=os.environ['API_TOKEN'] + print("Using API token from $API_TOKEN.") +except: + print("Using API token from config file.") api = Api(base_url, api_token) print('API status: ' +api.status) diff --git a/export-api-token.sh b/export-api-token.sh new file mode 100755 index 0000000..03fefce --- /dev/null +++ b/export-api-token.sh @@ -0,0 +1,3 @@ +#!/bin/sh +# source this file +export API_TOKEN=`cat /tmp/setup-all.sh.out | grep apiToken | jq .data.apiToken | tr -d \"`