aluttik / go-crossplane

An unofficial Go port of the NGINX config/JSON converter crossplane
Apache License 2.0
50 stars 15 forks source link

Standalone `server` block not parsable #14

Open SamuelMarks opened 1 year ago

SamuelMarks commented 1 year ago
server {
    # My comment here
    server_name domain.name;
    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;
    }
}

With your basic crossplane.Parse example in your README, this errors:

{
  "status": "failed",
  "errors": [
    {
      "file": "/tmp/configs/merged_roots.conf",
      "line": 1,
      "error": "\"server\" directive is not allowed here in /tmp/configs/merged_roots.conf:1"
    },
    {
      "file": "/tmp/configs/merged_roots.conf",
      "line": 3,
      "error": "\"server_name\" directive is not allowed here in /tmp/configs/merged_roots.conf:3"
    },
    {
      "file": "/tmp/configs/merged_roots.conf",
      "line": 4,
      "error": "\"listen\" directive is not allowed here in /tmp/configs/merged_roots.conf:4"
    },
    {
      "file": "/tmp/configs/merged_roots.conf",
      "line": 6,
      "error": "\"location\" directive is not allowed here in /tmp/configs/merged_roots.conf:6"
    },
    {
      "file": "/tmp/configs/merged_roots.conf",
      "line": 7,
      "error": "\"proxy_set_header\" directive is not allowed here in /tmp/configs/merged_roots.conf:7"
    },
    {
      "file": "/tmp/configs/merged_roots.conf",
      "line": 8,
      "error": "\"proxy_set_header\" directive is not allowed here in /tmp/configs/merged_roots.conf:8"
    },
    {
      "file": "/tmp/configs/merged_roots.conf",
      "line": 9,
      "error": "\"proxy_set_header\" directive is not allowed here in /tmp/configs/merged_roots.conf:9"
    },
    {
      "file": "/tmp/configs/merged_roots.conf",
      "line": 10,
      "error": "\"proxy_set_header\" directive is not allowed here in /tmp/configs/merged_roots.conf:10"
    },
    {
      "file": "/tmp/configs/merged_roots.conf",
      "line": 11,
      "error": "\"proxy_set_header\" directive is not allowed here in /tmp/configs/merged_roots.conf:11"
    },
    {
      "file": "/tmp/configs/merged_roots.conf",
      "line": 12,
      "error": "\"proxy_pass\" directive is not allowed here in /tmp/configs/merged_roots.conf:12"
    },
    {
      "file": "/tmp/configs/merged_roots.conf",
      "line": 13,
      "error": "\"proxy_redirect\" directive is not allowed here in /tmp/configs/merged_roots.conf:13"
    }
  ],
  "config": [
    {
      "file": "/tmp/configs/merged_roots.conf",
      "status": "failed",
      "errors": [
        {
          "line": 1,
          "error": "\"server\" directive is not allowed here in /tmp/configs/merged_roots.conf:1"
        },
        {
          "line": 3,
          "error": "\"server_name\" directive is not allowed here in /tmp/configs/merged_roots.conf:3"
        },
        {
          "line": 4,
          "error": "\"listen\" directive is not allowed here in /tmp/configs/merged_roots.conf:4"
        },
        {
          "line": 6,
          "error": "\"location\" directive is not allowed here in /tmp/configs/merged_roots.conf:6"
        },
        {
          "line": 7,
          "error": "\"proxy_set_header\" directive is not allowed here in /tmp/configs/merged_roots.conf:7"
        },
        {
          "line": 8,
          "error": "\"proxy_set_header\" directive is not allowed here in /tmp/configs/merged_roots.conf:8"
        },
        {
          "line": 9,
          "error": "\"proxy_set_header\" directive is not allowed here in /tmp/configs/merged_roots.conf:9"
        },
        {
          "line": 10,
          "error": "\"proxy_set_header\" directive is not allowed here in /tmp/configs/merged_roots.conf:10"
        },
        {
          "line": 11,
          "error": "\"proxy_set_header\" directive is not allowed here in /tmp/configs/merged_roots.conf:11"
        },
        {
          "line": 12,
          "error": "\"proxy_pass\" directive is not allowed here in /tmp/configs/merged_roots.conf:12"
        },
        {
          "line": 13,
          "error": "\"proxy_redirect\" directive is not allowed here in /tmp/configs/merged_roots.conf:13"
        }
      ],
      "parsed": []
    }
  ]
}

In the meantime I'll just:

crossplane.ParseOptions{SkipDirectiveContextCheck: true, SkipDirectiveArgsCheck: true}
mingmingshiliyu commented 10 months ago

you should make it surrounded by http{} block

SamuelMarks commented 10 months ago

@mingmingshiliyu Yes but these are included; so should not be surrounded so.

mingmingshiliyu commented 10 months ago

I use your case like nginx.conf

http{
    server {
        # My comment here
        server_name domain.name;
        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;
        }
    }
}

and parse it into json style ,it`s obviously workable.

mingmingshiliyu commented 10 months ago

And I`m doubt about using gonginx or go-crossplane to parse configuration,maybe not only nginx.conf in the future,Do you have any advices?

SamuelMarks commented 10 months ago

@mingmingshiliyu Sure but include is very useful, and in a dynamic environment I might want to reload nginx and include/exclude different server blocks. Being able to convert to JSON, modify the JSON, then emit the new server block is required functionality for my use-case.

And my use-case seems pretty common.

mingmingshiliyu commented 7 months ago

@mingmingshiliyu Sure but include is very useful, and in a dynamic environment I might want to reload nginx and include/exclude different server blocks. Being able to convert to JSON, modify the JSON, then emit the new server block is required functionality for my use-case.

And my use-case seems pretty common.

image

oh, it happened! agree with you

SamuelMarks commented 3 months ago

@aluttik Bump