From 1fab884a2fcae07293a2d3139889d7dcb4462fe0 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 25 May 2019 14:14:09 +0200 Subject: [PATCH] use Authorization for client --- scripts/rest_client.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/scripts/rest_client.py b/scripts/rest_client.py index b31a1de50..ca3da737e 100755 --- a/scripts/rest_client.py +++ b/scripts/rest_client.py @@ -26,10 +26,12 @@ logger = logging.getLogger("ft_rest_client") class FtRestClient(): - def __init__(self, serverurl): + def __init__(self, serverurl, username=None, password=None): self._serverurl = serverurl self._session = requests.Session() + self._username = username + self._password = password def _call(self, method, apipath, params: dict = None, data=None, files=None): @@ -41,6 +43,12 @@ class FtRestClient(): "Content-Type": "application/json" } + if self._username: + hd.update({"username": self._username}) + + if self._password: + hd.update({"password": self._password}) + # Split url schema, netloc, path, par, query, fragment = urlparse(basepath) # URLEncode query string @@ -244,8 +252,11 @@ def main(args): config = load_config(args["config"]) url = config.get("api_server", {}).get("server_url", "127.0.0.1") port = config.get("api_server", {}).get("listen_port", "8080") + username = config.get("api_server", {}).get("username") + password = config.get("api_server", {}).get("password") + server_url = f"http://{url}:{port}" - client = FtRestClient(server_url) + client = FtRestClient(server_url, username, password) m = [x for x, y in inspect.getmembers(client) if not x.startswith('_')] command = args["command"]