De Wiki inetshell
Saltar a: navegación, buscar

http://docs.python-requests.org/en/latest/api/ http://docs.python-requests.org/en/v0.6.5/user/quickstart/

# http://docs.python-requests.org/en/latest/api/
import requests

# Desactiva advertencia por no verificar conexion TLS
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

url = 'https://127.0.0.1:8200
host = 'https://127.0.0.1:8200'
ruta = args.ruta
token = args.token
timeout = 10

try:
	r = requests.get(host + '/v1/sys/init', headers={'X-Vault-Token':token}, verify=False, timeout=timeout)
except requests.exceptions.ReadTimeout as e:
	print('TimeOut:',e)
	sys.exit(11)
except requests.exceptions.ConnectionError as e:
	print('ConnectionError:',e)
	sys.exit(12)

data = r.json()
vault_state = data['initialized']
if vault_state:
	print('Vault disponible')
	r = requests.get(host + '/v1/data', headers={'X-Vault-Token':token}, verify=False, timeout=timeout)
	data = r.json()
	print(data['data']['principal'])
	print(data['data']['keytab'])
else:
	print('Vault sellado')