How to use the amplify.agent.objects.nginx.config.parser.NginxConfigParser function in amplify

To help you get started, we’ve selected a few amplify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nginxinc / nginx-amplify-agent / test / unit / agent / objects / nginx / config / parser.py View on Github external
def test_location_with_semicolon_equal(self):
        cfg = NginxConfigParser(location_with_semicolon_equal)
        assert_that(calling(cfg.parse), not_(raises(TypeError)))
        assert_that(cfg.errors, has_length(0))
github nginxinc / nginx-amplify-agent / test / unit / agent / objects / nginx / config / parser.py View on Github external
def test_parse_rewrites(self):
        cfg = NginxConfigParser(rewrites_config)

        cfg.parse()
        subtree = cfg.simplify()

        # common structure
        assert_that(subtree, contains(
            has_entries({'directive': 'user'}),
            has_entries({'directive': 'worker_processes'}),
            has_entries({'directive': 'worker_rlimit_nofile'}),
            has_entries({'directive': 'error_log'}),
            has_entries({'directive': 'pid'}),
            has_entries({'directive': 'events'}),
            has_entries({'directive': 'http'})
        ))

        # http
github nginxinc / nginx-amplify-agent / test / unit / agent / objects / nginx / config / parser.py View on Github external
def test_parse_huge(self):
        cfg = NginxConfigParser(huge_config)

        cfg.parse()
        subtree = cfg.simplify()

        # common structure
        assert_that(subtree, contains(
            has_entries({'directive': 'worker_processes'}),
            has_entries({'directive': 'error_log'}),
            has_entries({'directive': 'events'}),
            has_entries({'directive': 'http'})
        ))

        # http
        http = subtree[3]['block']
        assert_that(http, contains(
            has_entries({'directive': 'include', 'args': ['mime.types']}),
github nginxinc / nginx-amplify-agent / test / unit / agent / objects / nginx / config / parser.py View on Github external
def test_lightweight_parse_includes_permissions(self):
        """
        Checks that we get file permissions during lightweight parsing
        """
        cfg = NginxConfigParser(simple_config)
        files, directories = cfg.get_structure()

        test_file = '/amplify/test/fixtures/nginx/simple/conf.d/something.conf'
        size = os.path.getsize(test_file)
        mtime = int(os.path.getmtime(test_file))
        permissions = oct(os.stat(test_file).st_mode & 0777)

        assert_that(
            files[test_file],
            equal_to({'size': size, 'mtime': mtime, 'permissions': permissions})
        )

        test_directory = '/amplify/test/fixtures/nginx/simple/conf.d/'
        size = os.path.getsize(test_directory)
        mtime = int(os.path.getmtime(test_directory))
        permissions = oct(os.stat(test_directory).st_mode & 0777)
github nginxinc / nginx-amplify-agent / test / unit / agent / objects / nginx / config / parser.py View on Github external
def test_parse_simple(self):
        cfg = NginxConfigParser(simple_config)

        cfg.parse()
        subtree = cfg.simplify()

        # main context
        assert_that(subtree, contains(
            has_entries({'directive': 'user'}),
            has_entries({'directive': 'worker_processes'}),
            has_entries({'directive': 'pid'}),
            has_entries({
                'directive': 'events',
                'block': contains(
                    has_entries({'directive': 'worker_connections'})
                )
            }),
            has_entries({
github nginxinc / nginx-amplify-agent / test / unit / agent / objects / nginx / config / parser.py View on Github external
def test_parse_complex(self):
        cfg = NginxConfigParser(complex_config)

        cfg.parse()
        tree = cfg.simplify()

        # common structure
        assert_that(tree, contains(
            has_entries({'directive': 'worker_processes'}),
            has_entries({'directive': 'daemon'}),
            has_entries({'directive': 'events'}),
            has_entries({'directive': 'http'}),
        ))

        # http
        http = tree[3]['block']
        assert_that(http, contains(
            # main config file
github nginxinc / nginx-amplify-agent / test / unit / agent / objects / nginx / config / parser.py View on Github external
def test_parse_windows(self):
        """
        Test that windows style line endings are replaces with Unix style ones for parser.
        """
        cfg = NginxConfigParser(windows_config)

        cfg.parse()
        subtree = cfg.simplify()

        # common structure
        assert_that(subtree, contains(
            has_entries({'directive': 'user'}),
            has_entries({'directive': 'worker_processes'}),
            has_entries({'directive': 'worker_rlimit_nofile'}),
            has_entries({'directive': 'events'}),
            has_entries({'directive': 'error_log'}),
            has_entries({'directive': 'pid'}),
            has_entries({'directive': 'http'})
        ))

        http = subtree[6]['block']
github nginxinc / nginx-amplify-agent / test / unit / agent / objects / nginx / config / parser.py View on Github external
def test_parse_ssl_simple_config(self):
        cfg = NginxConfigParser(ssl_simple_config)

        cfg.parse()
        subtree = cfg.simplify()

        # common structure
        assert_that(subtree, contains(
            has_entries({'directive': 'user'}),
            has_entries({'directive': 'worker_processes'}),
            has_entries({'directive': 'pid'}),
            has_entries({'directive': 'events'}),
            has_entries({'directive': 'http'})
        ))

        http = subtree[4]['block']
        assert_that(http, contains(
            has_entries({'directive': 'sendfile'}),
github nginxinc / nginx-amplify-agent / test / unit / agent / objects / nginx / config / parser.py View on Github external
def test_escaped_string(self):
        cfg = NginxConfigParser(escaped_string_config)
        cfg.parse()

        assert_that(cfg.errors, empty())

        subtree = cfg.simplify()
        assert_that(subtree, contains(
            has_entries({
                'directive': 'http',
                'block': contains(
                    has_entries({
                        'directive': 'server',
                        'block': contains(
                            has_entries({
                                'directive': 'add_header',
                                'args': ['LinkOne', '; rel="foo"'],
                            }),
github nginxinc / nginx-amplify-agent / test / unit / agent / objects / nginx / config / parser.py View on Github external
def test_parse_ssl_include_dirs(self):
        cfg = NginxConfigParser(ssl_simple_config)

        cfg.parse(include_ssl_certs=True)
        assert_that(cfg.directories, has_length(3))
        assert_that(cfg.directory_map.keys(), has_item('/amplify/test/fixtures/nginx/ssl/simple/certs.d/'))
        assert_that(cfg.ssl_certificates, has_item('/amplify/test/fixtures/nginx/ssl/simple/certs.d/example.com.crt'))