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:
parent
3f39e639ea
commit
88e1c12b23
|
@ -163,6 +163,11 @@ class YAMLTranslator(HookableMiddlewareMixin, object):
|
||||||
if resp.status != '204 No Content':
|
if resp.status != '204 No Content':
|
||||||
resp.set_header('Content-Type', 'application/x-yaml')
|
resp.set_header('Content-Type', 'application/x-yaml')
|
||||||
|
|
||||||
|
kwargs = {
|
||||||
|
"explicit_start": True,
|
||||||
|
"explicit_end": True
|
||||||
|
}
|
||||||
|
|
||||||
for attr in ('body', 'data'):
|
for attr in ('body', 'data'):
|
||||||
if not hasattr(resp, attr):
|
if not hasattr(resp, attr):
|
||||||
continue
|
continue
|
||||||
|
@ -170,6 +175,6 @@ class YAMLTranslator(HookableMiddlewareMixin, object):
|
||||||
resp_attr = getattr(resp, attr)
|
resp_attr = getattr(resp, attr)
|
||||||
|
|
||||||
if isinstance(resp_attr, dict):
|
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)):
|
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))
|
||||||
|
|
Loading…
Reference in New Issue