Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support relative includes #25

Closed
pyhedgehog opened this issue May 13, 2024 · 3 comments · Fixed by #27
Closed

Support relative includes #25

pyhedgehog opened this issue May 13, 2024 · 3 comments · Fixed by #27

Comments

@pyhedgehog
Copy link

For example I have in nginx.conf line include mime.types;.
Then with full path:

$ nginx-static-analysis --file /etc/nginx/nginx.conf
Traceback (most recent call last):
  File "/home/<USER>/.local/bin/nginx-static-analysis", line 8, in <module>
    sys.exit(main())
  File "/home/<USER>/.local/pipx/venvs/nginx-static-analysis/lib/python3.10/site-packages/nginx_analysis/main.py", line 21, in main
    root_config = parse_config(args.file)
  File "/home/<USER>/.local/pipx/venvs/nginx-static-analysis/lib/python3.10/site-packages/nginx_analysis/analysis.py", line 70, in parse_config
    set_parents_of_blocks(root_config, line_config)
  File "/home/<USER>/.local/pipx/venvs/nginx-static-analysis/lib/python3.10/site-packages/nginx_analysis/analysis.py", line 55, in set_parents_of_blocks
    set_parents_of_blocks(root_config, block_config)
  File "/home/<USER>/.local/pipx/venvs/nginx-static-analysis/lib/python3.10/site-packages/nginx_analysis/analysis.py", line 56, in set_parents_of_blocks
    set_parents_in_include(root_config, line_config)
  File "/home/<USER>/.local/pipx/venvs/nginx-static-analysis/lib/python3.10/site-packages/nginx_analysis/analysis.py", line 41, in set_parents_in_include
    nested_file_configs = root_config.get_files(nginx_to_regex(file_path))
  File "/home/<USER>/.local/pipx/venvs/nginx-static-analysis/lib/python3.10/site-packages/nginx_analysis/dataclasses.py", line 183, in get_files
    raise IndexError(f"{file_path_regex} not found in config")
IndexError: mime.types not found in config

But if I start it with relative parameter it works: (cd /etc/nginx;nginx-static-analysis --file nginx.conf).
I think relative paths should be parsed against path of root config.

@AlexanderGrooff
Copy link
Owner

Hi there,

Thanks for catching this, you make a good point. I didn't consider relative paths yet, and it seems that Nginx defaults to prefixing relative paths with /etc/nginx (if this SO is still valid). This should either:

  1. Prefix relative paths with /etc/nginx
  2. Use the dir in which the root config file is located

I'll see if I can fix this some time in the future, seems straightforward enough.

@pyhedgehog
Copy link
Author

@AlexanderGrooff
Copy link
Owner

Thanks for the report. Should be fixed and tested in the latest release https://github.com/AlexanderGrooff/nginx-static-analysis/releases/tag/0.3.0

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants