Escape EMR template fields to avoid invalid XML responses (#1467)

I had an EMR step that contained a `&` and this caused the ListStep call to fail.

I've added the `| escape` filter to handle it in this case and a few other cases that look like they could suffer the same fate.
This commit is contained in:
Ash Berlin-Taylor 2018-03-21 15:57:50 +00:00 committed by Jack Danger
parent 508b392697
commit 1b20f21a75
2 changed files with 14 additions and 14 deletions

View File

@ -462,10 +462,10 @@ DESCRIBE_JOB_FLOWS_TEMPLATE = """<DescribeJobFlowsResponse xmlns="http://elastic
<ScriptBootstrapAction>
<Args>
{% for arg in bootstrap_action.args %}
<member>{{ arg }}</member>
<member>{{ arg | escape }}</member>
{% endfor %}
</Args>
<Path>{{ bootstrap_action.script_path }}</Path>
<Path>{{ bootstrap_action.script_path | escape }}</Path>
</ScriptBootstrapAction>
</BootstrapActionConfig>
</member>
@ -568,12 +568,12 @@ DESCRIBE_JOB_FLOWS_TEMPLATE = """<DescribeJobFlowsResponse xmlns="http://elastic
<MainClass>{{ step.main_class }}</MainClass>
<Args>
{% for arg in step.args %}
<member>{{ arg }}</member>
<member>{{ arg | escape }}</member>
{% endfor %}
</Args>
<Properties/>
</HadoopJarStep>
<Name>{{ step.name }}</Name>
<Name>{{ step.name | escape }}</Name>
</StepConfig>
</member>
{% endfor %}
@ -596,7 +596,7 @@ DESCRIBE_STEP_TEMPLATE = """<DescribeStepResponse xmlns="http://elasticmapreduce
<Config>
<Args>
{% for arg in step.args %}
<member>{{ arg }}</member>
<member>{{ arg | escape }}</member>
{% endfor %}
</Args>
<Jar>{{ step.jar }}</Jar>
@ -605,13 +605,13 @@ DESCRIBE_STEP_TEMPLATE = """<DescribeStepResponse xmlns="http://elasticmapreduce
{% for key, val in step.properties.items() %}
<member>
<key>{{ key }}</key>
<value>{{ val }}</value>
<value>{{ val | escape }}</value>
</member>
{% endfor %}
</Properties>
</Config>
<Id>{{ step.id }}</Id>
<Name>{{ step.name }}</Name>
<Name>{{ step.name | escape }}</Name>
<Status>
<!-- does not exist for botocore 1.4.28
<FailureDetails>
@ -646,7 +646,7 @@ LIST_BOOTSTRAP_ACTIONS_TEMPLATE = """<ListBootstrapActionsResponse xmlns="http:/
<member>
<Args>
{% for arg in bootstrap_action.args %}
<member>{{ arg }}</member>
<member>{{ arg | escape }}</member>
{% endfor %}
</Args>
<Name>{{ bootstrap_action.name }}</Name>
@ -760,22 +760,22 @@ LIST_STEPS_TEMPLATE = """<ListStepsResponse xmlns="http://elasticmapreduce.amazo
<Config>
<Args>
{% for arg in step.args %}
<member>{{ arg }}</member>
<member>{{ arg | escape }}</member>
{% endfor %}
</Args>
<Jar>{{ step.jar }}</Jar>
<Jar>{{ step.jar | escape }}</Jar>
<MainClass/>
<Properties>
{% for key, val in step.properties.items() %}
<member>
<key>{{ key }}</key>
<value>{{ val }}</value>
<value>{{ val | escape }}</value>
</member>
{% endfor %}
</Properties>
</Config>
<Id>{{ step.id }}</Id>
<Name>{{ step.name }}</Name>
<Name>{{ step.name | escape }}</Name>
<Status>
<!-- does not exist for botocore 1.4.28
<FailureDetails>

View File

@ -443,7 +443,7 @@ def test_bootstrap_actions():
BootstrapAction(
name='bs1',
path='path/to/script',
bootstrap_action_args=['arg1', 'arg2']),
bootstrap_action_args=['arg1', 'arg2&arg3']),
BootstrapAction(
name='bs2',
path='path/to/anotherscript',
@ -551,7 +551,7 @@ def test_steps():
input='s3n://elasticmapreduce/samples/wordcount/input',
output='s3n://output_bucket/output/wordcount_output'),
StreamingStep(
name='My wordcount example2',
name='My wordcount example & co.',
mapper='s3n://elasticmapreduce/samples/wordcount/wordSplitter2.py',
reducer='aggregate',
input='s3n://elasticmapreduce/samples/wordcount/input2',