def configure(m2ee):
    samesite_cookie_workaround_enabled = _is_samesite_cookie_workaround_enabled(
        MXVersion(str(m2ee.config.get_runtime_version())))
    if samesite_cookie_workaround_enabled:
        logging.info("SameSite cookie workaround is enabled")

    output_path = os.path.abspath(CONFIG_FILE)
    template_path = os.path.abspath("{}.j2".format(CONFIG_FILE))

    with open(template_path, "r") as file_:
        template = Template(file_.read(), trim_blocks=True, lstrip_blocks=True)
    rendered = template.render(
        instadeploy_enabled=instadeploy.use_instadeploy(
            m2ee.config.get_runtime_version()),
        samesite_cookie_workaround_enabled=samesite_cookie_workaround_enabled,
        locations=get_access_restriction_locations(),
        default_headers=get_http_headers(),
        nginx_port=str(util.get_nginx_port()),
        runtime_port=str(util.get_runtime_port()),
        admin_port=str(util.get_admin_port()),
        deploy_port=str(util.get_deploy_port()),
        root=os.getcwd(),
    )

    logging.debug("Writing nginx configuration file...")
    with open(output_path, "w") as file_:
        file_.write(rendered)
    logging.debug("nginx configuration file written")

    generate_password_file({"MxAdmin": security.get_m2ee_password()})
    generate_password_file({"deploy": os.getenv("DEPLOY_PASSWORD")},
                           file_name_suffix="-mxbuild")
Beispiel #2
0
def set_up_files(m2ee):
    lines = ""

    if util.use_instadeploy(m2ee.config.get_runtime_version()):
        mxbuild_upstream = "proxy_pass http://mendix_mxbuild"
    else:
        mxbuild_upstream = "return 501"
    with open("nginx/conf/nginx.conf") as fh:
        lines = "".join(fh.readlines())
    http_headers = parse_headers()
    lines = (
        lines.replace("CONFIG", get_path_config())
        .replace("NGINX_PORT", str(util.get_nginx_port()))
        .replace("RUNTIME_PORT", str(util.get_runtime_port()))
        .replace("ADMIN_PORT", str(util.get_admin_port()))
        .replace("DEPLOY_PORT", str(util.get_deploy_port()))
        .replace("ROOT", os.getcwd())
        .replace("HTTP_HEADERS", http_headers)
        .replace("MXBUILD_UPSTREAM", mxbuild_upstream)
    )
    for line in lines.split("\n"):
        logging.debug(line)
    with open("nginx/conf/nginx.conf", "w") as fh:
        fh.write(lines)

    gen_htpasswd({"MxAdmin": security.get_m2ee_password()})
    gen_htpasswd(
        {"deploy": os.getenv("DEPLOY_PASSWORD")}, file_name_suffix="-mxbuild"
    )
def set_up_files(m2ee):
    lines = ""

    if instadeploy.use_instadeploy(m2ee.config.get_runtime_version()):
        mxbuild_upstream = "proxy_pass http://mendix_mxbuild"
    else:
        mxbuild_upstream = "return 501"
    with open("nginx/conf/nginx.conf") as fh:
        lines = "".join(fh.readlines())

    samesite_cookie_workaround_enabled = _is_samesite_cookie_workaround_enabled(
        MXVersion(str(m2ee.config.get_runtime_version())))

    if samesite_cookie_workaround_enabled:
        logging.info("SameSite cookie workaround is enabled")

    http_headers = parse_headers(samesite_cookie_workaround_enabled)
    lines = (lines.replace(
        "CONFIG", get_path_config(samesite_cookie_workaround_enabled)).replace(
            "NGINX_PORT", str(util.get_nginx_port())).replace(
                "RUNTIME_PORT", str(util.get_runtime_port())).replace(
                    "ADMIN_PORT", str(util.get_admin_port())).replace(
                        "DEPLOY_PORT", str(util.get_deploy_port())).replace(
                            "ROOT", os.getcwd()).replace(
                                "HTTP_HEADERS",
                                http_headers).replace("MXBUILD_UPSTREAM",
                                                      mxbuild_upstream))
    with open("nginx/conf/nginx.conf", "w") as fh:
        fh.write(lines)

    gen_htpasswd({"MxAdmin": security.get_m2ee_password()})
    gen_htpasswd({"deploy": os.getenv("DEPLOY_PASSWORD")},
                 file_name_suffix="-mxbuild")
Beispiel #4
0
def update_config():
    samesite_cookie_workaround_enabled = (
        _is_samesite_cookie_workaround_enabled(runtime.get_runtime_version())
    )
    if samesite_cookie_workaround_enabled:
        logging.info("SameSite cookie workaround is enabled")

    # Populating nginx config template
    output_path = os.path.abspath(CONFIG_FILE)
    template_path = os.path.abspath("{}.j2".format(CONFIG_FILE))

    with open(template_path, "r") as file_:
        template = Template(file_.read(), trim_blocks=True, lstrip_blocks=True)
    rendered = template.render(
        samesite_cookie_workaround_enabled=samesite_cookie_workaround_enabled,
        locations=_get_locations(),
        default_headers=_get_http_headers(),
        nginx_port=str(util.get_nginx_port()),
        runtime_port=str(util.get_runtime_port()),
        admin_port=str(util.get_admin_port()),
        root=os.getcwd(),
        mxadmin_path=MXADMIN_PATH,
        client_cert_check_internal_path_prefix=CLIENT_CERT_CHECK_INTERNAL_PATH_PREFIX,
    )

    logging.debug("Writing nginx configuration file...")
    with open(output_path, "w") as file_:
        file_.write(rendered)
    logging.debug("nginx configuration file written")

    # Populating proxy params template
    output_path = os.path.abspath(PROXY_FILE)
    template_path = os.path.abspath("{}.j2".format(PROXY_FILE))

    with open(template_path, "r") as file_:
        template = Template(file_.read(), trim_blocks=True, lstrip_blocks=True)
    rendered = template.render(
        proxy_buffers=_get_proxy_buffers(),
        proxy_buffer_size=_get_proxy_buffer_size(),
    )

    logging.debug("Writing proxy_params configuration file...")
    with open(output_path, "w") as file_:
        file_.write(rendered)
    logging.debug("proxy_params configuration file written")

    _generate_password_file({"MxAdmin": security.get_m2ee_password()})