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

Fix mustache escaping #262

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "chevron"]
path = chevron
url = https://github.com/taylorjacklespriggs/chevron-1.git
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ lint:
@./lint

update:
@git submodule init
@git submodule update
@pip install -r requirements-dev.txt
@pip install -r requirements.txt
@python setup.py clean --all
Expand Down
1 change: 1 addition & 0 deletions chevron
Submodule chevron added at e8859e
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Pint>=0.16.0,<0.17.0
PyYAML==5.4.1,<6.0.0
backoff>=1.10.0,<2.0.0
boto3==1.16.34,<2.0.0
chevron>=0.14.0,<1.0.0
click>=8.0.0
docker>=4.4.0,<5.0.0
ipython>=5.0.0
Expand Down
8 changes: 3 additions & 5 deletions sigopt/orchestrate/template/service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chevron
from sigopt.vendored import chevron

from ..services.base import Service

Expand All @@ -7,9 +7,6 @@ class TemplateService(Service):
def _dockerfile_escape(self, s):
return s.replace('\\', '\\\\').replace('\n', '\\\n')

def _escape_args(self, args, escape):
return {k: escape(v) for k, v in args.items()}

def render_dockerfile_template_from_file(self, relative_filename, template_args):
return self._raw_render_template_from_file(self._dockerfile_escape, relative_filename, template_args)

Expand All @@ -23,5 +20,6 @@ def _raw_render_template_from_file(self, escape, relative_filename, template_arg
template = self.services.resource_service.read('template', relative_filename).decode("utf-8")
return chevron.render(
template=template,
data=self._escape_args(template_args, escape),
data=template_args,
escape=escape,
)
1 change: 1 addition & 0 deletions sigopt/vendored/chevron
2 changes: 0 additions & 2 deletions test/orchestrate/template/service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ def test_dockerfile_escape_newline(self, template_service):
# Ensure that the newline is preceded by a backslash, so Dockerfile doesn't interpret it as a new command
assert 'ENV SIGOPT_HOME "\\\nCOPY ."' in rendered

@pytest.mark.skip(reason="chevron doesn't handle quotes gracefully")
def test_dockerfile_escape_backslash(self, template_service):
rendered = template_service.render_dockerfile_template_from_file('model_packer/Dockerfile.ms', dict(
sigopt_home='echo ""\\',
))
# Ensure that the trailing backslash is escaped, and not interpreted as an escape sequence for the newline
assert 'ENV SIGOPT_HOME "echo ""\\\\"\n' in rendered

@pytest.mark.skip(reason="chevron doesn't handle quotes gracefully")
def test_yaml_escape_quotes(self, template_service):
rendered = template_service.render_yaml_template_from_file('test.yml.ms', dict(
endpoint_url='"', base64_encoded_ca_cert='"',
Expand Down