Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@

[[constraint]]
# This version includes concurrency fixes, but excludes changes to the
# library APIs. Using a version beyond this would require users to build the
# Thrift compiler from source to get API-compatible generated code. After the
# next Thrift release, this should become that tagged release (and the code
# generated appropriately).
name = "git.apache.org/thrift.git"
version = "0.11.0"
revision = "0dd823580c78a79ae9696eb9b3650e400fff140f"

[[constraint]]
name = "github.com/Microsoft/go-winio"
Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ deps:
dep ensure -vendor-only

gen: ./osquery.thrift
rm -rf ./gen
mkdir ./gen
thrift --gen go:package_prefix=github.com/kolide/osquery-go/gen/ -out ./gen ./osquery.thrift
rm -rf gen/osquery/extension-remote gen/osquery/extension_manager-remote
Expand Down Expand Up @@ -35,7 +36,4 @@ example_config: examples/config/*.go
test: all
go test -race -cover -v $(shell go list ./... | grep -v /vendor/)

clean:
rm -rf ./build ./gen

.PHONY: all
15 changes: 7 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package osquery

import (
"context"
"time"

"github.com/kolide/osquery-go/gen/osquery"
Expand Down Expand Up @@ -55,34 +54,34 @@ func (c *ExtensionManagerClient) Close() {

// Ping requests metadata from the extension manager.
func (c *ExtensionManagerClient) Ping() (*osquery.ExtensionStatus, error) {
return c.Client.Ping(context.Background())
return c.Client.Ping()
}

// Call requests a call to an extension (or core) registry plugin.
func (c *ExtensionManagerClient) Call(registry, item string, request osquery.ExtensionPluginRequest) (*osquery.ExtensionResponse, error) {
return c.Client.Call(context.Background(), registry, item, request)
return c.Client.Call(registry, item, request)
}

// Extensions requests the list of active registered extensions.
func (c *ExtensionManagerClient) Extensions() (osquery.InternalExtensionList, error) {
return c.Client.Extensions(context.Background())
return c.Client.Extensions()
}

// RegisterExtension registers the extension plugins with the osquery process.
func (c *ExtensionManagerClient) RegisterExtension(info *osquery.InternalExtensionInfo, registry osquery.ExtensionRegistry) (*osquery.ExtensionStatus, error) {
return c.Client.RegisterExtension(context.Background(), info, registry)
return c.Client.RegisterExtension(info, registry)
}

// Options requests the list of bootstrap or configuration options.
func (c *ExtensionManagerClient) Options() (osquery.InternalOptionList, error) {
return c.Client.Options(context.Background())
return c.Client.Options()
}

// Query requests a query to be run and returns the extension response.
// Consider using the QueryRow or QueryRows helpers for a more friendly
// interface.
func (c *ExtensionManagerClient) Query(sql string) (*osquery.ExtensionResponse, error) {
return c.Client.Query(context.Background(), sql)
return c.Client.Query(sql)
}

// QueryRows is a helper that executes the requested query and returns the
Expand Down Expand Up @@ -118,5 +117,5 @@ func (c *ExtensionManagerClient) QueryRow(sql string) (map[string]string, error)

// GetQueryColumns requests the columns returned by the parsed query.
func (c *ExtensionManagerClient) GetQueryColumns(sql string) (*osquery.ExtensionResponse, error) {
return c.Client.GetQueryColumns(context.Background(), sql)
return c.Client.GetQueryColumns(sql)
}
13 changes: 6 additions & 7 deletions client_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package osquery

import (
"context"
"errors"
"testing"

"github.com/kolide/osquery-go/gen/osquery"
"github.com/kolide/osquery-go/mock"
"github.com/kolide/osquery-go/gen/osquery/mock"
"github.com/stretchr/testify/assert"
)

Expand All @@ -15,7 +14,7 @@ func TestQueryRows(t *testing.T) {
client := &ExtensionManagerClient{Client: mock}

// Transport related error
mock.QueryFunc = func(ctx context.Context, sql string) (*osquery.ExtensionResponse, error) {
mock.QueryFunc = func(sql string) (*osquery.ExtensionResponse, error) {
return nil, errors.New("boom!")
}
rows, err := client.QueryRows("select 1")
Expand All @@ -24,7 +23,7 @@ func TestQueryRows(t *testing.T) {
assert.NotNil(t, err)

// Nil status
mock.QueryFunc = func(ctx context.Context, sql string) (*osquery.ExtensionResponse, error) {
mock.QueryFunc = func(sql string) (*osquery.ExtensionResponse, error) {
return &osquery.ExtensionResponse{}, nil
}
rows, err = client.QueryRows("select 1")
Expand All @@ -33,7 +32,7 @@ func TestQueryRows(t *testing.T) {
assert.NotNil(t, err)

// Query error
mock.QueryFunc = func(ctx context.Context, sql string) (*osquery.ExtensionResponse, error) {
mock.QueryFunc = func(sql string) (*osquery.ExtensionResponse, error) {
return &osquery.ExtensionResponse{
Status: &osquery.ExtensionStatus{Code: 1, Message: "bad query"},
}, nil
Expand All @@ -47,7 +46,7 @@ func TestQueryRows(t *testing.T) {
expectedRows := []map[string]string{
{"1": "1"},
}
mock.QueryFunc = func(ctx context.Context, sql string) (*osquery.ExtensionResponse, error) {
mock.QueryFunc = func(sql string) (*osquery.ExtensionResponse, error) {
return &osquery.ExtensionResponse{
Status: &osquery.ExtensionStatus{Code: 0, Message: "OK"},
Response: expectedRows,
Expand All @@ -65,7 +64,7 @@ func TestQueryRows(t *testing.T) {
{"1": "1"},
{"1": "2"},
}
mock.QueryFunc = func(ctx context.Context, sql string) (*osquery.ExtensionResponse, error) {
mock.QueryFunc = func(sql string) (*osquery.ExtensionResponse, error) {
return &osquery.ExtensionResponse{
Status: &osquery.ExtensionStatus{Code: 0, Message: "OK"},
Response: expectedRows,
Expand Down
5 changes: 2 additions & 3 deletions gen/osquery/GoUnusedProtection__.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 109 additions & 0 deletions gen/osquery/mock/osquery.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Automatically generated by mockimpl. DO NOT EDIT!

package mock

import "github.com/kolide/osquery-go/gen/osquery"

var _ osquery.ExtensionManager = (*ExtensionManager)(nil)

type CloseFunc func()

type PingFunc func() (*osquery.ExtensionStatus, error)

type CallFunc func(registry string, item string, req osquery.ExtensionPluginRequest) (*osquery.ExtensionResponse, error)

type ShutdownFunc func() error

type ExtensionsFunc func() (osquery.InternalExtensionList, error)

type RegisterExtensionFunc func(info *osquery.InternalExtensionInfo, registry osquery.ExtensionRegistry) (*osquery.ExtensionStatus, error)

type DeregisterExtensionFunc func(uuid osquery.ExtensionRouteUUID) (*osquery.ExtensionStatus, error)

type OptionsFunc func() (osquery.InternalOptionList, error)

type QueryFunc func(sql string) (*osquery.ExtensionResponse, error)

type GetQueryColumnsFunc func(sql string) (*osquery.ExtensionResponse, error)

type ExtensionManager struct {
CloseFunc CloseFunc
CloseFuncInvoked bool

PingFunc PingFunc
PingFuncInvoked bool

CallFunc CallFunc
CallFuncInvoked bool

ShutdownFunc ShutdownFunc
ShutdownFuncInvoked bool

ExtensionsFunc ExtensionsFunc
ExtensionsFuncInvoked bool

RegisterExtensionFunc RegisterExtensionFunc
RegisterExtensionFuncInvoked bool

DeregisterExtensionFunc DeregisterExtensionFunc
DeregisterExtensionFuncInvoked bool

OptionsFunc OptionsFunc
OptionsFuncInvoked bool

QueryFunc QueryFunc
QueryFuncInvoked bool

GetQueryColumnsFunc GetQueryColumnsFunc
GetQueryColumnsFuncInvoked bool
}

func (m *ExtensionManager) Close() {
m.CloseFuncInvoked = true
m.CloseFunc()
}

func (m *ExtensionManager) Ping() (*osquery.ExtensionStatus, error) {
m.PingFuncInvoked = true
return m.PingFunc()
}

func (m *ExtensionManager) Call(registry string, item string, req osquery.ExtensionPluginRequest) (*osquery.ExtensionResponse, error) {
m.CallFuncInvoked = true
return m.CallFunc(registry, item, req)
}

func (m *ExtensionManager) Shutdown() error {
m.ShutdownFuncInvoked = true
return m.ShutdownFunc()
}

func (m *ExtensionManager) Extensions() (osquery.InternalExtensionList, error) {
m.ExtensionsFuncInvoked = true
return m.ExtensionsFunc()
}

func (m *ExtensionManager) RegisterExtension(info *osquery.InternalExtensionInfo, registry osquery.ExtensionRegistry) (*osquery.ExtensionStatus, error) {
m.RegisterExtensionFuncInvoked = true
return m.RegisterExtensionFunc(info, registry)
}

func (m *ExtensionManager) DeregisterExtension(uuid osquery.ExtensionRouteUUID) (*osquery.ExtensionStatus, error) {
m.DeregisterExtensionFuncInvoked = true
return m.DeregisterExtensionFunc(uuid)
}

func (m *ExtensionManager) Options() (osquery.InternalOptionList, error) {
m.OptionsFuncInvoked = true
return m.OptionsFunc()
}

func (m *ExtensionManager) Query(sql string) (*osquery.ExtensionResponse, error) {
m.QueryFuncInvoked = true
return m.QueryFunc(sql)
}

func (m *ExtensionManager) GetQueryColumns(sql string) (*osquery.ExtensionResponse, error) {
m.GetQueryColumnsFuncInvoked = true
return m.GetQueryColumnsFunc(sql)
}
8 changes: 1 addition & 7 deletions gen/osquery/osquery-consts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading