def tags_spec(self): # http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html#tag-restrictions # Keys = 127 UTF-8 '^aws:' reserved. Values = 255 UTF-8 return dictof( valid_string_spec(validators.regexed("^.{0,127}$")) , formatted(string_spec(), after_format=valid_string_spec(validators.regexed("^(?!aws:).{0,255}$")), formatter=MergedOptionStringFormatter) )
def environment_spec(self): """Spec for each environment""" return create_spec(Environment , account_id = required(or_spec(string_spec(), valid_string_spec(validators.regexed("\d+")))) , region = defaulted(string_spec(), "ap-southeast-2") , vars = dictionary_spec() )
def environment_spec(self): """Spec for each environment""" return create_spec(stack_objs.Environment , account_id = required(or_spec(valid_string_spec(validators.regexed("\d+")), integer_spec())) , region = defaulted(string_spec(), "ap-southeast-2") , vars = dictionary_spec() , tags = self.tags_spec )
def image_name_spec(self): """ Image names are constrained by what docker wants And by the fact that option_merge means we can't have keys with dots in them. Otherwise if we have something like "ubuntu14.04" as an image, then when we do {images.ubuntu14.04.image_name} it'll look for config["images"]["ubuntu14"]["04"]["image_name"] instead of config["images"]["ubuntu14.04"]["image_name"] which is unlikely to be the desired result. """ return valid_string_spec( validators.no_whitespace(), validators.regexed("^[a-zA-Z][a-zA-Z0-9-_\.]*$"))
def container_name_spec(self): """Just needs to be ascii""" return valid_string_spec(validators.no_whitespace(), validators.regexed("^[a-zA-Z][a-zA-Z0-9-_\.]*$"))
validators.has_only_one_of(["Resource", "NotResource"]) ]) # http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/protect-stack-resources.html#stack-policy-reference policy_json_spec = lambda: sb.set_options(Statement=sb.listof( policy_set_options( Effect=sb.string_choice_spec(choices=["Deny", "Allow"]), Action=sb.optional_spec( sb.listof( sb.string_choice_spec(choices=[ "Update:Modify", "Update:Replace", "Update:Delete", "Update:*" ]))), NotAction=sb.optional_spec( sb.listof( sb.string_choice_spec(choices=[ "Update:Modify", "Update:Replace", "Update:Delete", "Update:*" ]))), Principal=sb.valid_string_spec(validators.regexed("^\*$")), Resource=sb.optional_spec( sb.listof( sb.valid_string_spec( validators.regexed(r"^(LogicalResourceId/.*|\*)$")))), NotResource=sb.optional_spec( sb.listof( sb.valid_string_spec( validators.regexed(r"^(LogicalResourceId/.*|\*)$")))), Condition=sb.optional_spec(sb.dictionary_spec()))))
regex3 = mock.Mock(name="regex3") regex4 = mock.Mock(name="regex4") compiled_regex1 = mock.Mock(name="compiled_regex1") compiled_regex2 = mock.Mock(name="compiled_regex2") compiled_regex3 = mock.Mock(name="compiled_regex3") compiled_regex4 = mock.Mock(name="compiled_regex4") matched = { regex1: compiled_regex1, regex2: compiled_regex2 , regex3: compiled_regex3, regex4: compiled_regex4 } fake_compile = mock.Mock(name="compile") fake_compile.side_effect = lambda reg: matched[reg] with mock.patch("re.compile", fake_compile): validator = va.regexed(regex1, regex2, regex3, regex4) self.assertEqual( validator.regexes , [ (regex1, compiled_regex1) , (regex2, compiled_regex2) , (regex3, compiled_regex3) , (regex4, compiled_regex4) ] ) it "returns the value if it matches all the regexes": self.assertEqual(va.regexed("[a-z]+", "asdf", "a.+").normalise(self.meta, "asdf"), "asdf") it "complains if the value doesn't match any of the regexes": val = "meh" with self.fuzzyAssertRaisesError(BadSpecValue, "Expected value to match regex, it didn't", spec="blah", meta=self.meta, val=val):
def container_name_spec(self): """Just needs to be ascii""" return valid_string_spec( validators.no_whitespace(), validators.regexed("^[a-zA-Z][a-zA-Z0-9-_\.]*$"))
listof, filename_spec, dictof, dictionary_spec, required, integer_spec, directory_spec, delayed, Spec, ) from input_algorithms.dictobj import dictobj from textwrap import dedent import six valid_import_name = regexed("[a-zA-Z_][a-zA-Z_0-9]*(\.[a-zA-Z_][a-zA-Z_0-9]*)*:[a-zA-Z_][a-zA-Z_0-9]") formatted_dict_or_string_or_list = lambda: match_spec( (six.string_types, formatted(string_spec(), MergedOptionStringFormatter)), ((list,), lambda: listof(formatted_dict_or_string_or_list())), fallback=lambda: dictof(string_spec(), formatted_dict_or_string_or_list()), ) class dashboards_spec(Spec): def normalise(self, meta, val): val = dictionary_spec().normalise(meta, val).as_dict() if "/" not in val: val["/"] = {"is_index": True} return dictof(string_spec(), dashboard_spec()).normalise(meta, val)