diff --git a/integration b/integration index 75327e74..fa8df1dd 160000 --- a/integration +++ b/integration @@ -1 +1 @@ -Subproject commit 75327e743196370d257249acbf3fa1520ef0c127 +Subproject commit fa8df1dd6c22b439508da4ae36082eca0c3434b1 diff --git a/scanner/serverapi.go b/scanner/scanner.go similarity index 96% rename from scanner/serverapi.go rename to scanner/scanner.go index b272d872..fc62d60c 100644 --- a/scanner/serverapi.go +++ b/scanner/scanner.go @@ -580,49 +580,42 @@ func (s Scanner) detectContainerOSesOnServer(containerHost osTypeInterface) (ose return oses } -func (s Scanner) detectOS(c config.ServerInfo) (osType osTypeInterface) { - var itsMe bool - var fatalErr error - - if itsMe, osType, _ = detectPseudo(c); itsMe { - return +func (s Scanner) detectOS(c config.ServerInfo) osTypeInterface { + if itsMe, osType, _ := detectPseudo(c); itsMe { + return osType } - itsMe, osType, fatalErr = s.detectDebianWithRetry(c) - if fatalErr != nil { - osType.setErrs([]error{ - xerrors.Errorf("Failed to detect OS: %w", fatalErr)}) - return + if itsMe, osType, fatalErr := s.detectDebianWithRetry(c); fatalErr != nil { + osType.setErrs([]error{xerrors.Errorf("Failed to detect OS: %w", fatalErr)}) + return osType + } else if itsMe { + logging.Log.Debugf("Debian based Linux. Host: %s:%s", c.Host, c.Port) + return osType } - if itsMe { - logging.Log.Debugf("Debian like Linux. Host: %s:%s", c.Host, c.Port) - return + if itsMe, osType := detectRedhat(c); itsMe { + logging.Log.Debugf("Redhat based Linux. Host: %s:%s", c.Host, c.Port) + return osType } - if itsMe, osType = detectRedhat(c); itsMe { - logging.Log.Debugf("Redhat like Linux. Host: %s:%s", c.Host, c.Port) - return - } - - if itsMe, osType = detectSUSE(c); itsMe { + if itsMe, osType := detectSUSE(c); itsMe { logging.Log.Debugf("SUSE Linux. Host: %s:%s", c.Host, c.Port) - return + return osType } - if itsMe, osType = detectFreebsd(c); itsMe { + if itsMe, osType := detectFreebsd(c); itsMe { logging.Log.Debugf("FreeBSD. Host: %s:%s", c.Host, c.Port) - return + return osType } - if itsMe, osType = detectAlpine(c); itsMe { + if itsMe, osType := detectAlpine(c); itsMe { logging.Log.Debugf("Alpine. Host: %s:%s", c.Host, c.Port) - return + return osType } - //TODO darwin https://github.com/mizzy/specinfra/blob/master/lib/specinfra/helper/detect_os/darwin.rb + osType := &unknown{base{ServerInfo: c}} osType.setErrs([]error{xerrors.New("Unknown OS Type")}) - return + return osType } // Retry as it may stall on the first SSH connection diff --git a/scanner/serverapi_test.go b/scanner/scanner_test.go similarity index 100% rename from scanner/serverapi_test.go rename to scanner/scanner_test.go