예제 #1
0
 def test_port_and_path(self):
     # The resulting URL includes the WebSocket port and path.
     url = utils.ws_to_http('wss://example.com:42/mypath')
     self.assertEqual('https://example.com:42/mypath', url)
예제 #2
0
def server():
    """Return the main server application.

    The server app is responsible for serving the WebSocket connection, the
    Juju GUI static files and the main index file for dynamic URLs.
    """
    # Set up static paths.
    guiroot = options.guiroot
    static_path = os.path.join(guiroot, 'juju-ui')
    # Set up the bundle deployer.
    deployer = Deployer(options.apiurl, options.apiversion,
                        options.charmworldurl)
    # Set up handlers.
    server_handlers = []
    if options.sandbox:
        # Sandbox mode.
        server_handlers.append((r'^/ws(?:/.*)?$', handlers.SandboxHandler, {}))
    else:
        # Real environment.
        tokens = auth.AuthenticationTokenHandler()
        websocket_handler_options = {
            # The Juju API backend url.
            'apiurl': options.apiurl,
            # The backend to use for user authentication.
            'auth_backend': auth.get_backend(options.apiversion),
            # The Juju deployer to use for importing bundles.
            'deployer': deployer,
            # The tokens collection for authentication token requests.
            'tokens': tokens,
        }
        juju_proxy_handler_options = {
            'target_url': utils.ws_to_http(options.apiurl),
            'charmworld_url': options.charmworldurl,
        }
        server_handlers.extend([
            # Handle WebSocket connections.
            (r'^/ws(?:/.*)?$', handlers.WebSocketHandler,
             websocket_handler_options),
            # Handle connections to the juju-core HTTPS server.
            # The juju-core HTTPS and WebSocket servers share the same URL.
            (r'^/juju-core/(.*)', handlers.JujuProxyHandler,
             juju_proxy_handler_options),
        ])
    if options.testsroot:
        params = {'path': options.testsroot, 'default_filename': 'index.html'}
        server_handlers.append(
            # Serve the Juju GUI tests.
            (r'^/test/(.*)', web.StaticFileHandler, params), )
    info_handler_options = {
        'apiurl': options.apiurl,
        'apiversion': options.apiversion,
        'deployer': deployer,
        'sandbox': options.sandbox,
        'start_time': int(time.time()),
    }
    server_handlers.extend([
        # Handle static files.
        (r'^/juju-ui/(.*)', web.StaticFileHandler, {
            'path': static_path
        }),
        (r'^/(favicon\.ico)$', web.StaticFileHandler, {
            'path': guiroot
        }),
        # Handle GUI server info.
        (r'^/gui-server-info', handlers.InfoHandler, info_handler_options),
        # Any other path is served by index.html.
        (r'^/(.*)', handlers.IndexHandler, {
            'path': guiroot
        }),
    ])
    return web.Application(server_handlers, debug=options.debug)
예제 #3
0
 def test_secure_websocket(self):
     # A secure WebSocket URL is correctly converted.
     url = utils.ws_to_http('wss://example.com')
     self.assertEqual('https://example.com', url)
예제 #4
0
 def test_secure_websocket(self):
     # A secure WebSocket URL is correctly converted.
     url = utils.ws_to_http('wss://example.com')
     self.assertEqual('https://example.com', url)
예제 #5
0
 def test_port_and_path(self):
     # The resulting URL includes the WebSocket port and path.
     url = utils.ws_to_http('wss://example.com:42/mypath')
     self.assertEqual('https://example.com:42/mypath', url)
