github.com/google/osv-scalibr@v0.4.1/extractor/filesystem/os/kernel/module/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 modules. 16 package metadata 17 18 import "github.com/google/osv-scalibr/log" 19 20 // Metadata holds parsing information for a kernel module. 21 type Metadata struct { 22 PackageName string 23 PackageVersion string 24 PackageVermagic string 25 PackageSourceVersionIdentifier string 26 OSID string 27 OSVersionCodename string 28 OSVersionID string 29 PackageAuthor string 30 } 31 32 // ToNamespace extracts the PURL namespace from the metadata. 33 func (m *Metadata) ToNamespace() string { 34 if m.OSID != "" { 35 return m.OSID 36 } 37 log.Errorf("os-release[ID] not set, fallback to 'linux'") 38 return "linux" 39 } 40 41 // ToDistro extracts the OS distro from the metadata. 42 func (m *Metadata) ToDistro() string { 43 // fallback: e.g. 22.04 44 if m.OSVersionID != "" { 45 return m.OSVersionID 46 } 47 log.Errorf("VERSION_ID not set in os-release") 48 return "" 49 }