github.com/google/osv-scalibr@v0.4.1/extractor/filesystem/os/kernel/vmlinuz/metadata/metadata.go (about)

     1  // Copyright 2025 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package metadata defines a metadata struct for kernel vmlinuz files.
    16  package metadata
    17  
    18  import "github.com/google/osv-scalibr/log"
    19  
    20  // Metadata holds parsing information for a kernel vmlinuz file.
    21  type Metadata struct {
    22  	Name              string
    23  	Version           string
    24  	Architecture      string
    25  	ExtendedVersion   string
    26  	Format            string
    27  	SwapDevice        int32
    28  	RootDevice        int32
    29  	VideoMode         string
    30  	OSID              string
    31  	OSVersionCodename string
    32  	OSVersionID       string
    33  	RWRootFS          bool
    34  }
    35  
    36  // ToNamespace extracts the PURL namespace from the metadata.
    37  func (m *Metadata) ToNamespace() string {
    38  	if m.OSID != "" {
    39  		return m.OSID
    40  	}
    41  	log.Errorf("os-release[ID] not set, fallback to 'linux'")
    42  	return "linux"
    43  }
    44  
    45  // ToDistro extracts the OS distro from the metadata.
    46  func (m *Metadata) ToDistro() string {
    47  	// fallback: e.g. 22.04
    48  	if m.OSVersionID != "" {
    49  		return m.OSVersionID
    50  	}
    51  	log.Errorf("VERSION_ID not set in os-release")
    52  	return ""
    53  }