Skip to content

Commit 8d705f0

Browse files
authored
Merge pull request #25 from IQSS/24-api-token-env-var
allow API token to be retrieved from environment variable #24
2 parents dcd0615 + 7adcc28 commit 8d705f0

4 files changed

Lines changed: 16 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Copy `dvconfig.py.sample` to `dvconfig.py` (see the `cp` command below) and add
3333
cp dvconfig.py.sample dvconfig.py
3434
vi dvconfig.py
3535

36+
Note that the environment variable `$API_TOKEN` will override `api_token` in `dvconfig.py`.
37+
3638
## Adding sample data
3739

3840
Assuming you have already run the `source` and `cd` commands above, you should be able to run the following command to create sample data.

create_sample_data.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
from io import StringIO
88
base_url = dvconfig.base_url
99
api_token = dvconfig.api_token
10+
try:
11+
api_token=os.environ['API_TOKEN']
12+
print("Using API token from $API_TOKEN.")
13+
except:
14+
print("Using API token from config file.")
1015
paths = dvconfig.sample_data
1116
api = Api(base_url, api_token)
1217
print(api.status)

destroy_all_dvobjects.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22
import json
33
import dvconfig
44
import requests
5+
import os
56
base_url = dvconfig.base_url
67
api_token = dvconfig.api_token
8+
try:
9+
api_token=os.environ['API_TOKEN']
10+
print("Using API token from $API_TOKEN.")
11+
except:
12+
print("Using API token from config file.")
713
api = Api(base_url, api_token)
814
print('API status: ' +api.status)
915

export-api-token.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
# source this file
3+
export API_TOKEN=`cat /tmp/setup-all.sh.out | grep apiToken | jq .data.apiToken | tr -d \"`

0 commit comments

Comments
 (0)