Skip to content

Commit

Permalink
Escape access request and access resolution reasons in tctl (#9381)
Browse files Browse the repository at this point in the history
* Pass request and resolve reasons in tctl through %q like it's done in tsh

* Update tool/tctl/common/access_request_command.go

Co-authored-by: Andrew Burke <[email protected]>

Co-authored-by: Andrew Burke <[email protected]>
  • Loading branch information
espadolini and atburke committed Dec 20, 2021
1 parent 08c4d66 commit 04fb457
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tool/tctl/common/access_request_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ func printRequestsOverview(reqs []types.AccessRequest, format string) error {
fmt.Sprintf("roles=%s", strings.Join(req.GetRoles(), ",")),
req.GetCreationTime().Format(time.RFC822),
req.GetState().String(),
req.GetRequestReason(),
req.GetResolveReason(),
quoteOrDefault(req.GetRequestReason(), ""),
quoteOrDefault(req.GetResolveReason(), ""),
})
}
_, err := table.AsBuffer().WriteTo(os.Stdout)
Expand All @@ -407,8 +407,8 @@ func printRequestsDetailed(reqs []types.AccessRequest, format string) error {
table.AddRow([]string{"Metadata: ", fmt.Sprintf("roles=%s", strings.Join(req.GetRoles(), ","))})
table.AddRow([]string{"Created At (UTC): ", req.GetCreationTime().Format(time.RFC822)})
table.AddRow([]string{"Status: ", req.GetState().String()})
table.AddRow([]string{"Request Reason: ", req.GetRequestReason()})
table.AddRow([]string{"Resolve Reason: ", req.GetResolveReason()})
table.AddRow([]string{"Request Reason: ", quoteOrDefault(req.GetRequestReason(), "[none]")})
table.AddRow([]string{"Resolve Reason: ", quoteOrDefault(req.GetResolveReason(), "[none]")})

_, err := table.AsBuffer().WriteTo(os.Stdout)
if err != nil {
Expand All @@ -432,3 +432,10 @@ func printJSON(in interface{}, desc string) error {
fmt.Printf("%s\n", out)
return nil
}

func quoteOrDefault(s, d string) string {
if s == "" {
return d
}
return fmt.Sprintf("%q", s)
}

0 comments on commit 04fb457

Please sign in to comment.