@@ -2,8 +2,6 @@ package cli
22
33import (
44 "crypto/tls"
5- "encoding/base64"
6- "encoding/json"
75 "fmt"
86 "io/ioutil"
97 "net/http"
@@ -262,7 +260,7 @@ func runCollectors(v *viper.Viper, collector troubleshootv1beta1.Collector, prog
262260 }
263261
264262 if result != nil {
265- err = parseAndSaveCollectorOutput ( string ( result ) , bundlePath )
263+ err = saveCollectorOutput ( result , bundlePath )
266264 if err != nil {
267265 progressChan <- fmt .Errorf ("failed to parse collector spec %q: %v" , collector .GetDisplayName (), err )
268266 continue
@@ -282,46 +280,17 @@ func runCollectors(v *viper.Viper, collector troubleshootv1beta1.Collector, prog
282280 return filename , nil
283281}
284282
285- func parseAndSaveCollectorOutput (output string , bundlePath string ) error {
286- input := make (map [string ]interface {})
287- if err := json .Unmarshal ([]byte (output ), & input ); err != nil {
288- return errors .Wrap (err , "unmarshal output" )
289- }
290-
291- for filename , maybeContents := range input {
283+ func saveCollectorOutput (output map [string ][]byte , bundlePath string ) error {
284+ for filename , maybeContents := range output {
292285 fileDir , fileName := filepath .Split (filename )
293286 outPath := filepath .Join (bundlePath , fileDir )
294287
295288 if err := os .MkdirAll (outPath , 0777 ); err != nil {
296289 return errors .Wrap (err , "create output file" )
297290 }
298291
299- switch maybeContents .(type ) {
300- case string :
301- decoded , err := base64 .StdEncoding .DecodeString (maybeContents .(string ))
302- if err != nil {
303- return errors .Wrap (err , "decode collector output" )
304- }
305-
306- if err := writeFile (filepath .Join (outPath , fileName ), decoded ); err != nil {
307- return errors .Wrap (err , "write collector output" )
308- }
309-
310- case map [string ]interface {}:
311- for k , v := range maybeContents .(map [string ]interface {}) {
312- s , _ := filepath .Split (filepath .Join (outPath , fileName , k ))
313- if err := os .MkdirAll (s , 0777 ); err != nil {
314- return errors .Wrap (err , "write output directories" )
315- }
316-
317- decoded , err := base64 .StdEncoding .DecodeString (v .(string ))
318- if err != nil {
319- return errors .Wrap (err , "decode output" )
320- }
321- if err := writeFile (filepath .Join (outPath , fileName , k ), decoded ); err != nil {
322- return errors .Wrap (err , "write output" )
323- }
324- }
292+ if err := writeFile (filepath .Join (outPath , fileName ), maybeContents ); err != nil {
293+ return errors .Wrap (err , "write collector output" )
325294 }
326295 }
327296
0 commit comments