ctubbsii commented on code in PR #5192:
URL: https://github.com/apache/accumulo/pull/5192#discussion_r1901307815
##########
core/src/main/java/org/apache/accumulo/core/fate/zookeeper/ZooUtil.java:
##########
@@ -170,26 +176,78 @@ private static String getFmtTime(final long epoch) {
}
/**
- * Get the ZooKeeper digest based on the instance secret that is used within
ZooKeeper for
- * authentication. This method is primary intended to be used to validate
ZooKeeper ACLs. Use
- * {@link #digestAuth(ZooKeeper, String)} to add authorizations to ZooKeeper.
+ * Given a zooCache and instanceId, look up the instance name.
*/
- public static Id getZkDigestAuthId(final String secret) {
+ public static String getInstanceName(ZooSession zk, InstanceId instanceId) {
+ requireNonNull(zk);
+ var instanceIdBytes =
requireNonNull(instanceId).canonical().getBytes(UTF_8);
+ for (String name : getInstanceNames(zk)) {
+ var bytes = getInstanceIdBytesFromName(zk, name);
+ if (Arrays.equals(bytes, instanceIdBytes)) {
+ return name;
+ }
+ }
+ return null;
+ }
+
+ private static List<String> getInstanceNames(ZooSession zk) {
try {
- final String scheme = "digest";
- String auth = DigestAuthenticationProvider.generateDigest("accumulo:" +
secret);
- return new Id(scheme, auth);
- } catch (NoSuchAlgorithmException ex) {
- throw new IllegalArgumentException("Could not generate ZooKeeper digest
string", ex);
+ return new ZooReader(zk).getChildren(Constants.ZROOT +
Constants.ZINSTANCES);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new IllegalStateException("Interrupted reading instance names from
ZooKeeper", e);
+ } catch (KeeperException e) {
+ throw new IllegalStateException("Failed to read instance names from
ZooKeeper", e);
}
}
- public static void digestAuth(ZooKeeper zoo, String secret) {
- auth(zoo, "digest", ("accumulo:" + secret).getBytes(UTF_8));
+ private static byte[] getInstanceIdBytesFromName(ZooSession zk, String name)
{
+ try {
+ return new ZooReader(zk)
Review Comment:
Fixed in 95674198ff37296a4936508f74b2303e18bdf486
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]