Don't require user params on template validation
Fixes #161 Change-Id: Ia7e1a83043f8d175e320bfd52aa64cb6f62ead90 Signed-off-by: Tomas Sedovic <tomas@sedovic.cz>
This commit is contained in:
parent
cf56c2613b
commit
466e9983d0
@ -131,7 +131,6 @@ class EngineManager(manager.Manager):
|
|||||||
arg3 -> Template of stack you want to create.
|
arg3 -> Template of stack you want to create.
|
||||||
arg4 -> Params passed from API.
|
arg4 -> Params passed from API.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
auth.authenticate(context)
|
auth.authenticate(context)
|
||||||
|
|
||||||
logger.info('validate_template')
|
logger.info('validate_template')
|
||||||
@ -139,20 +138,29 @@ class EngineManager(manager.Manager):
|
|||||||
msg = _("No Template provided.")
|
msg = _("No Template provided.")
|
||||||
return webob.exc.HTTPBadRequest(explanation=msg)
|
return webob.exc.HTTPBadRequest(explanation=msg)
|
||||||
|
|
||||||
stack_name = 'validate'
|
tmpl = parser.Template(template)
|
||||||
try:
|
resources = template.get('Resources', [])
|
||||||
tmpl = parser.Template(template)
|
|
||||||
user_params = parser.Parameters(stack_name, tmpl, params)
|
|
||||||
s = parser.Stack(context, stack_name, tmpl, user_params)
|
|
||||||
except KeyError as ex:
|
|
||||||
res = ('A Fn::FindInMap operation referenced '
|
|
||||||
'a non-existent map [%s]' % str(ex))
|
|
||||||
|
|
||||||
result = {'Description': 'Malformed Query Response [%s]' % (res),
|
if not resources:
|
||||||
'Parameters': []}
|
return {'Error': 'At least one Resources member must be defined.'}
|
||||||
else:
|
|
||||||
result = s.validate()
|
|
||||||
|
|
||||||
|
for res in resources.values():
|
||||||
|
if not res.get('Type'):
|
||||||
|
return {'Error':
|
||||||
|
'Every Resources object must contain a Type member.'}
|
||||||
|
|
||||||
|
parameters = []
|
||||||
|
for param_key, param in template.get('Parameters', {}).items():
|
||||||
|
parameters.append({
|
||||||
|
'NoEcho': param.get('NoEcho', 'false'),
|
||||||
|
'ParameterKey': param_key,
|
||||||
|
'Description': param.get('Description', '')
|
||||||
|
})
|
||||||
|
|
||||||
|
result = {
|
||||||
|
'Description': template.get('Description', ''),
|
||||||
|
'Parameters': parameters,
|
||||||
|
}
|
||||||
return {'ValidateTemplateResult': result}
|
return {'ValidateTemplateResult': result}
|
||||||
|
|
||||||
def get_template(self, context, stack_name, params):
|
def get_template(self, context, stack_name, params):
|
||||||
|
@ -269,7 +269,7 @@ class validateTest(unittest.TestCase):
|
|||||||
res = dict(manager.
|
res = dict(manager.
|
||||||
validate_template(None, t, params)['ValidateTemplateResult'])
|
validate_template(None, t, params)['ValidateTemplateResult'])
|
||||||
print 'res %s' % res
|
print 'res %s' % res
|
||||||
self.assertEqual(res['Description'], 'Successfully validated')
|
self.assertEqual(res['Description'], 'test.')
|
||||||
|
|
||||||
def test_validate_ref_invalid(self):
|
def test_validate_ref_invalid(self):
|
||||||
t = json.loads(test_template_ref % 'WikiDatabasez')
|
t = json.loads(test_template_ref % 'WikiDatabasez')
|
||||||
@ -301,7 +301,7 @@ class validateTest(unittest.TestCase):
|
|||||||
manager = managers.EngineManager()
|
manager = managers.EngineManager()
|
||||||
res = dict(manager.
|
res = dict(manager.
|
||||||
validate_template(None, t, params)['ValidateTemplateResult'])
|
validate_template(None, t, params)['ValidateTemplateResult'])
|
||||||
self.assertEqual(res['Description'], 'Successfully validated')
|
self.assertEqual(res['Description'], 'test.')
|
||||||
|
|
||||||
def test_validate_findinmap_invalid(self):
|
def test_validate_findinmap_invalid(self):
|
||||||
t = json.loads(test_template_findinmap_invalid)
|
t = json.loads(test_template_findinmap_invalid)
|
||||||
|
Loading…
Reference in New Issue
Block a user