Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow all parameter properties #83

Merged
merged 3 commits into from
Aug 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions stacker/blueprints/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,38 @@ def get_local_parameters(parameter_def, parameters):

return local

PARAMETER_PROPERTIES = {
'default': 'Default',
'description': 'Description',
'no_echo': 'NoEcho',
'allowed_values': 'AllowedValues',
'allowed_pattern': 'AllowedPattern',
'max_length': 'MaxLength',
'min_length': 'MinLength',
'max_value': 'MaxValue',
'min_value': 'MinValue',
'constaint_description': 'ConstraintDescription'
}


def build_parameter(name, properties):
"""Builds a troposphere Parameter with the given properties.

Args:
name (string): The name of the parameter.
properties (dict): Contains the properties that will be applied to the
parameter. See:
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html

Returns:
:class:`troposphere.Parameter`: The created parameter object.
"""
p = Parameter(name, Type=properties.get('type'))
for name, attr in PARAMETER_PROPERTIES.items():
if name in properties:
setattr(p, attr, properties[name])
return p


class Blueprint(object):
"""Base implementation for dealing with a troposphere template.
Expand Down Expand Up @@ -95,11 +127,7 @@ def setup_parameters(self):
return

for param, attrs in parameters.items():
p = Parameter(param,
Type=attrs.get('type'),
Description=attrs.get('description', ''))
if 'default' in attrs:
p.Default = attrs['default']
p = build_parameter(param, attrs)
t.add_parameter(p)

def import_mappings(self):
Expand Down
9 changes: 8 additions & 1 deletion stacker/tests/blueprints/test_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from stacker.blueprints.base import get_local_parameters
from stacker.blueprints.base import get_local_parameters, build_parameter
from stacker.exceptions import MissingLocalParameterException


Expand All @@ -27,3 +27,10 @@ def test_supplied_parameter(self):

local = get_local_parameters(parameter_def, parameters)
self.assertEquals(parameters, local)


class TestBuildParameter(unittest.TestCase):
def test_base_parameter(self):
p = build_parameter("BasicParam", {'type': 'String'})
p.validate()
self.assertEquals(p.Type, 'String')