feat: manage users

This commit is contained in:
Adrien Waksberg 2023-09-29 15:54:34 +02:00
parent aaeea21e54
commit f1ba54d2ad
10 changed files with 228 additions and 26 deletions

View file

@ -5,28 +5,25 @@ import base64
class ElasticsearchApi:
def __init__(self, url, user, password):
self.url = url
self.headers = {}
self.basic = None
if user and password:
token = base64.b64encode('{}:{}',)
self.headers = { 'Authorization': 'Basic ' + base64.b64encode({},) }
self.basic = requests.auth.HTTPBasicAuth(user, password)
def get(self, path):
r = requests.get(
'{}/{}'.format(self.url, path),
headers=self.headers
auth=self.basic
)
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,
auth=self.basic,
json=data
)