Пример #1
0
def run_server(addr: str, port: int, token: str) -> None:
    """Run webserver on specified scheme, address and port."""
    app.secret_key = token
    socketio.init_app(app, cors_allowed_origins=f"http://{addr}:{port}")

    cors_allowed_origins = f"http://{addr}:{port}"
    if is_development_env():
        cors_allowed_origins = "*"

    socketio.init_app(app, cors_allowed_origins=cors_allowed_origins)
    socketio.run(app, host=addr, port=port)
Пример #2
0
    def get_yaml_url(
        self,
        yaml_relative_location: str,
    ) -> Tuple[str, dict]:
        """Get url for yaml config download."""
        if is_development_env():
            from urllib.parse import quote_plus

            file_path = quote_plus(
                os.path.join(
                    "examples",
                    self.framework,
                    self.domain,
                    yaml_relative_location,
                ), )
            url = os.path.join(
                os.environ["LPOT_PROJECT_URL"],
                file_path,
                "raw?ref=developer",
            )
            headers = {"Private-Token": os.environ.get("LPOT_TOKEN")}
            return url, headers
        user = github_info.get("user")
        repository = github_info.get("repository")
        tag = github_info.get("tag")

        if not (user, repository, tag):
            message = "Missing github repository information."
            self.mq.post_error(
                "download_finish",
                {
                    "message": message,
                    "code": 500,
                    "id": self.request_id
                },
            )
            raise ClientErrorException(message)
        url_prefix = f"https://raw.githubusercontent.com/{user}/{repository}/{tag}/"
        url = os.path.join(
            url_prefix,
            "examples",
            self.framework,
            self.domain,
            yaml_relative_location,
        )
        return url, {}
Пример #3
0
def run_server(configuration: Configuration) -> None:
    """Run webserver on specified scheme, address and port."""
    addr = configuration.ip
    port = configuration.port
    token = configuration.token

    cors_allowed_origins = f"{configuration.scheme}://{addr}:{port}"
    if is_development_env():
        cors_allowed_origins = "*"

    app.secret_key = token
    CORS(app, origins=cors_allowed_origins)
    socketio.init_app(
        app,
        cors_allowed_origins=cors_allowed_origins,
        max_http_buffer_size=2000,
    )

    args = {}
    if configuration.is_tls_used():
        args["certfile"] = configuration.tls_certificate
        args["keyfile"] = configuration.tls_key

    socketio.run(app, host=addr, port=port, **args)
Пример #4
0
from flask import jsonify, request, send_file
from flask_cors import CORS, cross_origin
from flask_socketio import SocketIO

from lpot.ux.utils.exceptions import (
    AccessDeniedException,
    ClientErrorException,
    NotFoundException,
)
from lpot.ux.utils.utils import determine_ip, is_development_env, verify_file_path
from lpot.ux.web.communication import MessageQueue, Request
from lpot.ux.web.router import Router

allowed_origin = r"http://{}:*".format(determine_ip())

if is_development_env():
    allowed_origin = "*"

app = Flask(__name__, static_url_path="")
CORS(app, origins=allowed_origin)
socketio = SocketIO(app, max_http_buffer_size=2000)
router = Router()

METHODS = ["GET", "POST"]

# Suppress TensorFlow messages
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"


def run_server(addr: str, port: int, token: str) -> None:
    """Run webserver on specified scheme, address and port."""
Пример #5
0
 def test_is_empty_lpot_mode_env(self) -> None:
     """Check if development env is activated."""
     if os.environ.get("LPOT_MODE", None) is not None:
         del os.environ["LPOT_MODE"]
     is_develop = is_development_env()
     self.assertFalse(is_develop)
Пример #6
0
 def test_is_production_env(self) -> None:
     """Check if production env is activated."""
     os.environ.update({"LPOT_MODE": "production"})
     is_develop = is_development_env()
     self.assertFalse(is_develop)
Пример #7
0
 def test_is_development_env(self) -> None:
     """Check if development env is activated."""
     os.environ.update({"LPOT_MODE": "development"})
     is_develop = is_development_env()
     self.assertTrue(is_develop)