From 88e1c12b23230233b39e21bd1169c2c501a928f4 Mon Sep 17 00:00:00 2001 From: Felipe Monteiro Date: Mon, 24 Sep 2018 22:43:06 +0100 Subject: [PATCH] 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 --- deckhand/control/middleware.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/deckhand/control/middleware.py b/deckhand/control/middleware.py index cea31fcd..a776b6b1 100644 --- a/deckhand/control/middleware.py +++ b/deckhand/control/middleware.py @@ -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))