@Test void testGetUserAuthInfo() { Config config = getTestKubeConfig(); Context context = config.getContexts().get(0).getContext(); AuthInfo authInfo = KubeConfigUtils.getUserAuthInfo(config, context); assertNotNull(authInfo); assertEquals("test-token-2", authInfo.getToken()); }
public static AuthInfo getUserAuthInfo(Config config, Context context) { AuthInfo authInfo = null; if (config != null && context != null) { String user = context.getUser(); if (user != null) { List<NamedAuthInfo> users = config.getUsers(); if (users != null) { authInfo = users.stream() .filter(u -> u.getName().equals(user)) .findAny() .map(NamedAuthInfo::getUser) .orElse(null); } } } return authInfo; }
KubeConfigUtils { public static AuthInfo getUserAuthInfo(Config config, Context context) { AuthInfo authInfo = null; if (config != null && context != null) { String user = context.getUser(); if (user != null) { List<NamedAuthInfo> users = config.getUsers(); if (users != null) { authInfo = users.stream() .filter(u -> u.getName().equals(user)) .findAny() .map(NamedAuthInfo::getUser) .orElse(null); } } } return authInfo; } }
KubeConfigUtils { public static AuthInfo getUserAuthInfo(Config config, Context context) { AuthInfo authInfo = null; if (config != null && context != null) { String user = context.getUser(); if (user != null) { List<NamedAuthInfo> users = config.getUsers(); if (users != null) { authInfo = users.stream() .filter(u -> u.getName().equals(user)) .findAny() .map(NamedAuthInfo::getUser) .orElse(null); } } } return authInfo; } private  KubeConfigUtils(); }
KubeConfigUtils { public static AuthInfo getUserAuthInfo(Config config, Context context) { AuthInfo authInfo = null; if (config != null && context != null) { String user = context.getUser(); if (user != null) { List<NamedAuthInfo> users = config.getUsers(); if (users != null) { authInfo = users.stream() .filter(u -> u.getName().equals(user)) .findAny() .map(NamedAuthInfo::getUser) .orElse(null); } } } return authInfo; } private  KubeConfigUtils(); static Config parseConfig(File file); static Config parseConfigFromString(String contents); static NamedContext getCurrentContext(Config config); static String getUserToken(Config config, Context context); static AuthInfo getUserAuthInfo(Config config, Context context); static Cluster getCluster(Config config, Context context); static int getNamedUserIndexFromConfig(Config config, String userName); static void persistKubeConfigIntoFile(Config kubeConfig, String kubeConfigPath); }
KubeConfigUtils { public static AuthInfo getUserAuthInfo(Config config, Context context) { AuthInfo authInfo = null; if (config != null && context != null) { String user = context.getUser(); if (user != null) { List<NamedAuthInfo> users = config.getUsers(); if (users != null) { authInfo = users.stream() .filter(u -> u.getName().equals(user)) .findAny() .map(NamedAuthInfo::getUser) .orElse(null); } } } return authInfo; } private  KubeConfigUtils(); static Config parseConfig(File file); static Config parseConfigFromString(String contents); static NamedContext getCurrentContext(Config config); static String getUserToken(Config config, Context context); static AuthInfo getUserAuthInfo(Config config, Context context); static Cluster getCluster(Config config, Context context); static int getNamedUserIndexFromConfig(Config config, String userName); static void persistKubeConfigIntoFile(Config kubeConfig, String kubeConfigPath);  }