예제 #1
0
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")
예제 #2
0
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")