diff --git a/cmd/plugin/rpaasv2/cmd/extra_files.go b/cmd/plugin/rpaasv2/cmd/extra_files.go index f8867fe3b..c996845cc 100644 --- a/cmd/plugin/rpaasv2/cmd/extra_files.go +++ b/cmd/plugin/rpaasv2/cmd/extra_files.go @@ -5,10 +5,11 @@ package cmd import ( + "bytes" "fmt" - "io" "os" "strings" + "unicode/utf8" "github.com/olekukonko/tablewriter" rpaasclient "github.com/tsuru/rpaas-operator/pkg/rpaas/client" @@ -266,13 +267,20 @@ func runDeleteExtraFiles(c *cli.Context) error { return nil } -func writeExtraFilesOnTableFormat(writer io.Writer, files []types.RpaasFile) { +func writeExtraFilesOnTableFormat(files []types.RpaasFile) string { + var buffer bytes.Buffer + data := [][]string{} for _, file := range files { - data = append(data, []string{file.Name, string(file.Content)}) + content := string(file.Content) + if !utf8.Valid(file.Content) { + content = "WARNING!\nCANNOT SHOW THE FILE CONTENT AS IT'S NOT UTF-8 ENCODED." + } + + data = append(data, []string{file.Name, content}) } - table := tablewriter.NewWriter(writer) + table := tablewriter.NewWriter(&buffer) table.SetHeader([]string{"Name", "Content"}) table.SetAutoWrapText(false) table.SetRowLine(true) @@ -280,6 +288,8 @@ func writeExtraFilesOnTableFormat(writer io.Writer, files []types.RpaasFile) { table.SetAlignment(tablewriter.ALIGN_LEFT) table.AppendBulk(data) table.Render() + + return buffer.String() } func runListExtraFiles(c *cli.Context) error { @@ -303,7 +313,7 @@ func runListExtraFiles(c *cli.Context) error { fmt.Fprintln(c.App.Writer, file.Name) } case true: - writeExtraFilesOnTableFormat(c.App.Writer, files) + fmt.Fprint(c.App.Writer, writeExtraFilesOnTableFormat(files)) } return nil } diff --git a/cmd/plugin/rpaasv2/cmd/info.go b/cmd/plugin/rpaasv2/cmd/info.go index 9fbbedda1..018a27020 100644 --- a/cmd/plugin/rpaasv2/cmd/info.go +++ b/cmd/plugin/rpaasv2/cmd/info.go @@ -66,6 +66,7 @@ func newFuncMap() template.FuncMap { "formatCertificates": writeCertificatesOnTableFormat, "formatEvents": writeEventsOnTableFormat, "formatACLs": writeAccessControlListOnTableFormat, + "formatExtraFiles": writeExtraFilesOnTableFormat, } for k, v := range sprig.HtmlFuncMap() { @@ -131,6 +132,11 @@ Certificates: {{ formatCertificates . }} {{- end }} +{{- with .ExtraFiles }} +Extra files: +{{ formatExtraFiles . }} +{{- end }} + {{- with .Blocks }} Blocks: {{ formatBlocks . }} diff --git a/cmd/plugin/rpaasv2/cmd/info_test.go b/cmd/plugin/rpaasv2/cmd/info_test.go index 51b79e720..75af93aac 100644 --- a/cmd/plugin/rpaasv2/cmd/info_test.go +++ b/cmd/plugin/rpaasv2/cmd/info_test.go @@ -316,6 +316,10 @@ func TestInfo(t *testing.T) { WorkerConnections: 4096, }, }, + ExtraFiles: []clientTypes.RpaasFile{ + {Name: "modsecurity.cfg", Content: []byte("a bunch of WAF configs...")}, + {Name: "binary.exe", Content: []byte{66, 250, 0, 10}}, + }, }, nil }, }, @@ -453,6 +457,16 @@ Certificates: | | 384 | 2050-07-31T00:00:00Z | | +---------------+--------------------+----------------------+----------------------------+ +Extra files: ++-----------------+---------------------------------------------------------+ +| Name | Content | ++-----------------+---------------------------------------------------------+ +| modsecurity.cfg | a bunch of WAF configs... | ++-----------------+---------------------------------------------------------+ +| binary.exe | WARNING! | +| | CANNOT SHOW THE FILE CONTENT AS IT'S NOT UTF-8 ENCODED. | ++-----------------+---------------------------------------------------------+ + Blocks: +---------+---------------------------------------+ | Context | Configuration | diff --git a/pkg/rpaas/client/types/types.go b/pkg/rpaas/client/types/types.go index c8660c87d..c5c6c07f6 100644 --- a/pkg/rpaas/client/types/types.go +++ b/pkg/rpaas/client/types/types.go @@ -145,6 +145,7 @@ type InstanceInfo struct { Certificates []CertificateInfo `json:"certificates,omitempty"` Events []Event `json:"events,omitempty"` PlanOverride *v1alpha1.RpaasPlanSpec `json:"planOverride,omitempty"` + ExtraFiles []RpaasFile `json:"extraFiles,omitempty"` } type AllowedUpstream struct {