예제 #6
0
파일: apps.py 프로젝트: juju/juju-gui-charm
def server():
    """Return the main server application.

    The server app is responsible for serving the WebSocket connection, the
    Juju GUI static files and the main index file for dynamic URLs.
    """
    # Set up the bundle deployer.
    deployer = Deployer(options.apiurl, options.apiversion, options.charmworldurl)
    # Set up handlers.
    server_handlers = []
    if options.sandbox:
        # Sandbox mode.
        server_handlers.append((r"^/ws(?:/.*)?$", handlers.SandboxHandler, {}))
    else:
        # Real environment.
        is_legacy_juju = LooseVersion(options.jujuversion) < LooseVersion("2")
        tokens = auth.AuthenticationTokenHandler()
        auth_backend = auth.get_backend(options.apiversion)
        ws_model_target_template = WEBSOCKET_MODEL_TARGET_TEMPLATE
        if is_legacy_juju:
            ws_model_target_template = WEBSOCKET_TARGET_TEMPLATE_PRE2
        else:
            # Register the WebSocket handler for the controller connection.
            websocket_controller_handler_options = {
                # The Juju API backend url.
                "apiurl": options.apiurl,
                # The backend to use for user authentication.
                "auth_backend": auth_backend,
                # The Juju deployer to use for importing bundles.
                "deployer": deployer,
                # The tokens collection for authentication token requests.
                "tokens": tokens,
                # The WebSocket URL template the browser uses for connecting.
                "ws_source_template": WEBSOCKET_CONTROLLER_SOURCE_TEMPLATE,
                # The WebSocket URL template used for connecting to Juju.
                "ws_target_template": WEBSOCKET_CONTROLLER_TARGET_TEMPLATE,
            }
            server_handlers.append(
                (r"^/ws/controller-api(?:/.*)?$", handlers.WebSocketHandler, websocket_controller_handler_options)
            )
        websocket_model_handler_options = {
            # The Juju API backend url.
            "apiurl": options.apiurl,
            # The backend to use for user authentication.
            "auth_backend": auth_backend,
            # The Juju deployer to use for importing bundles.
            "deployer": deployer,
            # The tokens collection for authentication token requests.
            "tokens": tokens,
            # The WebSocket URL template the browser uses for the connection.
            "ws_source_template": WEBSOCKET_MODEL_SOURCE_TEMPLATE,
            # The WebSocket URL template used for connecting to Juju.
            "ws_target_template": ws_model_target_template,
        }
        juju_proxy_handler_options = {
            "target_url": utils.ws_to_http(options.apiurl),
            "charmworld_url": options.charmworldurl,
        }
        server_handlers.extend(
            [
                # Handle WebSocket connections to the Juju model.
                (r"^/ws/model-api(?:/.*)?$", handlers.WebSocketHandler, websocket_model_handler_options),
                # Handle connections to the juju-core HTTPS server.
                # The juju-core HTTPS and WebSocket servers share the same URL.
                (r"^/juju-core/(.*)", handlers.JujuProxyHandler, juju_proxy_handler_options),
            ]
        )
    if options.testsroot:
        params = {"path": options.testsroot, "default_filename": "index.html"}
        server_handlers.append(
            # Serve the Juju GUI tests.
            (r"^/test/(.*)", web.StaticFileHandler, params)
        )
    info_handler_options = {
        "apiurl": options.apiurl,
        "apiversion": options.apiversion,
        "deployer": deployer,
        "sandbox": options.sandbox,
        "start_time": int(time.time()),
    }
    wsgi_settings = {
        "jujugui.apiAddress": options.apiurl,
        "jujugui.combine": not options.jujuguidebug,
        "jujugui.gisf": options.gisf,
        "jujugui.GTM_enabled": options.gtm,
        "jujugui.gzip": options.gzip,
        "jujugui.insecure": options.insecure,
        "jujugui.interactive_login": options.interactivelogin,
        "jujugui.bundleservice_url": options.bundleservice_url,
        "jujugui.charmstore_url": options.charmstoreurl,
        "jujugui.jujuCoreVersion": options.jujuversion,
        "jujugui.raw": options.jujuguidebug,
        "jujugui.sandbox": options.sandbox,
        "jujugui.controllerSocketTemplate": (WEBSOCKET_CONTROLLER_SOURCE_TEMPLATE),
        "jujugui.socketTemplate": WEBSOCKET_MODEL_SOURCE_TEMPLATE,
        "jujugui.uuid": options.uuid,
    }
    if options.password:
        wsgi_settings["jujugui.password"] = options.password
    config = Configurator(settings=wsgi_settings)
    wsgi_app = WSGIContainer(make_application(config))
    server_handlers.extend(
        [
            # Handle GUI server info.
            (r"^/gui-server-info", handlers.InfoHandler, info_handler_options),
            (r".*", web.FallbackHandler, dict(fallback=wsgi_app)),
        ]
    )
    return web.Application(server_handlers, debug=options.debug)
