From 0d96aaacb728da9e06bacb629a50eb139fa4936a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 12 Jul 2019 12:05:43 +0100 Subject: [PATCH] Tidying --- daemon.py | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/daemon.py b/daemon.py index bb82ed82..f1298e73 100644 --- a/daemon.py +++ b/daemon.py @@ -174,6 +174,14 @@ class PubServer(BaseHTTPRequestHandler): return True return False + def _isAuthorized(self) -> bool: + if self.headers.get('Authorization'): + if authorize(self.server.baseDir,self.path, \ + self.headers['Authorization'], \ + self.server.debug): + return True + return False + def do_GET(self): if self.server.debug: print('DEBUG: GET from '+self.server.baseDir+ \ @@ -257,25 +265,22 @@ class PubServer(BaseHTTPRequestHandler): # get the inbox for a given person if self.path.endswith('/inbox'): if '/users/' in self.path: - if self.headers.get('Authorization'): - if authorize(self.server.baseDir,self.path, \ - self.headers['Authorization'], \ - self.server.debug): - inboxFeed=personBoxJson(self.server.baseDir, \ - self.server.domain, \ - self.server.port, \ - self.path, \ - self.server.httpPrefix, \ - maxPostsInFeed, 'inbox') - if inboxFeed: - self._set_headers('application/json') - self.wfile.write(json.dumps(inboxFeed).encode('utf-8')) - self.server.GETbusy=False - return - else: - if self.server.debug: - print('DEBUG: '+nickname+ \ - ' was not authorized to access '+self.path) + if self._isAuthorized(): + inboxFeed=personBoxJson(self.server.baseDir, \ + self.server.domain, \ + self.server.port, \ + self.path, \ + self.server.httpPrefix, \ + maxPostsInFeed, 'inbox') + if inboxFeed: + self._set_headers('application/json') + self.wfile.write(json.dumps(inboxFeed).encode('utf-8')) + self.server.GETbusy=False + return + else: + if self.server.debug: + print('DEBUG: '+nickname+ \ + ' was not authorized to access '+self.path) if self.server.debug: print('DEBUG: GET access to inbox is unauthorized') self.send_response(405) @@ -380,13 +385,10 @@ class PubServer(BaseHTTPRequestHandler): if self.path.endswith('/outbox'): if '/users/' in self.path: - if self.headers.get('Authorization'): - if authorize(self.server.baseDir,self.path, \ - self.headers['Authorization'], \ - self.server.debug): - self.outboxAuthenticated=True - pathUsersSection=path.split('/users/')[1] - self.postToNickname=pathUsersSection.split('/')[0] + if self._isAuthorized(): + self.outboxAuthenticated=True + pathUsersSection=path.split('/users/')[1] + self.postToNickname=pathUsersSection.split('/')[0] if not self.outboxAuthenticated: self.send_response(405) self.end_headers()