diff --git a/cmd/topicctl/subcmd/get.go b/cmd/topicctl/subcmd/get.go index 0b85fbe7..16f5dea7 100644 --- a/cmd/topicctl/subcmd/get.go +++ b/cmd/topicctl/subcmd/get.go @@ -246,7 +246,7 @@ func usersCmd() *cobra.Command { if err != nil { return err } - return cliRunner.GetUsers(ctx, getConfig.full) + return cliRunner.GetUsers(ctx, nil) }, } } diff --git a/pkg/admin/brokerclient.go b/pkg/admin/brokerclient.go index c717005e..d35ac848 100644 --- a/pkg/admin/brokerclient.go +++ b/pkg/admin/brokerclient.go @@ -402,9 +402,16 @@ func (c *BrokerAdminClient) GetUsers( results := []UserInfo{} for _, result := range resp.Results { + var credentials []CredentialInfo + for _, credential := range result.CredentialInfos { + credentials = append(credentials, CredentialInfo{ + ScramMechanism: ScramMechanism(credential.Mechanism), + Iterations: credential.Iterations, + }) + } results = append(results, UserInfo{ Name: result.User, - CredentialInfos: result.CredentialInfos, + CredentialInfos: credentials, }) } return results, err diff --git a/pkg/admin/brokerclient_test.go b/pkg/admin/brokerclient_test.go index 46c68945..5b0e573e 100644 --- a/pkg/admin/brokerclient_test.go +++ b/pkg/admin/brokerclient_test.go @@ -607,10 +607,10 @@ func TestBrokerClientCreateGetUsers(t *testing.T) { assert.Equal(t, []UserInfo{ { Name: "junk", - CredentialInfos: []kafka.DescribeUserScramCredentialsCredentialInfo{ + CredentialInfos: []CredentialInfo{ { - Mechanism: kafka.ScramMechanismSha512, - Iterations: 15000, + ScramMechanism: ScramMechanism(kafka.ScramMechanismSha512), + Iterations: 15000, }, }, }, diff --git a/pkg/admin/format.go b/pkg/admin/format.go index d1830cd9..4de826a6 100644 --- a/pkg/admin/format.go +++ b/pkg/admin/format.go @@ -752,7 +752,8 @@ func FormatUsers(users []UserInfo) string { headers := []string{ "Name", - "CredentialsInfo", + "Mechanism", + "Iterations", } table := tablewriter.NewWriter(buf) @@ -774,12 +775,15 @@ func FormatUsers(users []UserInfo) string { ) for _, user := range users { - row := []string{ - user.Name, - user.CredentialsInfo.String(), - } + for _, credential := range user.CredentialInfos { + row := []string{ + user.Name, + credential.ScramMechanism.String(), + fmt.Sprintf("%d", credential.Iterations), + } - table.Append(row) + table.Append(row) + } } table.Render() diff --git a/pkg/admin/types.go b/pkg/admin/types.go index da957766..3977d107 100644 --- a/pkg/admin/types.go +++ b/pkg/admin/types.go @@ -77,8 +77,30 @@ type PartitionAssignment struct { // UserInfo represents the information stored about a user // in zookeeper. type UserInfo struct { - Name string `json:"name"` - CredentialInfos []kafka.DescribeUserScramCredentialsCredentialInfo `json:"credentialInfos"` + Name string `json:"name"` + CredentialInfos []CredentialInfo `json:"credentialInfos"` +} + +// CredentialInfo represents read only information about +// a users credentials in zookeeper. +type CredentialInfo struct { + ScramMechanism ScramMechanism + Iterations int +} + +// ScramMechanism represents the ScramMechanism used +// for a users credential in zookeeper. +type ScramMechanism kafka.ScramMechanism + +func (s *ScramMechanism) String() string { + switch kafka.ScramMechanism(*s) { + case kafka.ScramMechanismSha256: + return "sha256" + case kafka.ScramMechanismSha512: + return "sha512" + default: + return "unknown" + } } type zkClusterID struct {