예제 #7
0
def server():
    """Return the main server application.

    The server app is responsible for serving the WebSocket connection, the
    Juju GUI static files and the main index file for dynamic URLs.
    """
    # Set up static paths.
    guiroot = options.guiroot
    static_path = os.path.join(guiroot, 'juju-ui')
    # Set up the bundle deployer.
    deployer = Deployer(options.apiurl, options.apiversion,
                        options.charmworldurl)
    # Set up handlers.
    server_handlers = []
    if options.sandbox:
        # Sandbox mode.
        server_handlers.append(
            (r'^/ws(?:/.*)?$', handlers.SandboxHandler, {}))
    else:
        # Real environment.
        tokens = auth.AuthenticationTokenHandler()
        websocket_handler_options = {
            # The Juju API backend url.
            'apiurl': options.apiurl,
            # The backend to use for user authentication.
            'auth_backend': auth.get_backend(options.apiversion),
            # The Juju deployer to use for importing bundles.
            'deployer': deployer,
            # The tokens collection for authentication token requests.
            'tokens': tokens,
        }
        juju_proxy_handler_options = {
            'target_url': utils.ws_to_http(options.apiurl),
            'charmworld_url': options.charmworldurl,
        }
        server_handlers.extend([
            # Handle WebSocket connections.
            (r'^/ws(?:/.*)?$', handlers.WebSocketHandler,
                websocket_handler_options),
            # Handle connections to the juju-core HTTPS server.
            # The juju-core HTTPS and WebSocket servers share the same URL.
            (r'^/juju-core/(.*)', handlers.JujuProxyHandler,
             juju_proxy_handler_options),
        ])
    if options.testsroot:
        params = {'path': options.testsroot, 'default_filename': 'index.html'}
        server_handlers.append(
            # Serve the Juju GUI tests.
            (r'^/test/(.*)', web.StaticFileHandler, params),
        )
    info_handler_options = {
        'apiurl': options.apiurl,
        'apiversion': options.apiversion,
        'deployer': deployer,
        'sandbox': options.sandbox,
        'start_time': int(time.time()),
    }
    server_handlers.extend([
        # Handle static files.
        (r'^/juju-ui/(.*)', web.StaticFileHandler, {'path': static_path}),
        (r'^/(favicon\.ico)$', web.StaticFileHandler, {'path': guiroot}),
        # Handle GUI server info.
        (r'^/gui-server-info', handlers.InfoHandler, info_handler_options),
        # Any other path is served by index.html.
        (r'^/(.*)', handlers.IndexHandler, {'path': guiroot}),
    ])
    return web.Application(server_handlers, debug=options.debug)
