mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-21 04:10:23 -07:00
hashi_vault: fix token logic
The token should not be set and checked twice, especially when the second time overrides a previously set token.
This commit is contained in:
parent
9d85d81ed0
commit
9c72d478ec
1 changed files with 10 additions and 13 deletions
|
@ -55,18 +55,6 @@ class HashiVault:
|
||||||
|
|
||||||
self.url = kwargs.get('url', ANSIBLE_HASHI_VAULT_ADDR)
|
self.url = kwargs.get('url', ANSIBLE_HASHI_VAULT_ADDR)
|
||||||
|
|
||||||
self.token = kwargs.get('token', os.environ.get('VAULT_TOKEN', None))
|
|
||||||
if self.token is None and os.environ.get('HOME'):
|
|
||||||
token_filename = os.path.join(
|
|
||||||
os.environ.get('HOME'),
|
|
||||||
'.vault-token'
|
|
||||||
)
|
|
||||||
if os.path.exists(token_filename):
|
|
||||||
with open(token_filename) as token_file:
|
|
||||||
self.token = token_file.read().strip()
|
|
||||||
if self.token is None:
|
|
||||||
raise AnsibleError("No Vault Token specified")
|
|
||||||
|
|
||||||
# split secret arg, which has format 'secret/hello:value' into secret='secret/hello' and secret_field='value'
|
# split secret arg, which has format 'secret/hello:value' into secret='secret/hello' and secret_field='value'
|
||||||
s = kwargs.get('secret')
|
s = kwargs.get('secret')
|
||||||
if s is None:
|
if s is None:
|
||||||
|
@ -94,7 +82,16 @@ class HashiVault:
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise AnsibleError("Authentication method '%s' not supported" % self.auth_method)
|
raise AnsibleError("Authentication method '%s' not supported" % self.auth_method)
|
||||||
else:
|
else:
|
||||||
self.token = kwargs.get('token')
|
self.token = kwargs.get('token', os.environ.get('VAULT_TOKEN', None))
|
||||||
|
if self.token is None and os.environ.get('HOME'):
|
||||||
|
token_filename = os.path.join(
|
||||||
|
os.environ.get('HOME'),
|
||||||
|
'.vault-token'
|
||||||
|
)
|
||||||
|
if os.path.exists(token_filename):
|
||||||
|
with open(token_filename) as token_file:
|
||||||
|
self.token = token_file.read().strip()
|
||||||
|
|
||||||
if self.token is None:
|
if self.token is None:
|
||||||
raise AnsibleError("No Vault Token specified")
|
raise AnsibleError("No Vault Token specified")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue