feat: manage index templates

This commit is contained in:
Adrien Waksberg 2019-11-21 13:15:34 +01:00
parent dac6a51c1d
commit c3e76afa73
8 changed files with 206 additions and 1 deletions

View file

@ -0,0 +1,38 @@
#!/usr/bin/python
import requests
import base64
class ElasticsearchApi:
def __init__(self, url, user, password):
self.url = url
self.headers = {}
if user and password:
token = base64.b64encode('{}:{}',)
self.headers = { 'Authorization': 'Basic ' + base64.b64encode({},) }
def get(self, path):
r = requests.get(
'{}/{}'.format(self.url, path),
headers=self.headers
)
if r.status_code == 500:
raise Exception('Server return 500 error: {}'.format(r.text))
elif r.status_code == 401:
raise Exception('Authentification has failed')
return r.status_code, r.json()
def put(self, path, data):
r = requests.put(
'{}/{}'.format(self.url, path),
headers=self.headers,
json=data
)
if r.status_code == 500:
raise Exception('Server return 500 error: {}'.format(r.text))
elif r.status_code == 401:
raise Exception('Authentification has failed')
elif r.status_code != 200:
raise Exception('Server return an unknown error: {}'.format(r.text))