-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add namespace support to kolide_wmi (#623)
Adds support for specifying the connection parameters to the underlying wmi package, and plumbs namespace through to the table. Additionally add `tablehelper` methods to improve code readability when parsing column constraints
- Loading branch information
1 parent
2e4c979
commit e1e2998
Showing
8 changed files
with
305 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package tablehelpers | ||
|
||
import ( | ||
"github.com/kolide/osquery-go/plugin/table" | ||
) | ||
|
||
// GetConstraints returns a []string of the constraint expressions on | ||
// a column. It's meant for the common, simple, usecase of iterating over them. | ||
func GetConstraints(queryContext table.QueryContext, columnName string, defaults ...string) []string { | ||
q, ok := queryContext.Constraints[columnName] | ||
if !ok || len(q.Constraints) == 0 { | ||
return defaults | ||
} | ||
|
||
constraintSet := make(map[string]struct{}) | ||
|
||
for _, c := range q.Constraints { | ||
constraintSet[c.Expression] = struct{}{} | ||
} | ||
|
||
constraints := make([]string, len(constraintSet)) | ||
|
||
i := 0 | ||
for key := range constraintSet { | ||
constraints[i] = key | ||
i++ | ||
} | ||
|
||
return constraints | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package tablehelpers | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestGetConstraints(t *testing.T) { | ||
t.Parallel() | ||
|
||
mockQC := MockQueryContext(map[string][]string{ | ||
"empty_array": []string{}, | ||
"blank": []string{""}, | ||
"single": []string{"a"}, | ||
"double": []string{"a", "b"}, | ||
"duplicates": []string{"a", "a", "b", "b"}, | ||
"duplicate_blanks": []string{"a", "a", "", ""}, | ||
}) | ||
|
||
var tests = []struct { | ||
name string | ||
expected []string | ||
defaults []string | ||
}{ | ||
{ | ||
name: "does_not_exist", | ||
expected: []string(nil), | ||
}, | ||
{ | ||
name: "does_not_exist_with_defaults", | ||
expected: []string{"a", "b"}, | ||
defaults: []string{"a", "b"}, | ||
}, | ||
{ | ||
name: "empty_array", | ||
expected: []string{"a", "b"}, | ||
defaults: []string{"a", "b"}, | ||
}, | ||
{ | ||
name: "empty_array", | ||
expected: []string(nil), | ||
}, | ||
{ | ||
name: "blank", | ||
expected: []string{""}, | ||
}, | ||
{ | ||
name: "blank", | ||
expected: []string{""}, | ||
defaults: []string{"a", "b"}, | ||
}, | ||
{ | ||
name: "single", | ||
expected: []string{"a"}, | ||
}, | ||
{ | ||
name: "single", | ||
expected: []string{"a"}, | ||
defaults: []string{"a", "b"}, | ||
}, | ||
{ | ||
name: "double", | ||
expected: []string{"a", "b"}, | ||
}, | ||
{ | ||
name: "duplicates", | ||
expected: []string{"a", "b"}, | ||
}, | ||
{ | ||
name: "duplicate_blanks", | ||
expected: []string{"a", ""}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
actual := GetConstraints(mockQC, tt.name, tt.defaults...) | ||
require.Equal(t, tt.expected, actual) | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.