Fix DO_API_KEY environment variable check (#33512)

`os.environ['DO_API_TOKEN']` raised a `KeyError` preventing the check
for `os.environ['DO_API_KEY]` from being executed. Fix this by failing
only if the api token isn't set.
pull/26062/merge
Gurchet Rai 7 years ago committed by ansibot
parent be5d68f3ad
commit 490dc40203

@ -201,7 +201,7 @@ try:
except ImportError:
pass
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.basic import AnsibleModule, env_fallback
class TimeoutError(Exception):
@ -346,11 +346,7 @@ def core(module):
module.fail_json(msg='Unable to load %s' % k)
return v
try:
api_token = module.params['api_token'] or os.environ['DO_API_TOKEN'] or os.environ['DO_API_KEY']
except KeyError as e:
module.fail_json(msg='Unable to load %s' % e.message)
api_token = module.params['api_token']
changed = True
command = module.params['command']
state = module.params['state']
@ -432,7 +428,11 @@ def main():
argument_spec=dict(
command=dict(choices=['droplet', 'ssh'], default='droplet'),
state=dict(choices=['active', 'present', 'absent', 'deleted'], default='present'),
api_token=dict(aliases=['API_TOKEN'], no_log=True),
api_token=dict(
aliases=['API_TOKEN'],
no_log=True,
fallback=(env_fallback, ['DO_API_TOKEN', 'DO_API_KEY'])
),
name=dict(type='str'),
size_id=dict(),
image_id=dict(),

Loading…
Cancel
Save