Add explicit start/end to Deckhand response middleware

Pegleg has linting rules dedicated to checking for explicit starts
and so on, so it makes sense that Deckhand just adds this in for
every response as it is a nice feature that better delineates
starting and endpoints points for individual YAML documents.

Change-Id: I6324cfa268ddf250a9c78cb663e7015a171bbc19
Related-Change: https://review.openstack.org/#/c/604123
This commit is contained in:
Felipe Monteiro 2018-09-24 22:43:06 +01:00
parent 3f39e639ea
commit 88e1c12b23
1 changed files with 7 additions and 2 deletions

View File

@ -163,6 +163,11 @@ class YAMLTranslator(HookableMiddlewareMixin, object):
if resp.status != '204 No Content':
resp.set_header('Content-Type', 'application/x-yaml')
kwargs = {
"explicit_start": True,
"explicit_end": True
}
for attr in ('body', 'data'):
if not hasattr(resp, attr):
continue
@ -170,6 +175,6 @@ class YAMLTranslator(HookableMiddlewareMixin, object):
resp_attr = getattr(resp, attr)
if isinstance(resp_attr, dict):
setattr(resp, attr, yaml.safe_dump(resp_attr))
setattr(resp, attr, yaml.safe_dump(resp_attr, **kwargs))
elif isinstance(resp_attr, (list, tuple)):
setattr(resp, attr, yaml.safe_dump_all(resp_attr))
setattr(resp, attr, yaml.safe_dump_all(resp_attr, **kwargs))