예제 #8
0
def server():
    """Return the main server application.

    The server app is responsible for serving the WebSocket connection, the
    Juju GUI static files and the main index file for dynamic URLs.
    """
    # Set up the bundle deployer.
    deployer = Deployer(options.apiurl, options.apiversion,
                        options.charmworldurl)
    # Set up handlers.
    server_handlers = []
    if options.sandbox:
        # Sandbox mode.
        server_handlers.append((r'^/ws(?:/.*)?$', handlers.SandboxHandler, {}))
    else:
        # Real environment.
        is_legacy_juju = LooseVersion(options.jujuversion) < LooseVersion('2')
        tokens = auth.AuthenticationTokenHandler()
        auth_backend = auth.get_backend(options.apiversion)
        ws_model_target_template = WEBSOCKET_MODEL_TARGET_TEMPLATE
        if is_legacy_juju:
            ws_model_target_template = WEBSOCKET_TARGET_TEMPLATE_PRE2
        else:
            # Register the WebSocket handler for the controller connection.
            websocket_controller_handler_options = {
                # The Juju API backend url.
                'apiurl': options.apiurl,
                # The backend to use for user authentication.
                'auth_backend': auth_backend,
                # The Juju deployer to use for importing bundles.
                'deployer': deployer,
                # The tokens collection for authentication token requests.
                'tokens': tokens,
                # The WebSocket URL template the browser uses for connecting.
                'ws_source_template': WEBSOCKET_CONTROLLER_SOURCE_TEMPLATE,
                # The WebSocket URL template used for connecting to Juju.
                'ws_target_template': WEBSOCKET_CONTROLLER_TARGET_TEMPLATE,
            }
            server_handlers.append(
                (r'^/ws/controller-api(?:/.*)?$', handlers.WebSocketHandler,
                 websocket_controller_handler_options))
        websocket_model_handler_options = {
            # The Juju API backend url.
            'apiurl': options.apiurl,
            # The backend to use for user authentication.
            'auth_backend': auth_backend,
            # The Juju deployer to use for importing bundles.
            'deployer': deployer,
            # The tokens collection for authentication token requests.
            'tokens': tokens,
            # The WebSocket URL template the browser uses for the connection.
            'ws_source_template': WEBSOCKET_MODEL_SOURCE_TEMPLATE,
            # The WebSocket URL template used for connecting to Juju.
            'ws_target_template': ws_model_target_template,
        }
        juju_proxy_handler_options = {
            'target_url': utils.ws_to_http(options.apiurl),
            'charmworld_url': options.charmworldurl,
        }
        server_handlers.extend([
            # Handle WebSocket connections to the Juju model.
            (r'^/ws/model-api(?:/.*)?$', handlers.WebSocketHandler,
             websocket_model_handler_options),
            # Handle connections to the juju-core HTTPS server.
            # The juju-core HTTPS and WebSocket servers share the same URL.
            (r'^/juju-core/(.*)', handlers.JujuProxyHandler,
             juju_proxy_handler_options),
        ])
    if options.testsroot:
        params = {'path': options.testsroot, 'default_filename': 'index.html'}
        server_handlers.append(
            # Serve the Juju GUI tests.
            (r'^/test/(.*)', web.StaticFileHandler, params), )
    info_handler_options = {
        'apiurl': options.apiurl,
        'apiversion': options.apiversion,
        'deployer': deployer,
        'sandbox': options.sandbox,
        'start_time': int(time.time()),
    }
    wsgi_settings = {
        'jujugui.apiAddress': options.apiurl,
        'jujugui.combine': not options.jujuguidebug,
        'jujugui.gisf': options.gisf,
        'jujugui.GTM_enabled': options.gtm,
        'jujugui.gzip': options.gzip,
        'jujugui.insecure': options.insecure,
        'jujugui.interactive_login': options.interactivelogin,
        'jujugui.bundleservice_url': options.bundleservice_url,
        'jujugui.charmstore_url': options.charmstoreurl,
        'jujugui.jujuCoreVersion': options.jujuversion,
        'jujugui.raw': options.jujuguidebug,
        'jujugui.sandbox': options.sandbox,
        'jujugui.controllerSocketTemplate':
        (WEBSOCKET_CONTROLLER_SOURCE_TEMPLATE),
        'jujugui.socketTemplate': WEBSOCKET_MODEL_SOURCE_TEMPLATE,
        'jujugui.uuid': options.uuid,
    }
    if options.password:
        wsgi_settings['jujugui.password'] = options.password
    config = Configurator(settings=wsgi_settings)
    wsgi_app = WSGIContainer(make_application(config))
    server_handlers.extend([
        # Handle GUI server info.
        (r'^/gui-server-info', handlers.InfoHandler, info_handler_options),
        (r".*", web.FallbackHandler, dict(fallback=wsgi_app))
    ])
    return web.Application(server_handlers, debug=options.debug)
