Skip to content

Commit

Permalink
Load API key from config
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Izotov committed May 25, 2016
1 parent e2ebe44 commit 17d69d3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
7 changes: 6 additions & 1 deletion st2client/st2client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

class Client(object):
def __init__(self, base_url=None, auth_url=None, api_url=None, api_version=None, cacert=None,
debug=False, token=None):
debug=False, token=None, apikey=None):
# Get CLI options. If not given, then try to get it from the environment.
self.endpoints = dict()

Expand Down Expand Up @@ -79,6 +79,11 @@ def __init__(self, base_url=None, auth_url=None, api_url=None, api_version=None,

self.token = token

if apikey:
os.environ['ST2_API_KEY'] = apikey

self.apikey = apikey

# Instantiate resource managers and assign appropriate API endpoint.
self.managers = dict()
self.managers['Token'] = ResourceManager(
Expand Down
4 changes: 4 additions & 0 deletions st2client/st2client/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
'password': {
'type': 'string',
'default': None
},
'apikey': {
'type': 'string',
'default': None
}
},
'api': {
Expand Down
1 change: 1 addition & 0 deletions st2client/st2client/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
'auth_url': ['auth', 'url'],
'api_url': ['api', 'url'],
'api_version': ['general', 'api_version'],
'apikey': ['credentials', 'apikey'],
'cacert': ['general', 'cacert'],
'debug': ['cli', 'debug']
}
Expand Down
3 changes: 2 additions & 1 deletion st2client/tests/unit/test_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def test_parse(self):
},
'credentials': {
'username': 'test1',
'password': 'test1'
'password': 'test1',
'apikey': None
},
'api': {
'url': 'http://127.0.0.1:9101/v1'
Expand Down

0 comments on commit 17d69d3

Please sign in to comment.