From 7e45e8c6dfb834a243d7a41956514e695a35d0ad Mon Sep 17 00:00:00 2001 From: Micah-Kolide <109157253+Micah-Kolide@users.noreply.github.com> Date: Wed, 13 Mar 2024 10:25:16 -0700 Subject: [PATCH] Update naming and comments --- ee/tables/execparsers/data_table/parser.go | 8 +++----- pkg/osquery/table/platform_tables_linux.go | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/ee/tables/execparsers/data_table/parser.go b/ee/tables/execparsers/data_table/parser.go index 8c6b80835..dcde25e06 100644 --- a/ee/tables/execparsers/data_table/parser.go +++ b/ee/tables/execparsers/data_table/parser.go @@ -9,7 +9,7 @@ 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 @@ -17,7 +17,7 @@ type parser struct { 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} } @@ -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) @@ -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 { diff --git a/pkg/osquery/table/platform_tables_linux.go b/pkg/osquery/table/platform_tables_linux.go index b7c93a875..8f21d8a90 100644 --- a/pkg/osquery/table/platform_tables_linux.go +++ b/pkg/osquery/table/platform_tables_linux.go @@ -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),