예제 #9
0
 def test_websocket(self):
     # A WebSocket URL is correctly converted.
     url = utils.ws_to_http("ws://example.com")
     self.assertEqual("http://example.com", url)
예제 #10
0
def server():
    """Return the main server application.

    The server app is responsible for serving the WebSocket connection, the
    Juju GUI static files and the main index file for dynamic URLs.
    """
    # Set up the bundle deployer.
    deployer = Deployer(options.apiurl, options.apiversion,
                        options.charmworldurl)
    # Set up handlers.
    server_handlers = []
    if options.sandbox:
        # Sandbox mode.
        server_handlers.append(
            (r'^/ws(?:/.*)?$', handlers.SandboxHandler, {}))
    else:
        # Real environment.
        ws_target_template = WEBSOCKET_TARGET_TEMPLATE
        if LooseVersion(options.jujuversion) < LooseVersion('2'):
            ws_target_template = WEBSOCKET_TARGET_TEMPLATE_PRE2
        tokens = auth.AuthenticationTokenHandler()
        websocket_handler_options = {
            # The Juju API backend url.
            'apiurl': options.apiurl,
            # The backend to use for user authentication.
            'auth_backend': auth.get_backend(options.apiversion),
            # The Juju deployer to use for importing bundles.
            'deployer': deployer,
            # The tokens collection for authentication token requests.
            'tokens': tokens,
            # The WebSocket URL template the browser uses for the connection.
            'ws_source_template': WEBSOCKET_SOURCE_TEMPLATE,
            # The WebSocket URL template used for connecting to Juju.
            'ws_target_template': ws_target_template,
        }
        juju_proxy_handler_options = {
            'target_url': utils.ws_to_http(options.apiurl),
            'charmworld_url': options.charmworldurl,
        }
        server_handlers.extend([
            # Handle WebSocket connections.
            (r'^/ws(?:/.*)?$', handlers.WebSocketHandler,
                websocket_handler_options),
            # Handle connections to the juju-core HTTPS server.
            # The juju-core HTTPS and WebSocket servers share the same URL.
            (r'^/juju-core/(.*)', handlers.JujuProxyHandler,
             juju_proxy_handler_options),
        ])
    if options.testsroot:
        params = {'path': options.testsroot, 'default_filename': 'index.html'}
        server_handlers.append(
            # Serve the Juju GUI tests.
            (r'^/test/(.*)', web.StaticFileHandler, params),
        )
    info_handler_options = {
        'apiurl': options.apiurl,
        'apiversion': options.apiversion,
        'deployer': deployer,
        'sandbox': options.sandbox,
        'start_time': int(time.time()),
    }
    wsgi_settings = {
        'jujugui.apiAddress': options.apiurl,
        'jujugui.combine': not options.jujuguidebug,
        'jujugui.gisf': options.gisf,
        'jujugui.GTM_enabled': options.gtm,
        'jujugui.gzip': options.gzip,
        'jujugui.insecure': options.insecure,
        'jujugui.interactive_login': options.interactivelogin,
        'jujugui.jem_url': options.jemurl,
        'jujugui.charmstore_url': options.charmstoreurl,
        'jujugui.jujuCoreVersion': options.jujuversion,
        'jujugui.raw': options.jujuguidebug,
        'jujugui.sandbox': options.sandbox,
        'jujugui.socketTemplate': WEBSOCKET_SOURCE_TEMPLATE,
        'jujugui.uuid': options.uuid,
    }
    if options.password:
        wsgi_settings['jujugui.password'] = options.password
    config = Configurator(settings=wsgi_settings)
    wsgi_app = WSGIContainer(make_application(config))
    server_handlers.extend([
        # Handle GUI server info.
        (r'^/gui-server-info', handlers.InfoHandler, info_handler_options),
        (r".*", web.FallbackHandler, dict(fallback=wsgi_app))
    ])
    return web.Application(server_handlers, debug=options.debug)