github.com/google/osv-scalibr@v0.4.1/guidedremediation/internal/util/util.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 util implements some utility functions for guided remediation. 16 package util 17 18 import ( 19 "deps.dev/util/resolve" 20 "github.com/ossf/osv-schema/bindings/go/osvconstants" 21 ) 22 23 // DepsDevToOSVEcosystem converts a deps.dev resolve.System into an osvschema.Ecosystem. 24 // Unknown / invalid Systems become the empty ecosystem `osvschema.Ecosystem("")`. 25 func DepsDevToOSVEcosystem(sys resolve.System) osvconstants.Ecosystem { 26 switch sys { 27 case resolve.Maven: 28 return osvconstants.EcosystemMaven 29 case resolve.NPM: 30 return osvconstants.EcosystemNPM 31 case resolve.PyPI: 32 return osvconstants.EcosystemPyPI 33 case resolve.UnknownSystem: 34 fallthrough 35 default: 36 return "" 37 } 38 } 39 40 // OSVToDepsDevEcosystem converts an osvschema.Ecosystem into a deps.dev resolve.System. 41 // Unknown / invalid Ecosystems become `resolve.UnknownEcosystem`. 42 func OSVToDepsDevEcosystem(sys osvconstants.Ecosystem) resolve.System { 43 switch sys { 44 case osvconstants.EcosystemMaven: 45 return resolve.Maven 46 case osvconstants.EcosystemNPM: 47 return resolve.NPM 48 case osvconstants.EcosystemPyPI: 49 return resolve.PyPI 50 case 51 osvconstants.EcosystemAlmaLinux, 52 osvconstants.EcosystemAlpine, 53 osvconstants.EcosystemAndroid, 54 osvconstants.EcosystemBioconductor, 55 osvconstants.EcosystemBitnami, 56 osvconstants.EcosystemChainguard, 57 osvconstants.EcosystemConanCenter, 58 osvconstants.EcosystemCRAN, 59 osvconstants.EcosystemCratesIO, 60 osvconstants.EcosystemDebian, 61 osvconstants.EcosystemGHC, 62 osvconstants.EcosystemGitHubActions, 63 osvconstants.EcosystemGo, 64 osvconstants.EcosystemHackage, 65 osvconstants.EcosystemHex, 66 osvconstants.EcosystemKubernetes, 67 osvconstants.EcosystemLinux, 68 osvconstants.EcosystemMageia, 69 osvconstants.EcosystemMinimOS, 70 osvconstants.EcosystemNuGet, 71 osvconstants.EcosystemOpenSUSE, 72 osvconstants.EcosystemOSSFuzz, 73 osvconstants.EcosystemPackagist, 74 osvconstants.EcosystemPhotonOS, 75 osvconstants.EcosystemPub, 76 osvconstants.EcosystemRedHat, 77 osvconstants.EcosystemRockyLinux, 78 osvconstants.EcosystemRubyGems, 79 osvconstants.EcosystemSUSE, 80 osvconstants.EcosystemSwiftURL, 81 osvconstants.EcosystemUbuntu, 82 osvconstants.EcosystemWolfi: 83 fallthrough 84 default: 85 return resolve.UnknownSystem 86 } 87 }