diff options
author | ABond <ajbond2005@gmail.com> | 2017-09-06 10:14:10 -0400 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2017-09-06 07:14:10 -0700 |
commit | 082f54eaf4c566f6862cf58f3dc05cf6a024f231 (patch) | |
tree | ceb9f8ab17aa5fdcae084f63a473c4646652ed63 /lib | |
parent | 0ddbcf884139ea3deb194035a799495eecebb6f3 (diff) | |
download | ansible-082f54eaf4c566f6862cf58f3dc05cf6a024f231.tar.gz |
Fix digital_ocean module_util api_token bug (#28924)
* Fix digital_ocean module_util api_token bug
* Included environment variables also
* Removed try/catch and added a check on self.oauth_token
Modules using the DigitalOceanHelper would expect the module to handle any api key resolution.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ansible/module_utils/digital_ocean.py | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/ansible/module_utils/digital_ocean.py b/lib/ansible/module_utils/digital_ocean.py index 564a7df296..2cf1443d9a 100644 --- a/lib/ansible/module_utils/digital_ocean.py +++ b/lib/ansible/module_utils/digital_ocean.py @@ -92,11 +92,10 @@ class DigitalOceanHelper: return self.send('DELETE', path, data) def get_do_oauth_token(self): - try: - self.oauth_token = self.module.params['oauth_token'] or \ - self.module.params['api_token'] or \ - os.environ['DO_API_TOKEN'] or \ - os.environ['DO_API_KEY'] or \ - os.environ['OAUTH_TOKEN'] - except KeyError as e: - self.module.fail_json(msg='Unable to load %s' % e.message) + self.oauth_token = self.module.params.get('oauth_token') or \ + self.module.params.get('api_token') or \ + os.environ.get('DO_API_TOKEN') or \ + os.environ.get('DO_API_KEY') or \ + os.environ.get('OAUTH_TOKEN') + if self.oauth_token is None: + self.module.fail_json(msg='Unable to load api key: oauth_token') |