def execute_kinit_cmd()

in Templates/kerberosSideCar/krb_side_car.py [0:0]


def execute_kinit_cmd(username_arg, password_arg, directory_name_arg):
    """
    Get kerberos tickets by executing the kinit command
    Kerberos tickets get saved to ticket cache specified by default_ccache_name in
    krb5.conf
    Kerberos tickets must be protected

    :param username_arg: Username in Active Directory domain
    :type username_arg: basestring
    :param password_arg: Plain text password of above user
    :type password_arg: basestring
    :param directory_name_arg: Directory name of AD domain such as example.com
    :type directory_name_arg: basestring
    :return: Kinit output visible in console
    :rtype: Nothing, also does not throw exceptions to allow retries
    """
    with subprocess.Popen(
            [
                "kinit", "-V",
                "%s@%s" % (username_arg, directory_name_arg.upper()),
            ],
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            encoding="utf-8",
            shell=False,
    ) as proc:
        output, error = proc.communicate(input="%s\n" % password_arg, timeout=15)
        if proc.returncode != 0:
            print("ERROR** kinit failed %d %s %s" % (proc.returncode, error,
                                                     output), flush=True)
            raise NameError("ERROR** kinit failed")

    return