From fd8c5da35a70f2c1dcd77fb9c0f8f0b2c7dcc68b Mon Sep 17 00:00:00 2001 From: Ludwig Behm Date: Wed, 25 Oct 2023 01:08:16 +0200 Subject: [PATCH] Fix apistatusd.py: missing `)` and code cleanup --- source/server/apistatusd.py | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/source/server/apistatusd.py b/source/server/apistatusd.py index 048e554..5ec3b68 100755 --- a/source/server/apistatusd.py +++ b/source/server/apistatusd.py @@ -130,18 +130,6 @@ def display_peercert(cert): else: logging.debug(f'{key}: {cert[key]}') logging.debug('-----------------') - try: - logging.debug('Peer certificate commonName: {}'.format( - cert['subject'][5][0][1])) - logging.debug('Peer certificate serialNumber: {}'.format( - cert['serialNumber'])) - logging.debug('Peer certificate notBefore: {}'.format( - cert['notBefore'])) - logging.debug('Peer certificate notAfter: {}'.format( - cert['notAfter'])) - except Exception as error: - logging.debug('Cert display failed') - logging.debug(error) def receive_buffer_is_valid(raw_data): ''' @@ -224,7 +212,7 @@ def get_status_and_time(raw_data): param 1: byte object return: tuple (boolean, integer) ''' - status = True if raw_data.decode('utf-8', 'strict') == '1' else False + status = raw_data.decode('utf-8', 'strict') == '1' timestamp = int(str(time()).split('.')[0]) logging.debug('Set values for timestamp: {} and status: {}'.format( @@ -274,10 +262,6 @@ class Toot(threading.Thread): return: boolean ''' timeformat = '%d.%m.%Y %H:%M Uhr' - # check if status is valid - if self.status not in (True, False): - logging.error('Invalid status to toot') - return False # convert seconds into timestring try: timestring = strftime(timeformat, localtime(self.timestamp)) @@ -285,9 +269,9 @@ class Toot(threading.Thread): logging.error('Can not convert timestamp into timestring') return False # set status message - if self.status == True: + if self.status: self.data['status'] = 'Krautspace is open since: {}'.format(timestring) - elif self.status == False: + else: self.data['status'] = 'Krautspace is closed since: {}'.format(timestring) logging.debug('Message: {}'.format(self.data['status'])) # build mastodon api url @@ -448,19 +432,17 @@ def main(): ClientSocket.settimeout(float(config['general']['timeout'])) logging.debug('set ssl handshake timeout to {}s'.format(ClientSocket.gettimeout())) Connection = context.wrap_socket(ClientSocket, server_side=True) - logging.info('SSL Connection established') - Connection.settimeout(float(config['general']['timeout'])) - logging.debug('Connection timeout set to {}'.format(Connection.gettimeout()) - cert = Connection.getpeercert(binary_form=False) - display_peercert(cert) + logging.debug('SSL Connection established') + display_peercert(Connection.getpeercert(binary_form=False)) except Exception as e: logging.error('Unexpected error: {}'.format(e)) continue + # empfangen und antworten raw_data = Connection.recv(1) - if receive_buffer_is_valid(raw_data) is True: + if receive_buffer_is_valid(raw_data): status, timestamp = get_status_and_time(raw_data) - if change_status(status, timestamp, api_template, config['api']['api']) is True: + if change_status(status, timestamp, api_template, config['api']['api']): answer = raw_data if config['mastodon']['send'].lower() == 'true': logging.debug('Toot is set to true')