예제 #1
0
def configure_riot_nginx5(root="/var/www/riot", **kwargs):
    kwargs.setdefault("LISTEN_PORT", 80)
    server_block = utils.merge_into(
        emit.server_block(
            server_name=kwargs["SERVER_NAME"], listen=kwargs["LISTEN_PORT"]
        ),
        emit.html5_block("/", root),
    )

    sio = StringIO()
    sio.write(
        dumps(
            loads(emit.redirect_block(server_name=kwargs["SERVER_NAME"], port=80))
            + server_block
            if kwargs["LISTEN_PORT"] == 443
            else server_block
        )
    )

    put(
        sio,
        "/etc/nginx/sites-enabled/{server_name}".format(
            server_name=kwargs["SERVER_NAME"]
        ),
        use_sudo=True,
    )
    return restart_systemd("nginx")
예제 #2
0
 def test_server_block_rest(self):
     server_name = "offscale.io"
     listen = "443"
     comment = None
     rest = """
      goodbye
      cruel
      world
     """
     self.assertEqual(
         loads(
             server_block(server_name=server_name,
                          listen=listen,
                          comment=comment,
                          rest=rest)),
         [[
             ["server"],
             [
                 ["# Emitted by nginx_parse_emit.emit.server_block", "\n"],
                 ["server_name", server_name],
                 ["listen", listen],
                 ["goodbye"],
                 ["cruel"],
                 ["world"],
             ],
         ]],
     )
    def setUp(self):
        # api_proxy_block
        self.location = "/api0"
        self.proxy_pass = "******"
        self.parsed_api_block = loads(
            api_proxy_block(location=self.location,
                            proxy_pass=self.proxy_pass))

        # server_block_no_rest
        self.server_name = "offscale.io"
        self.listen = "443"
        self.parsed_server_block_no_rest = loads(
            server_block(server_name=self.server_name, listen=self.listen))

        d = "/etc/letsencrypt/live/{server_name}".format(
            server_name=self.server_name)

        self.ssl_certificate = "{d}/fullchain.pem".format(d=d)
        self.ssl_certificate_key = "{d}/privkey.pem".format(d=d)

        self.nginx = configs_dir("nginx.conf")
        self.two_roots = configs_dir("two_roots.conf")
        self.one_root = configs_dir("one_root.conf")

        with open(self.one_root, "rt") as f:
            self.one_root_content = f.read()

        with open(self.two_roots, "rt") as f:
            self.two_roots_content = f.read()
예제 #4
0
    def test_merge_roots(self):
        server_name = "foo"
        self.assertEqual(
            """server {
    server_name foo;
    listen 80;
    return 301 https://$server_name$request_uri;
}
server {
    # Emitted by nginx_parse_emit.emit.server_block
    server_name foo;
    listen 443;
}""",
            dumps(
                loads(redirect_block(server_name=server_name, port="80")) +
                loads(server_block(server_name=server_name, listen="443"))),
        )
예제 #5
0
def configure_nginx2(*args, **kwargs):
    kwargs.setdefault("LISTEN_PORT", 80)

    nginx.install_nginx0()
    nginx.setup_nginx_init1()

    if kwargs.get("self_signed", False):
        certificate.self_signed0(use_sudo=True, **kwargs)

    server_block = utils.merge_into(
        (
            lambda server_block: utils.apply_attributes(
                server_block,
                emit.secure_attr(kwargs["SSL_CERTOUT"], kwargs["SSL_KEYOUT"]),
            )
            if kwargs["LISTEN_PORT"] == 443
            else server_block
        )(
            emit.server_block(
                server_name=kwargs["MATRIX_SERVER_NAME"], listen=kwargs["LISTEN_PORT"]
            )
        ),
        emit.api_proxy_block("/_matrix", "https://127.0.0.1:8008"),
    )

    sio = StringIO()
    sio.write(
        dumps(
            loads(
                emit.redirect_block(server_name=kwargs["MATRIX_SERVER_NAME"], port=80)
            )
            + server_block
            if kwargs["LISTEN_PORT"] == 443
            else server_block
        )
    )

    put(
        sio,
        "/etc/nginx/sites-enabled/{matrix_server_name}".format(
            matrix_server_name=kwargs["MATRIX_SERVER_NAME"]
        ),
        use_sudo=True,
    )
    return restart_systemd("nginx")
예제 #6
0
    def setUp(self):
        # api_proxy_block
        self.location = "/api0"
        self.proxy_pass = "******"
        self.parsed_api_block = loads(
            api_proxy_block(location=self.location,
                            proxy_pass=self.proxy_pass))

        # server_block_no_rest
        self.server_name = "offscale.io"
        self.listen = "443"
        self.parsed_server_block_no_rest = loads(
            server_block(server_name=self.server_name, listen=self.listen))

        d = "/etc/letsencrypt/live/{server_name}".format(
            server_name=self.server_name)

        self.ssl_certificate = "{d}/fullchain.pem".format(d=d)
        self.ssl_certificate_key = "{d}/privkey.pem".format(d=d)

        self.two_roots = loads("""
        server {
    # Emitted by nginx_parse_emit.emit.server_block
    server_name offscale.io;
    listen 80;
    }
        
        server {
    # Emitted by nginx_parse_emit.emit.server_block
    server_name offscale.io;
    listen 443;
 
    location /api0 {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:5000/awesome;
        proxy_redirect off;
    }
} 
        """)
예제 #7
0
def configure_nginx3(*args, **kwargs):
    nginx.install_nginx0()
    nginx.setup_nginx_init1()

    if kwargs.get("self_signed"):
        self_signed0(use_sudo=True, **kwargs)

    server_block = utils.merge_into(
        (
            lambda server_block: utils.apply_attributes(
                server_block,
                emit.secure_attr(kwargs["SSL_CERTOUT"], kwargs["SSL_KEYOUT"]),
            )
            if kwargs["LISTEN_PORT"] == 443
            else server_block
        )(
            emit.server_block(
                server_name=kwargs["SERVER_NAME"], listen=kwargs["LISTEN_PORT"]
            )
        ),
        emit.api_proxy_block("/go", "https://localhost:8154"),
    )

    sio = StringIO()
    sio.write(
        dumps(
            loads(emit.redirect_block(server_name=kwargs["SERVER_NAME"], port=80))
            + server_block
            if kwargs["LISTEN_PORT"] == 443
            else server_block
        )
    )

    put(
        sio,
        "/etc/nginx/sites-enabled/{server_name}".format(
            server_name=kwargs["SERVER_NAME"]
        ),
        use_sudo=True,
    )

    return restart_systemd("nginx")