Merge pull request #45820 from iustinam/reusetok

Make vault session token reusable
This commit is contained in:
Nicole Thomas 2018-02-23 14:26:29 -05:00 committed by GitHub
commit 90353c90f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,6 +24,8 @@ logging.getLogger("requests").setLevel(logging.WARNING)
# Load the __salt__ dunder if not already loaded (when called from utils-module)
__salt__ = None
def __virtual__(): # pylint: disable=expected-2-blank-lines-found-0
try:
global __salt__ # pylint: disable=global-statement
@ -126,7 +128,7 @@ def _get_vault_connection():
return _get_token_and_url_from_master()
def make_request(method, resource, profile=None, **args):
def make_request(method, resource, profile=None, token=None, vault_url=None, get_token_url=False, **args):
'''
Make a request to Vault
'''
@ -134,6 +136,7 @@ def make_request(method, resource, profile=None, **args):
# Deprecated code path
return make_request_with_profile(method, resource, profile, **args)
if not token or not vault_url:
connection = _get_vault_connection()
token, vault_url = connection['token'], connection['url']
if 'verify' not in args:
@ -143,6 +146,9 @@ def make_request(method, resource, profile=None, **args):
headers = {'X-Vault-Token': token, 'Content-Type': 'application/json'}
response = requests.request(method, url, headers=headers, **args)
if get_token_url:
return response, token, vault_url
else:
return response