Skip to content

Commit

Permalink
get users working
Browse files Browse the repository at this point in the history
  • Loading branch information
petedannemann committed Sep 19, 2023
1 parent dbabc5e commit e05af9f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/topicctl/subcmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func usersCmd() *cobra.Command {
if err != nil {
return err
}
return cliRunner.GetUsers(ctx, getConfig.full)
return cliRunner.GetUsers(ctx, nil)
},
}
}
9 changes: 8 additions & 1 deletion pkg/admin/brokerclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/admin/brokerclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
Expand Down
16 changes: 10 additions & 6 deletions pkg/admin/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,8 @@ func FormatUsers(users []UserInfo) string {

headers := []string{
"Name",
"CredentialsInfo",
"Mechanism",
"Iterations",
}

table := tablewriter.NewWriter(buf)
Expand All @@ -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()
Expand Down
26 changes: 24 additions & 2 deletions pkg/admin/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e05af9f

Please sign in to comment.