Add additional documentation.

This commit is contained in:
Felipe Monteiro 2017-07-11 16:03:36 +01:00
parent ac4fc210ee
commit e352b607ee
3 changed files with 21 additions and 3 deletions

View File

@ -63,8 +63,7 @@ class BaseResource(object):
return None
try:
json_body = json.loads(raw_body.decode('utf-8'))
return json_body
return json.loads(raw_body.decode('utf-8'))
except json.JSONDecodeError as jex:
raise errors.InvalidFormat("%s: Invalid JSON in body: %s" % (
req.path, jex))

View File

@ -28,6 +28,9 @@ class SecretSubstitution(object):
substituted or "forward-repalced" into the YAML file. The end result is a
YAML file containing all necessary secrets to be handed off to other
services.
:param data: YAML data that requires secrets to be validated, merged and
consolidated.
"""
def __init__(self, data):
@ -86,6 +89,8 @@ class SecretSubstitution(object):
'missing from the YAML data: "%s".' % (
missing_attr, dest, sub_data))
# TODO(fm577c): Query Deckhand API to validate "src" values.
def _multi_getattr(self, multi_key, substitutable_data):
"""Iteratively check for nested attributes in the YAML data.

View File

@ -37,6 +37,19 @@ class TestSecretSubtitution(testtools.TestCase):
self.data = yaml.safe_load(yaml_data)
def _corrupt_data(self, key):
"""Corrupt test data to check that pre-validation works.
Corrupt data by removing a key from the document. Each key must
correspond to a value that is a dictionary.
:param key: The document key to be removed. The key can have the
following formats:
* 'data' => document.pop('data')
* 'metadata.name' => document['metadata'].pop('name')
* 'metadata.substitutions.0.dest' =>
document['metadata']['substitutions'][0].pop('dest')
:returns: Corrupted YAML data.
"""
corrupted_data = copy.deepcopy(self.data)
if '.' in key:
@ -53,9 +66,10 @@ class TestSecretSubtitution(testtools.TestCase):
else:
corrupted_data.pop(key)
return yaml.safe_dump(corrupted_data)
return self._format_data(corrupted_data)
def _format_data(self, data=None):
"""Re-formats dict data as YAML to pass to ``SecretSubstitution``."""
if data is None:
data = self.data
return yaml.safe_dump(data)