Skip to content

crossplane.parse('nginx.conf') fails with a valid nginx config file. #110

Description

@Abuelodelanada

Describe the bug
crossplane.parse('nginx.conf') fails with a valid nginx config file.

To Reproduce
Steps to reproduce the behavior:

  1. Take the following valid nginx config file (nginx.conf) with the this content:
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    upstream self {
      server localhost:80;
    }

    server {
        listen               80;
        server_name          localhost;
        root                 /web;

	location ~ ^/[a-z0-9_-]+$ {
	 rewrite            /.* /;
	 proxy_pass         http://localhost:80;
	 proxy_redirect     off;
	 proxy_set_header   Host $host;
	}

        location  ~ /[a-z0-9_-]+/ {
	 if ($request_uri ~* "/[a-z0-9_-]+/(.*)") { 
            proxy_pass       http://localhost:80/$1;
          }   

          proxy_redirect     off;
          proxy_set_header   Host $host;
        }

	location ~ ^/[a-z0-9_-]+/(.*)$ {
	 rewrite            /[a-z0-9_-]+/(.*) /$2;
  	 proxy_pass         http://localhost:80;
          proxy_redirect     off;
          proxy_set_header   Host $host;
	}

        location / {
            index            index.html index.htm;
        }

        error_page           500 502 503 504  /50x.html;
        location = /50x.html {
            root             /usr/share/nginx/html;
        }
    }
}
  1. Run conf = crossplane.parse('nginx.conf') on nginx.conf file
  2. See the following errors:
In [40]: conf["status"]
Out[40]: 'failed'

In [41]: conf["errors"]
Out[41]: 
[{'file': 'nginx.conf',
  'error': "[Errno 2] No such file or directory: 'mime.types'",
  'line': 9}]
  1. If I try to run .build() with this config I get:
In [6]: crossplane.build(conf["config"])
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[6], line 1
----> 1 crossplane.build(conf["config"])

File ~/trabajos/canonical/env/lib/python3.11/site-packages/crossplane/builder.py:122, in build(payload, indent, tabs, header)
    119     return output
    121 body = ''
--> 122 body = _build_block(body, payload, 0, 0)
    123 return head + body

File ~/trabajos/canonical/env/lib/python3.11/site-packages/crossplane/builder.py:88, in build.<locals>._build_block(output, block, depth, last_line)
     85 margin = padding * depth
     87 for stmt in block:
---> 88     directive = _enquote(stmt['directive'])
     89     line = stmt.get('line', 0)
     91     if directive == '#' and line == last_line:

KeyError: 'directive'

In [7]: 

Expected behavior

I expect that crossplane.parse() parse the config file without any issues since this config is used by a nginx instance without any errors.

Your environment

  • Operating System: Debian GNU/Linux 11 (bullseye)
  • Version of crossplane: crossplane 0.5.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions