Skip to content

Commit

Permalink
Add flag for show to display secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
tgrondier committed Dec 2, 2024
1 parent c9627b2 commit ac6cb06
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
9 changes: 6 additions & 3 deletions cmd/dbaas_user_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type dbaasUserShowOutput struct {
Username string `json:"username,omitempty"`
Type string `json:"type,omitempty"`
Password string `json:"password,omitempty"`

// Additional user info for some DBAAS Services
MySQL *dbaasMysqlUserShowOutput `json:"mysql,omitempty"`
Expand All @@ -30,6 +31,7 @@ func (o *dbaasUserShowOutput) ToTable() {

t.Append([]string{"Username", o.Username})
t.Append([]string{"Type", o.Type})
t.Append([]string{"Password", o.Password})

switch {
case o.MySQL != nil:
Expand All @@ -47,9 +49,10 @@ type dbaasUserShowCmd struct {

_ bool `cli-cmd:"show"`

Name string `cli-arg:"#"`
Username string `cli-arg:"#"`
Zone string `cli-short:"z" cli-usage:"Database Service zone"`
Name string `cli-arg:"#"`
Username string `cli-arg:"#"`
Zone string `cli-short:"z" cli-usage:"Database Service zone"`
ShowSecrets bool `cli-flag:"secrets" cli-usage:"reveal user password and other secrets"`
}

func (c *dbaasUserShowCmd) cmdAliases() []string { return nil }
Expand Down
10 changes: 9 additions & 1 deletion cmd/dbaas_user_show_grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ func (c *dbaasUserShowCmd) showGrafana(ctx context.Context) (output.Outputter, e
if u.Username == c.Username {
return &dbaasUserShowOutput{
Username: c.Username,
Type: u.Type,
Password: func() string {
if c.ShowSecrets {
return u.Password
} else {
return "xxxxxx"
}
}(),

Type: u.Type,
}, nil
}

Expand Down
17 changes: 15 additions & 2 deletions cmd/dbaas_user_show_kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,22 @@ func (c *dbaasUserShowCmd) showKafka(ctx context.Context) (output.Outputter, err
if u.Username == c.Username {
return &dbaasUserShowOutput{
Username: c.Username,
Type: u.Type,
Password: func() string {
if c.ShowSecrets {
return u.Password
} else {
return "xxxxxx"
}
}(),
Type: u.Type,
Kafka: &dbaasKafkaUserShowOutput{
AccessKey: u.AccessKey,
AccessKey: func() string {
if c.ShowSecrets {
return u.AccessKey
} else {
return "xxxxxx"
}
}(),
AccessCert: u.AccessCert,
AccessCertExpiry: u.AccessCertExpiry,
},
Expand Down
10 changes: 9 additions & 1 deletion cmd/dbaas_user_show_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ func (c *dbaasUserShowCmd) showMysql(ctx context.Context) (output.Outputter, err
if u.Username == c.Username {
return &dbaasUserShowOutput{
Username: c.Username,
Type: u.Type,
Password: func() string {
if c.ShowSecrets {
return u.Password
} else {
return "xxxxxx"
}
}(),

Type: u.Type,
MySQL: &dbaasMysqlUserShowOutput{
Authentication: u.Authentication,
},
Expand Down
10 changes: 9 additions & 1 deletion cmd/dbaas_user_show_opensearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ func (c *dbaasUserShowCmd) showOpensearch(ctx context.Context) (output.Outputter
if u.Username == c.Username {
return &dbaasUserShowOutput{
Username: c.Username,
Type: u.Type,
Password: func() string {
if c.ShowSecrets {
return u.Password
} else {
return "xxxxxx"
}
}(),

Type: u.Type,
}, nil
}

Expand Down
10 changes: 9 additions & 1 deletion cmd/dbaas_user_show_pq.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ func (c *dbaasUserShowCmd) showPG(ctx context.Context) (output.Outputter, error)
if u.Username == c.Username {
return &dbaasUserShowOutput{
Username: c.Username,
Type: u.Type,
Password: func() string {
if c.ShowSecrets {
return u.Password
} else {
return "xxxxxx"
}
}(),

Type: u.Type,
PG: &dbaasPGUserShowOutput{
AllowReplication: u.AllowReplication,
},
Expand Down

0 comments on commit ac6cb06

Please sign in to comment.