示例#1
0
文件: fetcd.py 项目: GrimDerp/calico
def parse_tags(profile_id, raw_json):
    tags = json_decoder.decode(raw_json)
    try:
        common.validate_tags(profile_id, tags)
    except ValidationFailed:
        _log.exception("Validation failed for profile %s tags : %s",
                       profile_id, tags)
        return None
    else:
        return tags
示例#2
0
文件: fetcd.py 项目: rowhit/calico
def parse_tags(profile_id, raw_json):
    tags = safe_decode_json(raw_json, log_tag="tags %s" % profile_id)
    try:
        common.validate_tags(profile_id, tags)
    except ValidationFailed:
        _log.exception("Validation failed for profile %s tags : %s", profile_id, tags)
        return None
    else:
        # The tags aren't in a top-level object so we need to manually
        # intern them here.
        return intern_list(tags)
示例#3
0
def parse_tags(profile_id, raw_json):
    tags = safe_decode_json(raw_json, log_tag="tags %s" % profile_id)
    try:
        common.validate_tags(profile_id, tags)
    except ValidationFailed:
        _log.exception("Validation failed for profile %s tags : %s",
                       profile_id, tags)
        return None
    else:
        # The tags aren't in a top-level object so we need to manually
        # intern them here.
        return intern_list(tags)
示例#4
0
    def test_validate_tags(self):
        profile_id = "valid_name-ok."
        tags = ["name", "_name-with.chars.-_"]
        common.validate_tags(profile_id, tags)

        with self.assertRaisesRegexp(ValidationFailed, "Invalid profile"):
            common.validate_tags('bad"value', tags)

        with self.assertRaisesRegexp(ValidationFailed,
                                     "Expected tags to be a list"):
            common.validate_tags(profile_id, "not a list")

        with self.assertRaisesRegexp(ValidationFailed,
                                     "Expected tag.* to be a string"):
            common.validate_tags(profile_id, ["value", 3])

        with self.assertRaisesRegexp(ValidationFailed, "Invalid tag"):
            common.validate_tags(profile_id, ["value", "bad value"])
示例#5
0
    def test_validate_tags(self):
        profile_id = "valid_name-ok."
        tags = [ "name", "_name-with.chars.-_" ]
        common.validate_tags(profile_id, tags)

        with self.assertRaisesRegexp(ValidationFailed,
                                     "Invalid profile"):
            common.validate_tags('bad"value', tags)

        with self.assertRaisesRegexp(ValidationFailed,
                                     "Expected tags to be a list"):
            common.validate_tags(profile_id, "not a list")

        with self.assertRaisesRegexp(ValidationFailed,
                                     "Expected tag.* to be a string"):
            common.validate_tags(profile_id, ["value", 3])

        with self.assertRaisesRegexp(ValidationFailed,
                                     "Invalid tag"):
            common.validate_tags(profile_id, ["value", "bad value"])
示例#6
0
文件: fetcd.py 项目: kgrvamsi/calico
def parse_if_tags(etcd_node):
    m = TAGS_KEY_RE.match(etcd_node.key)
    if m:
        # Got some tags.
        profile_id = m.group("profile_id")
        if etcd_node.action == "delete":
            tags = None
        else:
            tags = json_decoder.decode(etcd_node.value)
            try:
                common.validate_tags(tags)
            except ValidationFailed:
                _log.exception("Validation failed for profile %s tags : %s",
                               profile_id, tags)
                return profile_id, None

        _log.debug("Found tags for profile %s : %s", profile_id, tags)

        return profile_id, tags
    return None, None