github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/detector/ospkg/version/version.go (about)

     1  package version
     2  
     3  import (
     4  	"strings"
     5  	"time"
     6  
     7  	"k8s.io/utils/clock"
     8  
     9  	ftypes "github.com/devseccon/trivy/pkg/fanal/types"
    10  	"github.com/devseccon/trivy/pkg/log"
    11  )
    12  
    13  // Major returns the major version
    14  // e.g. 8.1 => 8
    15  func Major(osVer string) string {
    16  	osVer, _, _ = strings.Cut(osVer, ".")
    17  	return osVer
    18  }
    19  
    20  // Minor returns the major and minor version
    21  // e.g. 3.17.2 => 3.17
    22  func Minor(osVer string) string {
    23  	major, s, ok := strings.Cut(osVer, ".")
    24  	if !ok {
    25  		return osVer
    26  	}
    27  	minor, _, _ := strings.Cut(s, ".")
    28  	return major + "." + minor
    29  }
    30  
    31  func Supported(c clock.Clock, eolDates map[string]time.Time, osFamily ftypes.OSType, osVer string) bool {
    32  	eol, ok := eolDates[osVer]
    33  	if !ok {
    34  		log.Logger.Warnf("This OS version is not on the EOL list: %s %s", osFamily, osVer)
    35  		return true // can be the latest version
    36  	}
    37  	return c.Now().Before(eol)
    38  }