Skip to content

Commit

Permalink
Update naming and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Micah-Kolide committed Mar 13, 2024
1 parent 988225f commit 7e45e8c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions ee/tables/execparsers/data_table/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
// data_table is a general parser for an input of data which conforms to columns and rows styled output.
// Parser options
// skipLines - The number of initial lines of data to skip. By default no lines are skipped. This can be useful if consistent undesired output/garbage is printed before the data to parse.
// headers - The set of headers. If left blank, the parser assumes the headers are in the first line of data and splits the line to set them.
// headers - The set of headers. If left blank, the parser assumes the headers are in the first line of data and splits that line to set them.
// delimiter - The splitting string. If left blank, the parser assumes the delimiter is whitespace and uses `strings.Fields()` split method.
type parser struct {
skipLines uint
headers []string
delimiter string
}

func Parser(skipLines uint, headers []string, delimiter string) parser {
func NewParser(skipLines uint, headers []string, delimiter string) parser {
return parser{skipLines: skipLines, headers: headers, delimiter: delimiter}
}

Expand All @@ -27,8 +27,6 @@ func (p parser) Parse(reader io.Reader) (any, error) {

// parseLines scans a reader line by line and splits it into fields based on a delimiter.
// The line fields are paired with a header, which is defined by an input array, or the first line of data.
// If no delimiter is provided, it's assumed that fields are separated by whitespace.
// The first N lines of data can be skipped in case garbage is sent before the data.
func (p parser) parseLines(reader io.Reader) ([]map[string]string, error) {
results := make([]map[string]string, 0)
scanner := bufio.NewScanner(reader)
Expand Down Expand Up @@ -73,7 +71,7 @@ func (p parser) parseLines(reader io.Reader) ([]map[string]string, error) {
return results, nil
}

// Switch to the appropriate function to return the current line's fields.
// lineSplit switches to the appropriate splitting method to return the current line's fields.
// Delimiter often might be a comma or similar single character.
func (p parser) lineSplit(line string, headerCount int) []string {
switch p.delimiter {
Expand Down
2 changes: 1 addition & 1 deletion pkg/osquery/table/platform_tables_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func platformSpecificTables(slogger *slog.Logger, currentOsquerydBinaryPath stri
dataflattentable.NewExecAndParseTable(slogger, "kolide_pacman_version_info", pacman_info.Parser, allowedcmd.Pacman, []string{"-Qi"}, dataflattentable.WithIncludeStderr()),
dataflattentable.NewExecAndParseTable(slogger, "kolide_pacman_upgradeable", pacman_upgradeable.Parser, allowedcmd.Pacman, []string{"-Qu"}, dataflattentable.WithIncludeStderr()),
dataflattentable.NewExecAndParseTable(slogger, "kolide_rpm_version_info", rpm.Parser, allowedcmd.Rpm, []string{"-qai"}, dataflattentable.WithIncludeStderr()),
dataflattentable.NewExecAndParseTable(slogger, "kolide_snap_upgradeable", data_table.Parser(0, nil, ""), allowedcmd.Snap, []string{"refresh", "--list"}, dataflattentable.WithIncludeStderr()),
dataflattentable.NewExecAndParseTable(slogger, "kolide_snap_upgradeable", data_table.NewParser(0, nil, ""), allowedcmd.Snap, []string{"refresh", "--list"}, dataflattentable.WithIncludeStderr()),
dataflattentable.NewExecAndParseTable(slogger, "kolide_carbonblack_repcli_status", repcli.Parser, allowedcmd.Repcli, []string{"status"}, dataflattentable.WithIncludeStderr()),
dataflattentable.TablePluginExec(slogger, "kolide_nftables", dataflattentable.JsonType, allowedcmd.Nftables, []string{"-jat", "list", "ruleset"}), // -j (json) -a (show object handles) -t (terse, omit set contents)
zfs.ZfsPropertiesPlugin(slogger),
Expand Down

0 comments on commit 7e45e8c

Please sign in to comment.