Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow API token to be retrieved from environment variable #24 #25

Merged
merged 1 commit into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only question here is which token should take precedence, the environment variable or the one in dvconfig.py? (I have not looked at this code very deeply overall, so not necessarily advocating for the switch)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I searched online and it seems standard for environment variable to take precedence.


## 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.
Expand Down
5 changes: 5 additions & 0 deletions create_sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions destroy_all_dvobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions export-api-token.sh
Original file line number Diff line number Diff line change
@@ -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 \"`