awscli2/ruamel-yaml-0.17.32.patch

114 lines
4.5 KiB
Diff

diff --git a/awscli/customizations/cloudformation/yamlhelper.py b/awscli/customizations/cloudformation/yamlhelper.py
index 8e3b291..a926d53 100644
--- a/awscli/customizations/cloudformation/yamlhelper.py
+++ b/awscli/customizations/cloudformation/yamlhelper.py
@@ -91,8 +91,14 @@ def yaml_dump(dict_to_dump):
yaml.Representer = FlattenAliasRepresenter
_add_yaml_1_1_boolean_resolvers(yaml.Resolver)
yaml.Representer.add_representer(OrderedDict, _dict_representer)
+ yaml.Representer.add_representer(dict, _dict_representer)
- return dump_yaml_to_str(yaml, dict_to_dump)
+ result = dump_yaml_to_str(yaml, dict_to_dump)
+
+ # let other YAML instances use the default dict representer
+ yaml.Representer.add_representer(dict, ruamel.yaml.representer.SafeRepresenter.represent_dict)
+
+ return result
def _dict_constructor(loader, node):
diff --git a/awscli/customizations/eks/kubeconfig.py b/awscli/customizations/eks/kubeconfig.py
index 2d302d8..d00c4a8 100644
--- a/awscli/customizations/eks/kubeconfig.py
+++ b/awscli/customizations/eks/kubeconfig.py
@@ -45,7 +45,7 @@ def _get_new_kubeconfig_content():
("contexts", []),
("current-context", ""),
("kind", "Config"),
- ("preferences", OrderedDict()),
+ ("preferences", {}),
("users", []),
]
)
@@ -135,7 +135,7 @@ class KubeconfigValidator(object):
for key, value in self._validation_content.items():
if key in config.content and type(config.content[key]) == list:
for element in config.content[key]:
- if not isinstance(element, OrderedDict):
+ if not isinstance(element, dict):
raise KubeconfigCorruptedError(
f"Entry in {key} not a {dict}. "
)
diff --git a/awscli/customizations/eks/ordered_yaml.py b/awscli/customizations/eks/ordered_yaml.py
index f9b1a11..0cce12e 100644
--- a/awscli/customizations/eks/ordered_yaml.py
+++ b/awscli/customizations/eks/ordered_yaml.py
@@ -50,10 +50,18 @@ def ordered_yaml_dump(to_dump, stream=None):
:type stream: file
"""
yaml = ruamel.yaml.YAML(typ="safe", pure=True)
+ yaml.width = 99999
yaml.default_flow_style = False
yaml.Representer.add_representer(OrderedDict, _ordered_representer)
+ yaml.Representer.add_representer(dict, _ordered_representer)
if stream is None:
- return dump_yaml_to_str(yaml, to_dump)
+ result = dump_yaml_to_str(yaml, to_dump)
+ else:
+ result = None
+ yaml.dump(to_dump, stream)
- yaml.dump(to_dump, stream)
+ # let other YAML instances use the default dict representer
+ yaml.Representer.add_representer(dict, ruamel.yaml.representer.SafeRepresenter.represent_dict)
+
+ return result
diff --git a/tests/unit/customizations/cloudformation/test_yamlhelper.py b/tests/unit/customizations/cloudformation/test_yamlhelper.py
index e7ac758..b9632e9 100644
--- a/tests/unit/customizations/cloudformation/test_yamlhelper.py
+++ b/tests/unit/customizations/cloudformation/test_yamlhelper.py
@@ -130,28 +130,10 @@ class TestYaml(BaseYAMLTest):
' Name: name1\n'
)
output_dict = yaml_parse(input_template)
- expected_dict = OrderedDict(
- [
- (
- 'B_Resource',
- OrderedDict(
- [
- ('Key2', {'Name': 'name2'}),
- ('Key1', {'Name': 'name1'}),
- ]
- ),
- ),
- (
- 'A_Resource',
- OrderedDict(
- [
- ('Key2', {'Name': 'name2'}),
- ('Key1', {'Name': 'name1'}),
- ]
- ),
- ),
- ]
- )
+ expected_dict = {
+ 'B_Resource': {'Key2': {'Name': 'name2'}, 'Key1': {'Name': 'name1'}},
+ 'A_Resource': {'Key2': {'Name': 'name2'}, 'Key1': {'Name': 'name1'}}
+ }
self.assertEqual(expected_dict, output_dict)
output_template = yaml_dump(output_dict)
@@ -165,7 +147,7 @@ class TestYaml(BaseYAMLTest):
<<: *base
"""
output = yaml_parse(test_yaml)
- self.assertTrue(isinstance(output, OrderedDict))
+ self.assertTrue(isinstance(output, dict))
self.assertEqual(output.get('test').get('property'), 'value')
def test_unroll_yaml_anchors(self):