/** * Convert the given user name formatted for the registry. * * @param shortUserName * @return converted user name */ public static String registryUser(String shortUserName) { String encodedName = encodeForRegistry(shortUserName); // DNS name doesn't allow "_", replace it with "-" encodedName = RegistryUtils.convertUsername(encodedName); return encodedName.replace("_", "-"); }
/** * Buld the user path -switches to the system path if the user is "". * It also cross-converts the username to ascii via punycode * @param username username or "" * @return the path to the user */ public static String homePathForUser(String username) { Preconditions.checkArgument(username != null, "null user"); // catch recursion if (username.startsWith(RegistryConstants.PATH_USERS)) { return username; } if (username.isEmpty()) { return RegistryConstants.PATH_SYSTEM_SERVICES; } // convert username to registry name String convertedName = convertUsername(username); return RegistryPathUtils.join(RegistryConstants.PATH_USERS, encodeForRegistry(convertedName)); }
/** * Buld the user path -switches to the system path if the user is "". * It also cross-converts the username to ascii via punycode * @param username username or "" * @return the path to the user */ public static String homePathForUser(String username) { Preconditions.checkArgument(username != null, "null user"); // catch recursion if (username.startsWith(RegistryConstants.PATH_USERS)) { return username; } if (username.isEmpty()) { return RegistryConstants.PATH_SYSTEM_SERVICES; } // convert username to registry name String convertedName = convertUsername(username); return RegistryPathUtils.join(RegistryConstants.PATH_USERS, encodeForRegistry(convertedName)); }
/** * Buld the user path -switches to the system path if the user is "". * It also cross-converts the username to ascii via punycode * @param username username or "" * @return the path to the user */ public static String homePathForUser(String username) { Preconditions.checkArgument(username != null, "null user"); // catch recursion if (username.startsWith(RegistryConstants.PATH_USERS)) { return username; } if (username.isEmpty()) { return RegistryConstants.PATH_SYSTEM_SERVICES; } // convert username to registry name String convertedName = convertUsername(username); return RegistryPathUtils.join(RegistryConstants.PATH_USERS, encodeForRegistry(convertedName)); }
/** * Buld the user path -switches to the system path if the user is "". * It also cross-converts the username to ascii via punycode * @param username username or "" * @return the path to the user */ public static String homePathForUser(String username) { Preconditions.checkArgument(username != null, "null user"); // catch recursion if (username.startsWith(RegistryConstants.PATH_USERS)) { return username; } if (username.isEmpty()) { return RegistryConstants.PATH_SYSTEM_SERVICES; } // convert username to registry name String convertedName = convertUsername(username); return RegistryPathUtils.join(RegistryConstants.PATH_USERS, encodeForRegistry(convertedName)); }
/** * Qualify a user. * <ol> * <li> <code>"~"</code> maps to user home path home</li> * <li> <code>"~user"</code> maps to <code>/users/$user</code></li> * <li> <code>"/"</code> maps to <code>/services/</code></li> * </ol> * @param user the username * @return the base path */ public static String qualifyUser(String user) { // qualify the user String t = user.trim(); if (t.startsWith("/")) { // already resolved return t; } else if (t.equals("~")) { // self return currentUsernameUnencoded(); } else if (t.startsWith("~")) { // another user // convert username to registry name String convertedName = convertUsername(t.substring(1)); return RegistryPathUtils.join(RegistryConstants.PATH_USERS, encodeForRegistry(convertedName)); } else { return "/" + t; } }
/** * Qualify a user. * <ol> * <li> <code>"~"</code> maps to user home path home</li> * <li> <code>"~user"</code> maps to <code>/users/$user</code></li> * <li> <code>"/"</code> maps to <code>/services/</code></li> * </ol> * @param user the username * @return the base path */ public static String qualifyUser(String user) { // qualify the user String t = user.trim(); if (t.startsWith("/")) { // already resolved return t; } else if (t.equals("~")) { // self return currentUsernameUnencoded(); } else if (t.startsWith("~")) { // another user // convert username to registry name String convertedName = convertUsername(t.substring(1)); return RegistryPathUtils.join(RegistryConstants.PATH_USERS, encodeForRegistry(convertedName)); } else { return "/" + t; } }
@Test public void testShortenUsername() throws Throwable { assertEquals("hbase", RegistryUtils.convertUsername("hbase@HADOOP.APACHE.ORG")); assertEquals("hbase", RegistryUtils.convertUsername("hbase/localhost@HADOOP.APACHE.ORG")); assertEquals("hbase", RegistryUtils.convertUsername("hbase")); assertEquals("hbase user", RegistryUtils.convertUsername("hbase user")); }
@Test public void testShortenUsername() throws Throwable { assertEquals("hbase", RegistryUtils.convertUsername("hbase@HADOOP.APACHE.ORG")); assertEquals("hbase", RegistryUtils.convertUsername("hbase/localhost@HADOOP.APACHE.ORG")); assertEquals("hbase", RegistryUtils.convertUsername("hbase")); assertEquals("hbase user", RegistryUtils.convertUsername("hbase user")); }