From 879a3c124a2567c0d0fd42e817a606c925b4a2e7 Mon Sep 17 00:00:00 2001 From: Edoardo Spadolini Date: Thu, 16 Dec 2021 17:16:46 +0100 Subject: [PATCH] Escape access request and access resolution reasons in tctl (#9381) * 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 <31974658+atburke@users.noreply.github.com> Co-authored-by: Andrew Burke <31974658+atburke@users.noreply.github.com> --- tool/tctl/common/access_request_command.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tool/tctl/common/access_request_command.go b/tool/tctl/common/access_request_command.go index 192a4cb73f505..950b3f2ef769b 100644 --- a/tool/tctl/common/access_request_command.go +++ b/tool/tctl/common/access_request_command.go @@ -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) @@ -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 { @@ -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) +}