diff --git a/cmd/scan.go b/cmd/scan.go index 65baa16..e48173c 100644 --- a/cmd/scan.go +++ b/cmd/scan.go @@ -78,26 +78,17 @@ var scanCmd = &cobra.Command{ } // generate a slice of all hosts to scan from subnets - targetHosts = append(targetHosts, magellan.GenerateHostsWithSubnet(subnet, &subnetMask, ports, scheme)...) - } - - // convert everything into full addresses for scanning - for _, host := range hosts { - var targets []string - for _, port := range ports { - _ = port - targets = append(targets, host) - } - targetHosts = append(targetHosts, targets) + subnetHosts := magellan.GenerateHostsWithSubnet(subnet, &subnetMask, ports, scheme) + targetHosts = append(targetHosts, subnetHosts...) } // if there are no target hosts, then there's nothing to do if len(targetHosts) <= 0 { - log.Warn().Msg("nothing to do (no target hosts)") + log.Warn().Msg("nothing to do (no valid target hosts)") return } else { if len(targetHosts[0]) <= 0 { - log.Warn().Msg("nothing to do (no target hosts)") + log.Warn().Msg("nothing to do (no valid target hosts)") return } } diff --git a/internal/cache/cache.go b/internal/cache/cache.go index d4dabed..96513de 100644 --- a/internal/cache/cache.go +++ b/internal/cache/cache.go @@ -1,6 +1,8 @@ package cache -import "database/sql/driver" +import ( + "database/sql/driver" +) type Cache[T any] interface { CreateIfNotExists(path string) (driver.Connector, error) diff --git a/internal/cache/storage.go b/internal/cache/storage.go new file mode 100644 index 0000000..06b42a9 --- /dev/null +++ b/internal/cache/storage.go @@ -0,0 +1,28 @@ +package cache + +import "github.com/google/uuid" + +type Storage[T any] interface { + Save(id uuid.UUID, val T, varargs ...T) error + Get(id uuid.UUID) (T, error) + Update(id uuid.UUID, val T) error + Delete(id uuid.UUID) error +} + +type Compute struct{} +type BMC struct{} + +type Node[T any] struct { +} + +type NodeStorage struct { + Storage[Node[Compute]] +} + +type BMCStorage struct { + Storage[Node[BMC]] +} + +func (ns *NodeStorage) Save(id uuid.UUID, val Node[Compute], varargs ...Node[Compute]) { + +} diff --git a/internal/util/net.go b/internal/util/net.go index 5999ac7..50bbbfa 100644 --- a/internal/util/net.go +++ b/internal/util/net.go @@ -145,31 +145,27 @@ func FormatIPUrls(ips []string, ports []int, scheme string, verbose bool) [][]st // format each positional arg as a complete URL var formattedHosts [][]string for _, ip := range ips { - // if parsing completely fails, try to build new URL object + if scheme == "" { + scheme = "https" + } + // make an entirely new object since we're expecting just IPs uri := &url.URL{ Scheme: scheme, Host: ip, } - // check if scheme is set, if not set it with flag or default value ('https' if flag is not set) - if uri.Scheme == "" { - if scheme != "" { - uri.Scheme = scheme - } else { - // hardcoded assumption - uri.Scheme = "https" - } - } - // tidy up slashes and update arg with new value uri.Path = strings.TrimSuffix(uri.Path, "/") uri.Path = strings.ReplaceAll(uri.Path, "//", "/") // for hosts with unspecified ports, add ports to scan from flag if uri.Port() == "" { + if len(ports) == 0 { + ports = append(ports, 443) + } var tmp []string for _, port := range ports { - uri.Host = fmt.Sprintf("%s:%d", ip, port) + uri.Host += fmt.Sprintf(":%d", port) tmp = append(tmp, uri.String()) } formattedHosts = append(formattedHosts, tmp)