Example #1
0
def matches_partner_regex(alias, product_name):
    for alias_pattern, product_pattern in PARTNER_ALIASES_REGEX.items():
        alias_match = re.match(alias_pattern, alias)
        product_match = re.match(product_pattern, product_name)
        if alias_match and product_match and alias_match.groups()[0] == product_match.groups()[0]:
            return True
    return False
Example #2
0
def check_product_names_match_aliases(context):
    """Make sure we don't do any cross-product/channel alias update"""
    aliases = context.task["payload"]["aliases_entries"]
    all_partner_aliases = "|".join(PARTNER_ALIASES_REGEX.keys())

    validations = []
    for alias, product_name in aliases.items():
        if alias in ALIASES_REGEXES.keys():
            validations.append(matches(product_name, ALIASES_REGEXES[alias]))
        elif re.match(all_partner_aliases, alias):
            validations.append(matches_partner_regex(alias, product_name))
        else:
            raise TaskVerificationError("Unrecognized alias:{}".format(alias))

    if not all(validations):
        raise TaskVerificationError("The product/alias pairs are corrupt: {}".format(aliases))