Skip to content

Commit

Permalink
Fix newline handling while converting osquery JSON (kolide#1831)
Browse files Browse the repository at this point in the history
  • Loading branch information
zwass authored Jun 18, 2018
1 parent ece499d commit 34a8b9e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Binary file added cmd/fleetctl/api
Binary file not shown.
25 changes: 16 additions & 9 deletions cmd/fleetctl/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"path/filepath"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -99,18 +100,24 @@ func convertCommand() cli.Command {
return err
}

// Remove any literal newlines (because they are not
// valid JSON but osquery accepts them) and replace
// with \n so that we get them in the YAML output where
// they are allowed.
re := regexp.MustCompile(`\W*\\\n`)
b = re.ReplaceAll(b, []byte(`\n`))

var specs *specGroup

var pack kolide.PermissivePackContent
packErr := json.Unmarshal(b, &pack)
if packErr == nil {
base := filepath.Base(flFilename)
specs, err = specGroupFromPack(strings.TrimSuffix(base, filepath.Ext(base)), pack)
if err != nil {
return err
}
} else {
return packErr
if err := json.Unmarshal(b, &pack); err != nil {
return err
}

base := filepath.Base(flFilename)
specs, err = specGroupFromPack(strings.TrimSuffix(base, filepath.Ext(base)), pack)
if err != nil {
return err
}

if specs == nil {
Expand Down

0 comments on commit 34a8b9e

Please sign in to comment.