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

Cannot parse partial configs #99

Open
kenneth-vkd opened this issue Jan 21, 2022 · 5 comments
Open

Cannot parse partial configs #99

kenneth-vkd opened this issue Jan 21, 2022 · 5 comments

Comments

@kenneth-vkd
Copy link

Describe the bug
Unable to process config file with http block

To Reproduce
Parse this file:
template-config-no-http.txt

It works if you wrap it in an http block:
template-config-http.txt

Expected behavior
Since the file is a valid partial configuration, it would be expected to have this work

Your environment

  • Operating System Ubuntu 20.04
  • Version of crossplane crossplane 0.5.7
@rogueloop
Copy link

the same issue with server block - parsing returns lots of errors
got some alternative to this? @kenneth-vkd

@kenneth-vkd
Copy link
Author

@rogueloop have not yet found another solution.
Currently reading a template config file to a string and the replace the simple parts, such as server_name and ssl certificate paths.
For more "complex" things, such as adding directives at specific points or remove directives, I convert the string to a list with .splitlines() and then use .join() to merge it back to a single string before creating a file

@astrowonk
Copy link

astrowonk commented Aug 13, 2022

Yeah I want to edit the file(s) I have in sites-available and since they are partial (just a server block) that gets pulled into the main config with an include, clossplane throws nothing but errors. Kind of defeats the purpose ...

I could use the combine param on the nginix.conf file but then there's no way to split out just what's in sites-available.

Isn't putting server blocks insites-available a best practice? why wouldn't crossplane support editing those files?

@nikhilweee
Copy link

Same issue here. I wish to edit just the files in sites-available, I was hoping there was a way to do so.

@aliqandil
Copy link

aliqandil commented Aug 13, 2024

I do have a hack handy, I may later turn it into a full fledged python library, but here is the core idea:

Instead of the default lex function, I use this one:

import crossplane
def lex( self, filename = None ):
		it = ( line + '\n' for line in self.template.split("\n") )
		it = crossplane.lexer._lex_file_object(it)
		it = crossplane.lexer._balance_braces(it)
		for token, line, quoted in it:
			yield (token, line, quoted) 

Where self.template is my sites-available config as a string, then using mocking, I patch the code like this:

from unittest.mock import patch
with patch('crossplane.parser.lex', lex):
			payload = crossplane.parse(f"{self.template_name}.conf",
				comments=True,
				single=True,
				check_ctx=False,
				check_args=False
			)

This way I can fool the library that it's reading a partial config from a file named f"{self.template_name}.conf", without actually needing to write my config strings into a file and making sure they make sense in the context of the global nginx.conf file.

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

No branches or pull requests

5 participants