From 38054eddbfae7623cabdfd3b0019e71d075e90a4 Mon Sep 17 00:00:00 2001 From: Anas Muhammed Date: Sun, 6 Oct 2024 22:49:04 +0400 Subject: [PATCH] feat: add falcon_discover_host_details datasource --- .mockery.yaml | 1 + .../falcon_discover_host_details.md | 93 +++++++++ docs/plugins/plugins.json | 14 ++ .../data_falcon_discover_host_details.fabric | 32 ++++ .../data_falcon_discover_host_details.go | 102 ++++++++++ .../data_falcon_discover_host_details_test.go | 176 +++++++++++++++++ internal/crowdstrike/plugin.go | 20 +- mocks/internalpkg/crowdstrike/client.go | 47 +++++ .../crowdstrike/discover_client.go | 181 ++++++++++++++++++ 9 files changed, 662 insertions(+), 4 deletions(-) create mode 100644 docs/plugins/crowdstrike/data-sources/falcon_discover_host_details.md create mode 100644 examples/templates/crowdstrike/data_falcon_discover_host_details.fabric create mode 100644 internal/crowdstrike/data_falcon_discover_host_details.go create mode 100644 internal/crowdstrike/data_falcon_discover_host_details_test.go create mode 100644 mocks/internalpkg/crowdstrike/discover_client.go diff --git a/.mockery.yaml b/.mockery.yaml index 66703957..f135379e 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -60,6 +60,7 @@ packages: DetectsClient: SpotVulnerabilitiesClient: IntelClient: + DiscoverClient: github.com/blackstork-io/fabric/plugin/resolver: config: inpackage: true diff --git a/docs/plugins/crowdstrike/data-sources/falcon_discover_host_details.md b/docs/plugins/crowdstrike/data-sources/falcon_discover_host_details.md new file mode 100644 index 00000000..874bcd83 --- /dev/null +++ b/docs/plugins/crowdstrike/data-sources/falcon_discover_host_details.md @@ -0,0 +1,93 @@ +--- +title: "`falcon_discover_host_details` data source" +plugin: + name: blackstork/crowdstrike + description: "The `falcon_discover_host_details` data source fetches host details from Falcon Discover Host API" + tags: [] + version: "v0.4.2" + source_github: "https://github.com/blackstork-io/fabric/tree/main/internal/crowdstrike/" +resource: + type: data-source +type: docs +--- + +{{< breadcrumbs 2 >}} + +{{< plugin-resource-header "blackstork/crowdstrike" "crowdstrike" "v0.4.2" "falcon_discover_host_details" "data source" >}} + +## Description +The `falcon_discover_host_details` data source fetches host details from Falcon Discover Host API. + +## Installation + +To use `falcon_discover_host_details` data source, you must install the plugin `blackstork/crowdstrike`. + +To install the plugin, add the full plugin name to the `plugin_versions` map in the Fabric global configuration block (see [Global configuration]({{< ref "configs.md#global-configuration" >}}) for more details), as shown below: + +```hcl +fabric { + plugin_versions = { + "blackstork/crowdstrike" = ">= v0.4.2" + } +} +``` + +Note the version constraint set for the plugin. + +## Configuration + +The data source supports the following configuration arguments: + +```hcl +config data falcon_discover_host_details { + # Client ID for accessing CrowdStrike Falcon Platform + # + # Required string. + # Must be non-empty + # For example: + client_id = "some string" + + # Client Secret for accessing CrowdStrike Falcon Platform + # + # Required string. + # Must be non-empty + # For example: + client_secret = "some string" + + # Member CID for MSSP + # + # Optional string. + # Default value: + member_cid = null + + # Falcon cloud abbreviation + # + # Optional string. + # Must be one of: "autodiscover", "us-1", "us-2", "eu-1", "us-gov-1", "gov1" + # For example: + # client_cloud = "us-1" + # + # Default value: + client_cloud = null +} +``` + +## Usage + +The data source supports the following execution arguments: + +```hcl +data falcon_discover_host_details { + # limit the number of queried items + # + # Required integer. + # For example: + size = 42 + + # Host search expression using Falcon Query Language (FQL) + # + # Optional string. + # Default value: + filter = null +} +``` \ No newline at end of file diff --git a/docs/plugins/plugins.json b/docs/plugins/plugins.json index 1910ef55..e16e5e9f 100644 --- a/docs/plugins/plugins.json +++ b/docs/plugins/plugins.json @@ -165,6 +165,20 @@ "limit" ] }, + { + "name": "falcon_discover_host_details", + "type": "data-source", + "config_params": [ + "client_cloud", + "client_id", + "client_secret", + "member_cid" + ], + "arguments": [ + "filter", + "size" + ] + }, { "name": "falcon_intel_indicators", "type": "data-source", diff --git a/examples/templates/crowdstrike/data_falcon_discover_host_details.fabric b/examples/templates/crowdstrike/data_falcon_discover_host_details.fabric new file mode 100644 index 00000000..24533b13 --- /dev/null +++ b/examples/templates/crowdstrike/data_falcon_discover_host_details.fabric @@ -0,0 +1,32 @@ +document "falcon_discover_host_details" { + meta { + name = "example_document" + } + + data falcon_discover_host_details "fdhd" { + config { + client_id = "" + client_secret = "" + client_cloud = "eu-1" + } + size = 100 + } + + title = "List of discover host details" + + content table { + rows = query_jq(".data.falcon_discover_host_details.fdhd") + columns = [ + { + "header" = "Cid" + "value" = "{{.row.value.cid}}" + }, + { + "header" = "City" + "value" = "{{.row.value.city}}" + } + ] + } + +} + diff --git a/internal/crowdstrike/data_falcon_discover_host_details.go b/internal/crowdstrike/data_falcon_discover_host_details.go new file mode 100644 index 00000000..8d808ccf --- /dev/null +++ b/internal/crowdstrike/data_falcon_discover_host_details.go @@ -0,0 +1,102 @@ +package crowdstrike + +import ( + "context" + + "github.com/crowdstrike/gofalcon/falcon" + "github.com/crowdstrike/gofalcon/falcon/client/discover" + "github.com/hashicorp/hcl/v2" + "github.com/zclconf/go-cty/cty" + + "github.com/blackstork-io/fabric/pkg/diagnostics" + "github.com/blackstork-io/fabric/plugin" + "github.com/blackstork-io/fabric/plugin/dataspec" + "github.com/blackstork-io/fabric/plugin/dataspec/constraint" + "github.com/blackstork-io/fabric/plugin/plugindata" +) + +func makeFalconDiscoverHostDetailsDataSource(loader ClientLoaderFn) *plugin.DataSource { + return &plugin.DataSource{ + Doc: "The `falcon_discover_host_details` data source fetches host details from Falcon Discover Host API.", + DataFunc: fetchFalconDiscoverHostDetails(loader), + Config: makeDataSourceConfig(), + Args: &dataspec.RootSpec{ + Attrs: []*dataspec.AttrSpec{ + { + Name: "size", + Type: cty.Number, + Constraints: constraint.Integer | constraint.RequiredNonNull, + Doc: "limit the number of queried items", + }, + { + Name: "filter", + Type: cty.String, + Doc: "Host search expression using Falcon Query Language (FQL)", + }, + }, + }, + } +} + +func fetchFalconDiscoverHostDetails(loader ClientLoaderFn) plugin.RetrieveDataFunc { + return func(ctx context.Context, params *plugin.RetrieveDataParams) (plugindata.Data, diagnostics.Diag) { + cli, err := loader(makeApiConfig(ctx, params.Config)) + if err != nil { + return nil, diagnostics.Diag{{ + Severity: hcl.DiagError, + Summary: "Unable to create falcon client", + Detail: err.Error(), + }} + } + size, _ := params.Args.GetAttrVal("size").AsBigFloat().Int64() + queryHostParams := discover.NewQueryHostsParams().WithDefaults() + queryHostParams.SetLimit(&size) + queryHostParams.SetContext(ctx) + queryHostsResponse, err := cli.Discover().QueryHosts(queryHostParams) + if err != nil { + return nil, diagnostics.Diag{{ + Severity: hcl.DiagError, + Summary: "Failed to query Falcon Discover Hosts", + Detail: err.Error(), + }} + } + if err = falcon.AssertNoError(queryHostsResponse.GetPayload().Errors); err != nil { + return nil, diagnostics.Diag{{ + Severity: hcl.DiagError, + Summary: "Failed to query Falcon Discover Hosts", + Detail: err.Error(), + }} + } + hostIds := queryHostsResponse.GetPayload().Resources + + getHostParams := discover.NewGetHostsParams().WithDefaults() + getHostParams.SetIds(hostIds) + getHostParams.SetContext(ctx) + getHostsResponse, err := cli.Discover().GetHosts(getHostParams) + if err != nil { + return nil, diagnostics.Diag{{ + Severity: hcl.DiagError, + Summary: "Failed to fetch Falcon Discover Hosts", + Detail: err.Error(), + }} + } + if err = falcon.AssertNoError(queryHostsResponse.GetPayload().Errors); err != nil { + return nil, diagnostics.Diag{{ + Severity: hcl.DiagError, + Summary: "Failed to fetch Falcon Discover Hosts", + Detail: err.Error(), + }} + } + + resources := getHostsResponse.GetPayload().Resources + data, err := encodeResponse(resources) + if err != nil { + return nil, diagnostics.Diag{{ + Severity: hcl.DiagError, + Summary: "Failed to parse response", + Detail: err.Error(), + }} + } + return data, nil + } +} diff --git a/internal/crowdstrike/data_falcon_discover_host_details_test.go b/internal/crowdstrike/data_falcon_discover_host_details_test.go new file mode 100644 index 00000000..9fc6f6a4 --- /dev/null +++ b/internal/crowdstrike/data_falcon_discover_host_details_test.go @@ -0,0 +1,176 @@ +package crowdstrike_test + +import ( + "context" + "errors" + "testing" + + "github.com/crowdstrike/gofalcon/falcon" + "github.com/crowdstrike/gofalcon/falcon/client/discover" + "github.com/crowdstrike/gofalcon/falcon/models" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" + "github.com/zclconf/go-cty/cty" + + "github.com/blackstork-io/fabric/internal/crowdstrike" + mocks "github.com/blackstork-io/fabric/mocks/internalpkg/crowdstrike" + "github.com/blackstork-io/fabric/pkg/diagnostics/diagtest" + "github.com/blackstork-io/fabric/plugin" + "github.com/blackstork-io/fabric/plugin/plugindata" + "github.com/blackstork-io/fabric/plugin/plugintest" +) + +type CrowdstrikeDiscoverHostDetailsTestSuite struct { + suite.Suite + plugin *plugin.Schema + cli *mocks.Client + discoverCli *mocks.DiscoverClient +} + +func TestCrowdstrikeDiscoverHostDetailsSuite(t *testing.T) { + suite.Run(t, &CrowdstrikeDiscoverHostDetailsTestSuite{}) +} + +func (s *CrowdstrikeDiscoverHostDetailsTestSuite) SetupSuite() { + s.plugin = crowdstrike.Plugin("1.2.3", func(cfg *falcon.ApiConfig) (client crowdstrike.Client, err error) { + return s.cli, nil + }) +} + +func (s *CrowdstrikeDiscoverHostDetailsTestSuite) SetupTest() { + s.cli = &mocks.Client{} + s.discoverCli = &mocks.DiscoverClient{} +} + +func (s *CrowdstrikeDiscoverHostDetailsTestSuite) TearDownTest() { + s.cli.AssertExpectations(s.T()) +} + +func (s *CrowdstrikeDiscoverHostDetailsTestSuite) DatasourceName() string { + return "falcon_discover_host_details" +} + +func (s *CrowdstrikeDiscoverHostDetailsTestSuite) Datasource() *plugin.DataSource { + return s.plugin.DataSources[s.DatasourceName()] +} + +func (s *CrowdstrikeDiscoverHostDetailsTestSuite) TestSchema() { + schema := s.plugin.DataSources["falcon_cspm_ioms"] + s.Require().NotNil(schema) + s.NotNil(schema.Config) + s.NotNil(schema.Args) + s.NotNil(schema.DataFunc) +} + +func (s *CrowdstrikeDiscoverHostDetailsTestSuite) String(val string) *string { + return &val +} + +func (s *CrowdstrikeDiscoverHostDetailsTestSuite) TestBasic() { + s.cli.On("Discover").Return(s.discoverCli) + s.discoverCli.On("QueryHosts", mock.MatchedBy(func(params *discover.QueryHostsParams) bool { + return params.Limit != nil && *params.Limit == 10 + })).Return(&discover.QueryHostsOK{ + Payload: &models.MsaspecQueryResponse{ + Resources: []string{"test_host_1", "test_host_2"}, + }, + }, nil) + s.discoverCli.On("GetHosts", mock.MatchedBy(func(params *discover.GetHostsParams) bool { + return params.Ids[0] == "test_host_1" && params.Ids[1] == "test_host_2" + })).Return(&discover.GetHostsOK{ + Payload: &models.DomainDiscoverAPIHostEntitiesResponse{ + Resources: []*models.DomainDiscoverAPIHost{ + { + Cid: s.String("test_cid_1"), + City: "Dublin", + }, + { + Cid: s.String("test_cid_2"), + City: "London", + }, + }, + }, + }, nil) + ctx := context.Background() + data, diags := s.plugin.RetrieveData(ctx, s.DatasourceName(), &plugin.RetrieveDataParams{ + Config: plugintest.NewTestDecoder(s.T(), s.Datasource().Config). + SetAttr("client_id", cty.StringVal("test")). + SetAttr("client_secret", cty.StringVal("test")). + Decode(), + Args: plugintest.NewTestDecoder(s.T(), s.Datasource().Args). + SetAttr("size", cty.NumberIntVal(10)). + Decode(), + }) + s.Require().Nil(diags) + list := data.AsPluginData().(plugindata.List) + s.Len(list, 2) + s.Subset(list[0], plugindata.Map{ + "cid": plugindata.String("test_cid_1"), + "city": plugindata.String("Dublin"), + }) + s.Subset(list[1], plugindata.Map{ + "cid": plugindata.String("test_cid_2"), + "city": plugindata.String("London"), + }) +} + +func (s *CrowdstrikeDiscoverHostDetailsTestSuite) TestPayloadErrors() { + s.cli.On("Discover").Return(s.discoverCli) + s.discoverCli.On("QueryHosts", mock.MatchedBy(func(params *discover.QueryHostsParams) bool { + return params.Limit != nil && *params.Limit == 10 + })).Return(&discover.QueryHostsOK{ + Payload: &models.MsaspecQueryResponse{ + Errors: []*models.MsaAPIError{{ + Message: s.String("something went wrong"), + }}, + }, + }, nil) + ctx := context.Background() + _, diags := s.plugin.RetrieveData(ctx, s.DatasourceName(), &plugin.RetrieveDataParams{ + Config: plugintest.NewTestDecoder(s.T(), s.Datasource().Config). + SetAttr("client_id", cty.StringVal("test")). + SetAttr("client_secret", cty.StringVal("test")). + Decode(), + Args: plugintest.NewTestDecoder(s.T(), s.Datasource().Args). + SetAttr("size", cty.NumberIntVal(10)). + Decode(), + }) + diagtest.Asserts{{ + diagtest.IsError, + diagtest.SummaryContains("Failed to query Falcon Discover Hosts"), + diagtest.DetailContains("something went wrong"), + }}.AssertMatch(s.T(), diags, nil) +} + +func (s *CrowdstrikeDiscoverHostDetailsTestSuite) TestError() { + s.cli.On("Discover").Return(s.discoverCli) + s.discoverCli.On("QueryHosts", mock.MatchedBy(func(params *discover.QueryHostsParams) bool { + return params.Limit != nil && *params.Limit == 10 + })).Return(nil, errors.New("something went wrong")) + ctx := context.Background() + _, diags := s.plugin.RetrieveData(ctx, s.DatasourceName(), &plugin.RetrieveDataParams{ + Config: plugintest.NewTestDecoder(s.T(), s.Datasource().Config). + SetAttr("client_id", cty.StringVal("test")). + SetAttr("client_secret", cty.StringVal("test")). + Decode(), + Args: plugintest.NewTestDecoder(s.T(), s.Datasource().Args). + SetAttr("size", cty.NumberIntVal(10)). + Decode(), + }) + diagtest.Asserts{{ + diagtest.IsError, + diagtest.SummaryContains("Failed to query Falcon Discover Hosts"), + diagtest.DetailContains("something went wrong"), + }}.AssertMatch(s.T(), diags, nil) +} + +func (s *CrowdstrikeDiscoverHostDetailsTestSuite) TestMissingArgs() { + plugintest.NewTestDecoder( + s.T(), + s.Datasource().Args, + ).Decode([]diagtest.Assert{ + diagtest.IsError, + diagtest.SummaryEquals("Missing required attribute"), + diagtest.DetailContains("size"), + }) +} diff --git a/internal/crowdstrike/plugin.go b/internal/crowdstrike/plugin.go index 2cb258a3..98f5f12a 100644 --- a/internal/crowdstrike/plugin.go +++ b/internal/crowdstrike/plugin.go @@ -9,6 +9,7 @@ import ( "github.com/crowdstrike/gofalcon/falcon/client" "github.com/crowdstrike/gofalcon/falcon/client/cspm_registration" "github.com/crowdstrike/gofalcon/falcon/client/detects" + "github.com/crowdstrike/gofalcon/falcon/client/discover" "github.com/crowdstrike/gofalcon/falcon/client/intel" "github.com/crowdstrike/gofalcon/falcon/client/spotlight_vulnerabilities" "github.com/zclconf/go-cty/cty" @@ -36,11 +37,17 @@ type IntelClient interface { QueryIntelIndicatorEntities(params *intel.QueryIntelIndicatorEntitiesParams, opts ...intel.ClientOption) (*intel.QueryIntelIndicatorEntitiesOK, error) } +type DiscoverClient interface { + QueryHosts(params *discover.QueryHostsParams, opts ...discover.ClientOption) (*discover.QueryHostsOK, error) + GetHosts(params *discover.GetHostsParams, opts ...discover.ClientOption) (*discover.GetHostsOK, error) +} + type Client interface { CspmRegistration() CspmRegistrationClient Detects() DetectsClient SpotlightVulnerabilities() SpotVulnerabilitiesClient Intel() IntelClient + Discover() DiscoverClient } type ClientAdapter struct { @@ -63,6 +70,10 @@ func (c *ClientAdapter) Intel() IntelClient { return c.client.Intel } +func (c *ClientAdapter) Discover() DiscoverClient { + return c.client.Discover +} + type ClientLoaderFn func(cfg *falcon.ApiConfig) (client Client, err error) var DefaultClientLoader = func(cfg *falcon.ApiConfig) (Client, error) { @@ -81,10 +92,11 @@ func Plugin(version string, loader ClientLoaderFn) *plugin.Schema { Name: "blackstork/crowdstrike", Version: version, DataSources: plugin.DataSources{ - "falcon_cspm_ioms": makeFalconCspmIomsDataSource(loader), - "falcon_detection_details": makeFalconDetectionDetailsDataSource(loader), - "falcon_vulnerabilities": makeFalconVulnerabilitiesDataSource(loader), - "falcon_intel_indicators": makeFalconIntelIndicatorsDataSource(loader), + "falcon_cspm_ioms": makeFalconCspmIomsDataSource(loader), + "falcon_detection_details": makeFalconDetectionDetailsDataSource(loader), + "falcon_vulnerabilities": makeFalconVulnerabilitiesDataSource(loader), + "falcon_intel_indicators": makeFalconIntelIndicatorsDataSource(loader), + "falcon_discover_host_details": makeFalconDiscoverHostDetailsDataSource(loader), }, } } diff --git a/mocks/internalpkg/crowdstrike/client.go b/mocks/internalpkg/crowdstrike/client.go index 5baddb5c..ff25bd14 100644 --- a/mocks/internalpkg/crowdstrike/client.go +++ b/mocks/internalpkg/crowdstrike/client.go @@ -114,6 +114,53 @@ func (_c *Client_Detects_Call) RunAndReturn(run func() crowdstrike.DetectsClient return _c } +// Discover provides a mock function with given fields: +func (_m *Client) Discover() crowdstrike.DiscoverClient { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Discover") + } + + var r0 crowdstrike.DiscoverClient + if rf, ok := ret.Get(0).(func() crowdstrike.DiscoverClient); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(crowdstrike.DiscoverClient) + } + } + + return r0 +} + +// Client_Discover_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Discover' +type Client_Discover_Call struct { + *mock.Call +} + +// Discover is a helper method to define mock.On call +func (_e *Client_Expecter) Discover() *Client_Discover_Call { + return &Client_Discover_Call{Call: _e.mock.On("Discover")} +} + +func (_c *Client_Discover_Call) Run(run func()) *Client_Discover_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *Client_Discover_Call) Return(_a0 crowdstrike.DiscoverClient) *Client_Discover_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *Client_Discover_Call) RunAndReturn(run func() crowdstrike.DiscoverClient) *Client_Discover_Call { + _c.Call.Return(run) + return _c +} + // Intel provides a mock function with given fields: func (_m *Client) Intel() crowdstrike.IntelClient { ret := _m.Called() diff --git a/mocks/internalpkg/crowdstrike/discover_client.go b/mocks/internalpkg/crowdstrike/discover_client.go new file mode 100644 index 00000000..67ad1a25 --- /dev/null +++ b/mocks/internalpkg/crowdstrike/discover_client.go @@ -0,0 +1,181 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package crowdstrike_mocks + +import ( + discover "github.com/crowdstrike/gofalcon/falcon/client/discover" + mock "github.com/stretchr/testify/mock" +) + +// DiscoverClient is an autogenerated mock type for the DiscoverClient type +type DiscoverClient struct { + mock.Mock +} + +type DiscoverClient_Expecter struct { + mock *mock.Mock +} + +func (_m *DiscoverClient) EXPECT() *DiscoverClient_Expecter { + return &DiscoverClient_Expecter{mock: &_m.Mock} +} + +// GetHosts provides a mock function with given fields: params, opts +func (_m *DiscoverClient) GetHosts(params *discover.GetHostsParams, opts ...discover.ClientOption) (*discover.GetHostsOK, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, params) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for GetHosts") + } + + var r0 *discover.GetHostsOK + var r1 error + if rf, ok := ret.Get(0).(func(*discover.GetHostsParams, ...discover.ClientOption) (*discover.GetHostsOK, error)); ok { + return rf(params, opts...) + } + if rf, ok := ret.Get(0).(func(*discover.GetHostsParams, ...discover.ClientOption) *discover.GetHostsOK); ok { + r0 = rf(params, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*discover.GetHostsOK) + } + } + + if rf, ok := ret.Get(1).(func(*discover.GetHostsParams, ...discover.ClientOption) error); ok { + r1 = rf(params, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DiscoverClient_GetHosts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetHosts' +type DiscoverClient_GetHosts_Call struct { + *mock.Call +} + +// GetHosts is a helper method to define mock.On call +// - params *discover.GetHostsParams +// - opts ...discover.ClientOption +func (_e *DiscoverClient_Expecter) GetHosts(params interface{}, opts ...interface{}) *DiscoverClient_GetHosts_Call { + return &DiscoverClient_GetHosts_Call{Call: _e.mock.On("GetHosts", + append([]interface{}{params}, opts...)...)} +} + +func (_c *DiscoverClient_GetHosts_Call) Run(run func(params *discover.GetHostsParams, opts ...discover.ClientOption)) *DiscoverClient_GetHosts_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]discover.ClientOption, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(discover.ClientOption) + } + } + run(args[0].(*discover.GetHostsParams), variadicArgs...) + }) + return _c +} + +func (_c *DiscoverClient_GetHosts_Call) Return(_a0 *discover.GetHostsOK, _a1 error) *DiscoverClient_GetHosts_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DiscoverClient_GetHosts_Call) RunAndReturn(run func(*discover.GetHostsParams, ...discover.ClientOption) (*discover.GetHostsOK, error)) *DiscoverClient_GetHosts_Call { + _c.Call.Return(run) + return _c +} + +// QueryHosts provides a mock function with given fields: params, opts +func (_m *DiscoverClient) QueryHosts(params *discover.QueryHostsParams, opts ...discover.ClientOption) (*discover.QueryHostsOK, error) { + _va := make([]interface{}, len(opts)) + for _i := range opts { + _va[_i] = opts[_i] + } + var _ca []interface{} + _ca = append(_ca, params) + _ca = append(_ca, _va...) + ret := _m.Called(_ca...) + + if len(ret) == 0 { + panic("no return value specified for QueryHosts") + } + + var r0 *discover.QueryHostsOK + var r1 error + if rf, ok := ret.Get(0).(func(*discover.QueryHostsParams, ...discover.ClientOption) (*discover.QueryHostsOK, error)); ok { + return rf(params, opts...) + } + if rf, ok := ret.Get(0).(func(*discover.QueryHostsParams, ...discover.ClientOption) *discover.QueryHostsOK); ok { + r0 = rf(params, opts...) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*discover.QueryHostsOK) + } + } + + if rf, ok := ret.Get(1).(func(*discover.QueryHostsParams, ...discover.ClientOption) error); ok { + r1 = rf(params, opts...) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DiscoverClient_QueryHosts_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'QueryHosts' +type DiscoverClient_QueryHosts_Call struct { + *mock.Call +} + +// QueryHosts is a helper method to define mock.On call +// - params *discover.QueryHostsParams +// - opts ...discover.ClientOption +func (_e *DiscoverClient_Expecter) QueryHosts(params interface{}, opts ...interface{}) *DiscoverClient_QueryHosts_Call { + return &DiscoverClient_QueryHosts_Call{Call: _e.mock.On("QueryHosts", + append([]interface{}{params}, opts...)...)} +} + +func (_c *DiscoverClient_QueryHosts_Call) Run(run func(params *discover.QueryHostsParams, opts ...discover.ClientOption)) *DiscoverClient_QueryHosts_Call { + _c.Call.Run(func(args mock.Arguments) { + variadicArgs := make([]discover.ClientOption, len(args)-1) + for i, a := range args[1:] { + if a != nil { + variadicArgs[i] = a.(discover.ClientOption) + } + } + run(args[0].(*discover.QueryHostsParams), variadicArgs...) + }) + return _c +} + +func (_c *DiscoverClient_QueryHosts_Call) Return(_a0 *discover.QueryHostsOK, _a1 error) *DiscoverClient_QueryHosts_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DiscoverClient_QueryHosts_Call) RunAndReturn(run func(*discover.QueryHostsParams, ...discover.ClientOption) (*discover.QueryHostsOK, error)) *DiscoverClient_QueryHosts_Call { + _c.Call.Return(run) + return _c +} + +// NewDiscoverClient creates a new instance of DiscoverClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewDiscoverClient(t interface { + mock.TestingT + Cleanup(func()) +}) *DiscoverClient { + mock := &DiscoverClient{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +}