From af1a9f1eebd5f511f1d2e1857650e8c0f5a7b7e7 Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 30 Aug 2018 20:40:21 +0900 Subject: [PATCH] discoveryConfig added --- discovery/DiscoverHost.go | 53 ++---------------------------------- discovery/DiscoverPort.go | 2 ++ discovery/DiscoverService.go | 2 ++ discovery/DiscoveryConfig.go | 2 +- 4 files changed, 7 insertions(+), 52 deletions(-) diff --git a/discovery/DiscoverHost.go b/discovery/DiscoverHost.go index f3cd4cf..c09d228 100644 --- a/discovery/DiscoverHost.go +++ b/discovery/DiscoverHost.go @@ -1,14 +1,12 @@ package discovery import ( - "fmt" - "net" - - "git.loafle.net/commons/util-go/net/cidr" "git.loafle.net/overflow/model/meta" ) type DiscoverHost struct { + DiscoveryConfig *DiscoveryConfig `json:"discoveryConfig,omitempty"` + MetaIPType *meta.MetaIPType `json:"metaIPType,omitempty"` FirstScanRange string `json:"firstScanRange,omitempty"` @@ -18,50 +16,3 @@ type DiscoverHost struct { DiscoverPort *DiscoverPort `json:"discoverPort,omitempty"` } - -func (dh *DiscoverHost) TargetHosts(network string) ([]net.IP, error) { - cr, err := cidr.NewCIDRRanger(network) - if nil != err { - return nil, err - } - - var firstIP net.IP - if "" != dh.FirstScanRange { - firstIP = net.ParseIP(dh.FirstScanRange) - if nil == firstIP { - return nil, fmt.Errorf("IP(%v) of FirstScanRange host is not valid", firstIP) - } - } - var lastIP net.IP - if "" != dh.LastScanRange { - lastIP = net.ParseIP(dh.LastScanRange) - if nil == lastIP { - return nil, fmt.Errorf("IP(%v) of LastScanRange host is not valid", lastIP) - } - } - - includeIPs := make([]net.IP, 0) - for _, iHost := range dh.IncludeHosts { - iIP := net.ParseIP(iHost) - if nil == iIP { - return nil, fmt.Errorf("IP(%v) of include host is not valid", iHost) - } - includeIPs = append(includeIPs, iIP) - } - - excludeIPs := make([]net.IP, 0) - for _, eHost := range dh.ExcludeHosts { - eIP := net.ParseIP(eHost) - if nil == eIP { - return nil, fmt.Errorf("IP(%v) of exclude host is not valid", eHost) - } - excludeIPs = append(excludeIPs, eIP) - } - - ranges, err := cr.Ranges(firstIP, lastIP, includeIPs, excludeIPs) - if nil != err { - return nil, err - } - - return ranges, nil -} diff --git a/discovery/DiscoverPort.go b/discovery/DiscoverPort.go index 8e7e37f..196f7d3 100644 --- a/discovery/DiscoverPort.go +++ b/discovery/DiscoverPort.go @@ -1,6 +1,8 @@ package discovery type DiscoverPort struct { + DiscoveryConfig *DiscoveryConfig `json:"discoveryConfig,omitempty"` + FirstScanRange int `json:"firstScanRange,omitempty"` LastScanRange int `json:"lastScanRange,omitempty"` ExcludePorts []int `json:"excludePorts,omitempty"` diff --git a/discovery/DiscoverService.go b/discovery/DiscoverService.go index 5b32960..48088d9 100644 --- a/discovery/DiscoverService.go +++ b/discovery/DiscoverService.go @@ -1,5 +1,7 @@ package discovery type DiscoverService struct { + DiscoveryConfig *DiscoveryConfig `json:"discoveryConfig,omitempty"` + IncludeServices []string `json:"includeServices,omitempty"` } diff --git a/discovery/DiscoveryConfig.go b/discovery/DiscoveryConfig.go index e24517b..f3dfa0c 100644 --- a/discovery/DiscoveryConfig.go +++ b/discovery/DiscoveryConfig.go @@ -5,5 +5,5 @@ import ( ) type DiscoveryConfig struct { - Credentials credential.CredentialMap `json:"credentials,omitempty"` + Credentials credential.CredentialsMap `json:"credentials,omitempty"` }