aboutsummaryrefslogtreecommitdiff
path: root/updater/utils.py
blob: bf54d0e0f8329a9dbe66715a20e5d2ca3667d536 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import logging


def record_transformer(public_suffixes):
    def transform(record):
        name = record["name"]
        suffixes = [suffix for suffix in public_suffixes if name.endswith(suffix)]
        suffix = suffixes[0] if suffixes else None

        if suffix:
            logging.debug(f"stripping {suffix} from {name} as it is a public suffix")

            record["name"] = name[: -len(suffix)]
            record["internal"] = "off"
            return record

        logging.debug(f"keeping {name} as it is not a public suffix")
        record["internal"] = "on"
        return record

    return transform