Add write_raw method to vault module

This method allow to write complex data to the vault
This commit is contained in:
slaws 2018-05-18 00:49:31 +02:00
parent 567395f4fb
commit 72c14cb2b5

View File

@ -178,6 +178,28 @@ def write_secret(path, **kwargs):
log.error('Failed to write secret! %s: %s', type(err).__name__, err)
return False
def write_raw(path, raw):
'''
Set raw data at the path in vault. The vault policy used must allow this.
CLI Example:
.. code-block:: bash
salt '*' vault.write_secret "secret/my/secret" '{"user":"foo","password": "bar"}'
'''
log.debug('Writing vault secrets for %s at %s', __grains__['id'], path)
try:
url = 'v1/{0}'.format(path)
response = __utils__['vault.make_request']('POST', url, json=raw)
if response.status_code == 200:
return response.json()['data']
elif response.status_code != 204:
response.raise_for_status()
return True
except Exception as err:
log.error('Failed to write secret! %s: %s', type(err).__name__, err)
return False
def delete_secret(path):
'''