go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/detector/parser_sol.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package detector
     5  
     6  import (
     7  	"fmt"
     8  	"regexp"
     9  	"strings"
    10  )
    11  
    12  type SolarisRelease struct {
    13  	ID      string
    14  	Title   string
    15  	Release string
    16  }
    17  
    18  var solarisVersionRegex = regexp.MustCompile(`^\s+((?:[\w]\s*)*Solaris)\s([\w\d.]+)`)
    19  
    20  func ParseSolarisRelease(content string) (*SolarisRelease, error) {
    21  	m := solarisVersionRegex.FindStringSubmatch(content)
    22  	if len(m) < 2 {
    23  		return nil, fmt.Errorf("could not parse solaris version: %s", content)
    24  	}
    25  
    26  	id := strings.ToLower(m[1])
    27  	id = strings.Replace(id, "oracle", "", 1)
    28  	id = strings.ReplaceAll(id, " ", "")
    29  
    30  	return &SolarisRelease{
    31  		ID:      id,
    32  		Title:   m[1],
    33  		Release: m[2],
    34  	}, nil
    35  }