func TestCredentials1(t *testing.T) { acl := stdzk.DigestACL(stdzk.PermAll, "user", "secret") c, _ := NewClient(host, logger, ACL(acl), Credentials("user", "secret")) defer c.Stop() _, err := NewSubscriber(c, "/acl-issue-test", newFactory(""), logger) if err != nil { t.Fatal(err) } }
func TestCredentials2(t *testing.T) { acl := stdzk.DigestACL(stdzk.PermAll, "user", "secret") c, _ := NewClient(host, logger, ACL(acl)) defer c.Stop() _, err := NewSubscriber(c, "/acl-issue-test", newFactory(""), logger) if err != stdzk.ErrNoAuth { t.Errorf("want %v, have %v", stdzk.ErrNoAuth, err) } }
// Returns acls func BuildACL(authScheme string, user string, pwd string, acls string) (perms []zk.ACL, err error) { aclsList := strings.Split(acls, ",") for _, elem := range aclsList { acl, err := strconv.ParseInt(elem, 10, 32) if err != nil { break } perm := zk.DigestACL(int32(acl), user, pwd) perms = append(perms, perm[0]) } return perms, err }
func (conn *ZKConn) NewNode(path string, value string) error { auth := strings.Split(conn.Auth, ":") readOnlyACL := append([]zk.ACL{}, zk.DigestACL(zk.PermAll, auth[0], auth[1])...) readOnlyACL = append(readOnlyACL, zk.WorldACL(zk.PermRead)...) if err := conn.checkRoot(path, readOnlyACL); err != nil { return err } retry := true var err error for retry { _, err := conn.Create(path, []byte(value), zk.FlagEphemeral, readOnlyACL) if err == nil { log.Printf("Node %s created", path) } else if err == zk.ErrNodeExists { log.Printf("Node %s existed, wait and retry", path) time.Sleep(time.Second * 3) continue } retry = false } return err }