def get_domain_search()

in sagemaker_studio_sparkmagic_lib/utils.py [0:0]


def get_domain_search(region):
    """
    returns domain search by parsing /etc/resolv.conf
    see https://man7.org/linux/man-pages/man5/resolv.conf.5.html
    This value is used in kerberos config

    NOTE: we should ideally read this information from studio metadata file as /etc/resolv.conf may not
    be in all types of environments. Will be done as follow up
    """
    default_search = get_default_domain_search(region)
    file = "/etc/resolv.conf"
    try:
        with open(file, "r") as resolvconf:
            for line in resolvconf.readlines():
                line = line.split("#", 1)[0]
                line = line.rstrip()
                if "search" in line:
                    return line.split()[1]
    except IOError:
        logger.warning(
            f"Unable to read {file}. Using default value for domain search name: {default_search}"
        )

    return default_search