From 4fd621813978bb999f1b1603f6c5a459d7a15628 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sat, 11 Apr 2020 14:44:52 -0700 Subject: Slightly better auth handling --- Run/Que/client.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'Run/Que/client.py') diff --git a/Run/Que/client.py b/Run/Que/client.py index cd24618..4cf5d05 100755 --- a/Run/Que/client.py +++ b/Run/Que/client.py @@ -16,19 +16,22 @@ import urllib.request as request MAX_TIMEOUT = 99999999 # basically never timeout -def auth(): - conf_file = os.path.expanduser("~/.config/que.conf") - if not os.path.exists(conf_file): - sys.exit("you need a ~/.config/que.conf") - cfg = configparser.ConfigParser() - cfg.read(conf_file) - return cfg +def auth(args): + ns = args.target.split("/")[0] + if ns == "pub": + return None + else: + conf_file = os.path.expanduser("~/.config/que.conf") + if not os.path.exists(conf_file): + sys.exit("you need a ~/.config/que.conf") + cfg = configparser.ConfigParser() + cfg.read(conf_file) + return cfg[ns]["key"] def send(args): "Send a message to the que." - ns = args.target.split("/")[0] - key = auth()[ns]["key"] + key = auth(args) data = args.infile.read().encode("utf-8").strip() req = request.Request(f"{args.host}/{args.target}") req.add_header("User-AgenT", "Que/Client") @@ -44,8 +47,7 @@ def send(args): def recv(args): "Receive a message from the que." - ns = args.target.split("/")[0] - key = auth()[ns]["key"] + key = auth(args) def _recv(_req): msg = _req.readline().decode("utf-8").strip() -- cgit v1.2.3