Perform a small refactor
This commit is contained in:
parent
0cb79d734a
commit
beb470fe4b
|
@ -1,4 +1,3 @@
|
|||
# For more information, please refer to https://aka.ms/vscode-docker-python
|
||||
FROM python:3.8-slim-buster
|
||||
|
||||
# Keeps Python from generating .pyc files in the container
|
||||
|
@ -7,7 +6,6 @@ ENV PYTHONDONTWRITEBYTECODE 1
|
|||
# Turns off buffering for easier container logging
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
# Install pip requirements
|
||||
ADD requirements.txt .
|
||||
RUN python -m pip install -r requirements.txt
|
||||
|
||||
|
@ -15,13 +13,11 @@ WORKDIR /app
|
|||
COPY alertify.py /app
|
||||
COPY src /app/src
|
||||
|
||||
# Switching to a non-root user, please refer to https://aka.ms/vscode-docker-python-user-rights
|
||||
RUN useradd appuser && chown -R appuser /app
|
||||
USER appuser
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
|
||||
CMD ["python", "alertify.py"]
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=3s --retries=1 \
|
||||
|
|
|
@ -56,8 +56,6 @@ if __name__ == '__main__':
|
|||
|
||||
args = parse_cli()
|
||||
|
||||
logging.info('Version: %s', alertify.__version__)
|
||||
|
||||
# forwarder = alertify.Alertify(args.config)
|
||||
forwarder = alertify.Alertify()
|
||||
|
||||
|
@ -69,6 +67,8 @@ if __name__ == '__main__':
|
|||
# Invert the sense of 'healthy' for Unix CLI usage
|
||||
return not forwarder.healthcheck.report()
|
||||
|
||||
logging.info('Version: %s', alertify.__version__)
|
||||
|
||||
if forwarder.config.verbose:
|
||||
logging.debug('Parsed config:')
|
||||
for key, val in forwarder.config.items():
|
||||
|
|
|
@ -4,6 +4,7 @@ Module to handle communication with the Gotify server
|
|||
import http.client
|
||||
import json
|
||||
import logging
|
||||
import socket
|
||||
|
||||
|
||||
class Gotify:
|
||||
|
@ -35,8 +36,8 @@ class Gotify:
|
|||
try:
|
||||
self.api.request(method, url, body=body, headers=headers)
|
||||
response = self.api.getresponse()
|
||||
except ConnectionRefusedError as error:
|
||||
logging.error(error)
|
||||
except (ConnectionRefusedError, socket.gaierror) as error:
|
||||
logging.error('Connection error: %s', error)
|
||||
return {
|
||||
'status': error.errno,
|
||||
'reason': error.strerror,
|
||||
|
@ -52,7 +53,7 @@ class Gotify:
|
|||
try:
|
||||
resp_obj['json'] = json.loads(rawbody.decode())
|
||||
except json.decoder.JSONDecodeError as error:
|
||||
logging.error(error)
|
||||
logging.error('Could not parse JSON: %s', error)
|
||||
|
||||
logging.debug('Returned from Gotify:\n%s', json.dumps(resp_obj, indent=2))
|
||||
logging.debug('Status: %s, Reason: %s', resp_obj['status'], resp_obj['reason'])
|
||||
|
|
Loading…
Reference in a new issue