IBM / sarama

Sarama is a Go library for Apache Kafka.
MIT License
11.55k stars 1.76k forks source link

Geting ListAcls for Principal: &User #1392

Closed skate9819 closed 5 years ago

skate9819 commented 5 years ago
Versions

Sarama Version:1.22.1 Kafka Version:V2_2_0_0 Go Version:1.12.5

Configuration
config := sarama.NewConfig()
config.Version = sarama.V2_2_0_0
timeout, _ := time.ParseDuration("20s")
config.Net.DialTimeout = timeout
if len(clusterConfig.User) > 0 {
    config.Net.SASL.Enable = true
    config.Net.SASL.User = clusterConfig.User
    config.Net.SASL.Password = clusterConfig.Password
}
Logs

When filing an issue please provide logs from Sarama and Kafka if at all possible. You can set sarama.Logger to a log.Logger to capture Sarama debug output.

Problem Description

i want to get acls of user. I'm running this code: ` config := sarama.NewConfig() config.Version = sarama.V2_2_00 timeout, := time.ParseDuration("20s") config.Net.DialTimeout = timeout

if len(clusterConfig.User) > 0 {
    config.Net.SASL.Enable = true
    config.Net.SASL.User = clusterConfig.User
    config.Net.SASL.Password = clusterConfig.Password
}

cluster, err := sarama.NewClusterAdmin(clusterConfig.Addr, config)
if err != nil {
    return nil, err
}
User := "User:bpm"
ans_1, err1 := cluster.ListAcls(sarama.AclFilter{
    Principal: &User,
})
if err1 != nil {
    fmt.Println(err1.Error())
}
fmt.Println(len(ans_1))`

It returns an empty list ans_1. When i use confluent-5.2.1, and run ./kafka-acls --authorizer kafka.security.auth.SimpleAclAuthorizer --authorizer-properties zookeeper.connect=MY_ZOOKEEPER_HOST --principal User:bpm --list , Then it works perfectly!

What could be the problem?

skate9819 commented 5 years ago

Oh. I found a solution: ans_1, err1 := cluster.ListAcls(sarama.AclFilter{ ResourceType: sarama.AclResourceAny, ResourcePatternTypeFilter: sarama.AclPatternLiteral, Version: 1, Principal: &User, Operation: sarama.AclOperationAny, PermissionType: sarama.AclPermissionAny, })