Commit 21e13d4e authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

WebUI component:

- removed hardcoded paths and replaced by url_for methods
- arranged service paths to be homogeneous with other entities
- implemented service delete
- adapted JavaScript scripts to use dynamically generated paths from Jinja
- corrected error logger in delete of device and service
- implemented logic to support deploying the WebUI on a subpath of WSGI servers
parent f28cab56
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -36,3 +36,6 @@ CONTEXT_SERVICE_PORT = int(os.environ.get('CONTEXTSERVICE_SERVICE_PORT_GRPC', 10

DEVICE_SERVICE_ADDRESS = os.environ.get('DEVICESERVICE_SERVICE_HOST', 'deviceservice')
DEVICE_SERVICE_PORT = int(os.environ.get('DEVICESERVICE_SERVICE_PORT_GRPC', 2020))

SERVICE_SERVICE_ADDRESS = os.environ.get('SERVICESERVICE_SERVICE_HOST', 'serviceservice')
SERVICE_SERVICE_PORT = int(os.environ.get('SERVICESERVICE_SERVICE_PORT_GRPC', 3030))
+3 −0
Original line number Diff line number Diff line
@@ -54,6 +54,9 @@ COPY --chown=webui:webui context/client/. context/client
COPY --chown=webui:webui device/__init__.py device/__init__.py
COPY --chown=webui:webui device/proto/. device/proto
COPY --chown=webui:webui device/client/. device/client
COPY --chown=webui:webui service/__init__.py service/__init__.py
COPY --chown=webui:webui service/proto/. service/proto
COPY --chown=webui:webui service/client/. service/client
COPY --chown=webui:webui webui/. webui

# Start webui service
+6 −8
Original line number Diff line number Diff line
@@ -227,12 +227,12 @@
          "current": {
            "selected": true,
            "text": [
              "R1-INF",
              "R3-INF"
              "R1-EMU",
              "R3-EMU"
            ],
            "value": [
              "R1-INF",
              "R3-INF"
              "R1-EMU",
              "R3-EMU"
            ]
          },
          "datasource": null,
@@ -257,12 +257,10 @@
          "current": {
            "selected": true,
            "text": [
              "13/2/0",
              "13/2/1"
              "13/1/2"
            ],
            "value": [
              "13/2/0",
              "13/2/1"
              "13/1/2"
            ]
          },
          "datasource": null,
+15 −1
Original line number Diff line number Diff line
@@ -51,8 +51,17 @@ def readiness():
def from_json(json_str):
    return json.loads(json_str)

class SetSubAppMiddleware():
    def __init__(self, app, web_app_root):
        self.app = app
        self.web_app_root = web_app_root

def create_app(use_config=None):
    def __call__(self, environ, start_response):
        environ['SCRIPT_NAME'] = self.web_app_root
        environ['APPLICATION_ROOT'] = self.web_app_root
        return self.app(environ, start_response)

def create_app(use_config=None, web_app_root=None):
    app = Flask(__name__)
    if use_config:
        app.config.from_mapping(**use_config)
@@ -64,6 +73,9 @@ def create_app(use_config=None):
    
    app.register_blueprint(healthz, url_prefix='/healthz')

    from webui.service.js.routes import js
    app.register_blueprint(js)

    from webui.service.main.routes import main
    app.register_blueprint(main)

@@ -80,4 +92,6 @@ def create_app(use_config=None):
    
    app.jinja_env.globals.update(get_working_context=get_working_context)

    if web_app_root is not None:
        app.wsgi_app = SetSubAppMiddleware(app.wsgi_app, web_app_root)
    return app
+2 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ def main():
    metrics_port = os.environ.get('METRICS_PORT',              METRICS_PORT      )
    host         = os.environ.get('HOST',                      HOST              )
    debug        = os.environ.get('DEBUG',                     DEBUG             )
    web_app_root = os.environ.get('WEBUI_APPLICATION_ROOT',    None              )

    logging.basicConfig(level=log_level)
    logger = logging.getLogger(__name__)
@@ -40,7 +41,7 @@ def main():
    app = create_app(use_config={
        'SECRET_KEY': SECRET_KEY,
        'MAX_CONTENT_LENGTH': MAX_CONTENT_LENGTH,
    })
    }, web_app_root=web_app_root)
    app.run(host=host, port=service_port, debug=debug)

    logger.info('Bye')
Loading