From 0d41b4c8e9bada26ff93ab38bc8f9ae6563bb0fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 31 Jan 2018 15:50:52 +0100 Subject: [PATCH 1/2] Refactor project structure --- {src => lib/tfw}/__init__.py | 0 lib/{ => tfw}/config/__init__.py | 0 lib/{ => tfw}/config/envvars.py | 0 lib/{ => tfw}/config/logs.py | 0 {src/event_handlers => lib/tfw}/event_handler_base.py | 2 +- {src/app => lib/tfw}/fsm_base.py | 0 {src/event_handlers => lib/tfw}/message_sender.py | 2 +- {src/app => lib/tfw/networking}/__init__.py | 0 .../app => lib/tfw/networking}/event_handler_connector.py | 6 +++--- .../tfw/networking}/server_connector.py | 8 ++++---- .../tfw/networking}/zmq_websocket_handler.py | 6 +++--- lib/{ => tfw}/util.py | 2 +- src/app/app.py | 6 +++--- src/app/handlers/__init__.py | 1 - src/app/sql_injection_fsm.py | 2 +- src/event_handlers/__init__.py | 0 src/event_handlers/source_code_event_handler.py | 6 +++--- src/event_handlers/source_code_server/server.py | 2 +- src/event_handlers/terminado_event_handler.py | 8 ++++---- src/event_handlers/terminado_server/server.py | 4 ++-- 20 files changed, 27 insertions(+), 28 deletions(-) rename {src => lib/tfw}/__init__.py (100%) rename lib/{ => tfw}/config/__init__.py (100%) rename lib/{ => tfw}/config/envvars.py (100%) rename lib/{ => tfw}/config/logs.py (100%) rename {src/event_handlers => lib/tfw}/event_handler_base.py (96%) rename {src/app => lib/tfw}/fsm_base.py (100%) rename {src/event_handlers => lib/tfw}/message_sender.py (91%) rename {src/app => lib/tfw/networking}/__init__.py (100%) rename {src/app => lib/tfw/networking}/event_handler_connector.py (91%) rename {src/event_handlers => lib/tfw/networking}/server_connector.py (93%) rename {src/app/handlers => lib/tfw/networking}/zmq_websocket_handler.py (94%) rename lib/{ => tfw}/util.py (92%) delete mode 100644 src/app/handlers/__init__.py delete mode 100644 src/event_handlers/__init__.py diff --git a/src/__init__.py b/lib/tfw/__init__.py similarity index 100% rename from src/__init__.py rename to lib/tfw/__init__.py diff --git a/lib/config/__init__.py b/lib/tfw/config/__init__.py similarity index 100% rename from lib/config/__init__.py rename to lib/tfw/config/__init__.py diff --git a/lib/config/envvars.py b/lib/tfw/config/envvars.py similarity index 100% rename from lib/config/envvars.py rename to lib/tfw/config/envvars.py diff --git a/lib/config/logs.py b/lib/tfw/config/logs.py similarity index 100% rename from lib/config/logs.py rename to lib/tfw/config/logs.py diff --git a/src/event_handlers/event_handler_base.py b/lib/tfw/event_handler_base.py similarity index 96% rename from src/event_handlers/event_handler_base.py rename to lib/tfw/event_handler_base.py index 8d949b3..c5c7bf2 100644 --- a/src/event_handlers/event_handler_base.py +++ b/lib/tfw/event_handler_base.py @@ -1,6 +1,6 @@ import json -from server_connector import ServerConnector +from .networking.server_connector import ServerConnector class EventHandlerBase: diff --git a/src/app/fsm_base.py b/lib/tfw/fsm_base.py similarity index 100% rename from src/app/fsm_base.py rename to lib/tfw/fsm_base.py diff --git a/src/event_handlers/message_sender.py b/lib/tfw/message_sender.py similarity index 91% rename from src/event_handlers/message_sender.py rename to lib/tfw/message_sender.py index 63a03b2..ab05e13 100644 --- a/src/event_handlers/message_sender.py +++ b/lib/tfw/message_sender.py @@ -1,7 +1,7 @@ import json from datetime import datetime -from server_connector import ServerUplinkConnector +from .networking.server_connector import ServerUplinkConnector class MessageSender: diff --git a/src/app/__init__.py b/lib/tfw/networking/__init__.py similarity index 100% rename from src/app/__init__.py rename to lib/tfw/networking/__init__.py diff --git a/src/app/event_handler_connector.py b/lib/tfw/networking/event_handler_connector.py similarity index 91% rename from src/app/event_handler_connector.py rename to lib/tfw/networking/event_handler_connector.py index f918aeb..e5126a4 100644 --- a/src/app/event_handler_connector.py +++ b/lib/tfw/networking/event_handler_connector.py @@ -2,10 +2,10 @@ import zmq from zmq.eventloop import ioloop from zmq.eventloop.zmqstream import ZMQStream -from config import PUBLISHER_PORT, RECEIVER_PORT -from config.logs import logging +from ..config import PUBLISHER_PORT, RECEIVER_PORT +from ..config.logs import logging log = logging.getLogger(__name__) -from util import parse_anchor_from_message, ZMQConnectorBase +from ..util import parse_anchor_from_message, ZMQConnectorBase ioloop.install() diff --git a/src/event_handlers/server_connector.py b/lib/tfw/networking/server_connector.py similarity index 93% rename from src/event_handlers/server_connector.py rename to lib/tfw/networking/server_connector.py index 078449f..c1597a6 100644 --- a/src/event_handlers/server_connector.py +++ b/lib/tfw/networking/server_connector.py @@ -1,11 +1,11 @@ -from functools import partial - import zmq +from functools import partial from zmq.eventloop import ioloop from zmq.eventloop.zmqstream import ZMQStream -from config import PUBLISHER_PORT, RECEIVER_PORT -from util import ZMQConnectorBase +from ..config import PUBLISHER_PORT, RECEIVER_PORT +from ..util import ZMQConnectorBase + ioloop.install() diff --git a/src/app/handlers/zmq_websocket_handler.py b/lib/tfw/networking/zmq_websocket_handler.py similarity index 94% rename from src/app/handlers/zmq_websocket_handler.py rename to lib/tfw/networking/zmq_websocket_handler.py index 3090712..3a5e947 100644 --- a/src/app/handlers/zmq_websocket_handler.py +++ b/lib/tfw/networking/zmq_websocket_handler.py @@ -1,9 +1,9 @@ import json from tornado.websocket import WebSocketHandler -from util import parse_anchor_from_message -from event_handler_connector import EventHandlerConnector -from config.logs import logging +from ..util import parse_anchor_from_message +from .event_handler_connector import EventHandlerConnector +from ..config.logs import logging log = logging.getLogger(__name__) diff --git a/lib/util.py b/lib/tfw/util.py similarity index 92% rename from lib/util.py rename to lib/tfw/util.py index 0717101..5aa685b 100644 --- a/lib/util.py +++ b/lib/tfw/util.py @@ -1,6 +1,6 @@ import json, xmlrpc.client, zmq -from config.envvars import SUPERVISOR_HTTP_URI +from .config.envvars import SUPERVISOR_HTTP_URI def parse_anchor_from_message(message): diff --git a/src/app/app.py b/src/app/app.py index 0a33687..1fc3c44 100644 --- a/src/app/app.py +++ b/src/app/app.py @@ -4,10 +4,10 @@ import zmq from tornado.web import Application from tornado.ioloop import IOLoop -from config import WEB_PORT -from config.logs import logging +from tfw.config import WEB_PORT +from tfw.config.logs import logging log = logging.getLogger(__name__) -from handlers import FSMManagingSocketHandler +from tfw.networking.zmq_websocket_handler import FSMManagingSocketHandler from sql_injection_fsm import SQLInjectionFSM diff --git a/src/app/handlers/__init__.py b/src/app/handlers/__init__.py deleted file mode 100644 index 9ba4aa7..0000000 --- a/src/app/handlers/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .zmq_websocket_handler import FSMManagingSocketHandler diff --git a/src/app/sql_injection_fsm.py b/src/app/sql_injection_fsm.py index 47f123e..933ab46 100644 --- a/src/app/sql_injection_fsm.py +++ b/src/app/sql_injection_fsm.py @@ -1,4 +1,4 @@ -from fsm_base import FSMBase +from tfw.fsm_base import FSMBase class SQLInjectionFSM(FSMBase): diff --git a/src/event_handlers/__init__.py b/src/event_handlers/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/event_handlers/source_code_event_handler.py b/src/event_handlers/source_code_event_handler.py index 78cd636..4620729 100644 --- a/src/event_handlers/source_code_event_handler.py +++ b/src/event_handlers/source_code_event_handler.py @@ -3,9 +3,9 @@ from os.path import splitext from contextlib import suppress from xmlrpc.client import Fault as SupervisorFault -from util import SupervisorMixin -from config import LOGIN_APP_DIR -from event_handler_base import EventHandlerBase +from tfw.util import SupervisorMixin +from tfw.config import LOGIN_APP_DIR +from tfw.event_handler_base import EventHandlerBase class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin): diff --git a/src/event_handlers/source_code_server/server.py b/src/event_handlers/source_code_server/server.py index 83db5d6..96afb6a 100644 --- a/src/event_handlers/source_code_server/server.py +++ b/src/event_handlers/source_code_server/server.py @@ -3,7 +3,7 @@ import json from tornado.ioloop import IOLoop from tornado.web import RequestHandler, Application -from config import LOGIN_APP_PORT +from tfw.config import LOGIN_APP_PORT from login_component import authorize_login diff --git a/src/event_handlers/terminado_event_handler.py b/src/event_handlers/terminado_event_handler.py index 0fd9fb2..463af7e 100644 --- a/src/event_handlers/terminado_event_handler.py +++ b/src/event_handlers/terminado_event_handler.py @@ -1,9 +1,9 @@ from shutil import rmtree, copytree -from event_handler_base import EventHandlerBase -from util import SupervisorMixin -from config import TERMINADO_DIR -from config.logs import logging +from tfw.event_handler_base import EventHandlerBase +from tfw.util import SupervisorMixin +from tfw.config import TERMINADO_DIR +from tfw.config.logs import logging log = logging.getLogger(__name__) diff --git a/src/event_handlers/terminado_server/server.py b/src/event_handlers/terminado_server/server.py index 7f8de5f..ecf16ad 100644 --- a/src/event_handlers/terminado_server/server.py +++ b/src/event_handlers/terminado_server/server.py @@ -2,8 +2,8 @@ from tornado.ioloop import IOLoop from tornado.web import Application from terminado import TermSocket, UniqueTermManager -from config import TERMINADO_PORT, TERMINADO_WD -from config.logs import logging +from tfw.config import TERMINADO_PORT, TERMINADO_WD +from tfw.config.logs import logging log = logging.getLogger(__name__) From 4c50f07be91f66ab0f21a6e7b10f4c2f0ff48ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 31 Jan 2018 16:15:19 +0100 Subject: [PATCH 2/2] Unify Docker container config file locations to project root --- Dockerfile | 4 ++-- {src/nginx => nginx}/sites-available/default | 0 supervisord.conf => supervisor/supervisord.conf | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename {src/nginx => nginx}/sites-available/default (100%) rename supervisord.conf => supervisor/supervisord.conf (100%) diff --git a/Dockerfile b/Dockerfile index 943e034..2258331 100644 --- a/Dockerfile +++ b/Dockerfile @@ -59,7 +59,7 @@ ENV TFW_LIB_DIR="/usr/local/lib/" ENV TFW_SUPERVISORD_CONF="/etc/supervisor/supervisord.conf" ENV PYTHONPATH=${TFW_LIB_DIR} -COPY src/nginx /etc/nginx +COPY nginx /etc/nginx RUN chown -R ${AVATAO_USER}: /var/log/nginx /var/lib/nginx && \ # nginx runs as a regular user, and can't write to /run sed -i 's#pid /run/nginx.pid;#pid /tmp/nginx.pid;#g' /etc/nginx/nginx.conf && \ @@ -70,7 +70,7 @@ RUN chown -R ${AVATAO_USER}: /var/log/nginx /var/lib/nginx && \ USER ${AVATAO_USER} WORKDIR /home/${AVATAO_USER} COPY lib ${TFW_LIB_DIR} -COPY supervisord.conf ${TFW_SUPERVISORD_CONF} +COPY supervisor/supervisord.conf ${TFW_SUPERVISORD_CONF} COPY src/app ${TFW_APP_DIR} COPY src/event_handlers ${TFW_EVENT_HANDLERS_DIR} diff --git a/src/nginx/sites-available/default b/nginx/sites-available/default similarity index 100% rename from src/nginx/sites-available/default rename to nginx/sites-available/default diff --git a/supervisord.conf b/supervisor/supervisord.conf similarity index 100% rename from supervisord.conf rename to supervisor/supervisord.conf