summaryrefslogtreecommitdiff
path: root/Run/Que/client.py
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-04-11 14:44:52 -0700
committerBen Sima <ben@bsima.me>2020-04-11 14:44:52 -0700
commit4fd621813978bb999f1b1603f6c5a459d7a15628 (patch)
tree06ec322c79a9d360710d097407bf2356a241bfa7 /Run/Que/client.py
parentfd51dbc6ae0a90d7047eebb0a44318a237a15e34 (diff)
Slightly better auth handling
Diffstat (limited to 'Run/Que/client.py')
-rwxr-xr-xRun/Que/client.py24
1 files changed, 13 insertions, 11 deletions
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()