def get_secret_password(username):
    'Get the password for the given user from the secret that CK created.'
    try:
        output = kubernetes_common.kubectl('get', 'secrets', '-n', AUTH_SECRET_NS, '--field-selector', 'type={}'.format(AUTH_SECRET_TYPE), '-o', 'json').decode('UTF-8')
    except CalledProcessError:
        token = None
        if (username == 'admin'):
            admin_kubeconfig = Path('/root/.kube/config')
            if admin_kubeconfig.exists():
                with admin_kubeconfig.open('r') as f:
                    data = safe_load(f)
                    try:
                        token = data['users'][0]['user']['token']
                    except (KeyError, ValueError):
                        pass
        return token
    except FileNotFoundError:
        return None
    secrets = json.loads(output)
    if ('items' in secrets):
        for secret in secrets['items']:
            try:
                data_b64 = secret['data']
                password_b64 = data_b64['password'].encode('UTF-8')
                username_b64 = data_b64['username'].encode('UTF-8')
            except (KeyError, TypeError):
                continue
            password = b64decode(password_b64).decode('UTF-8')
            secret_user = b64decode(username_b64).decode('UTF-8')
            if (username == secret_user):
                return password
    return None
Get the password for the given user from the secret that CK created.
def get_secret_password(username):
    
    try:
        output = kubernetes_common.kubectl('get', 'secrets', '-n', AUTH_SECRET_NS, '--field-selector', 'type={}'.format(AUTH_SECRET_TYPE), '-o', 'json').decode('UTF-8')
    except CalledProcessError:
        token = None
        if (username == 'admin'):
            admin_kubeconfig = Path('/root/.kube/config')
            if admin_kubeconfig.exists():
                with admin_kubeconfig.open('r') as f:
                    data = safe_load(f)
                    try:
                        token = data['users'][0]['user']['token']
                    except (KeyError, ValueError):
                        pass
        return token
    except FileNotFoundError:
        return None
    secrets = json.loads(output)
    if ('items' in secrets):
        for secret in secrets['items']:
            try:
                data_b64 = secret['data']
                password_b64 = data_b64['password'].encode('UTF-8')
                username_b64 = data_b64['username'].encode('UTF-8')
            except (KeyError, TypeError):
                continue
            password = b64decode(password_b64).decode('UTF-8')
            secret_user = b64decode(username_b64).decode('UTF-8')
            if (username == secret_user):
                return password
    return None