github.com/google/osv-scalibr@v0.4.1/guidedremediation/internal/suggest/suggest.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 suggest provides the functionality to suggest dependency update patch. 16 package suggest 17 18 import ( 19 "context" 20 "errors" 21 "fmt" 22 23 "deps.dev/util/resolve" 24 "github.com/google/osv-scalibr/guidedremediation/internal/manifest" 25 "github.com/google/osv-scalibr/guidedremediation/options" 26 "github.com/google/osv-scalibr/guidedremediation/result" 27 ) 28 29 // A PatchSuggester provides an ecosystem-specific method for 'suggesting' 30 // Patch for dependency updates. 31 type PatchSuggester interface { 32 // Suggest returns the Patch required to update the dependencies to 33 // a newer version based on the given options. 34 Suggest(ctx context.Context, mf manifest.Manifest, opts options.UpdateOptions) (result.Patch, error) 35 } 36 37 // NewSuggester returns the PatchSuggester based on the specified ecosystem. 38 func NewSuggester(system resolve.System) (PatchSuggester, error) { 39 switch system { 40 case resolve.Maven: 41 return &MavenSuggester{}, nil 42 case resolve.NPM: 43 return nil, errors.New("npm not yet supported") 44 case resolve.PyPI: 45 return nil, errors.New("PyPI not yet supported") 46 case resolve.UnknownSystem: 47 return nil, errors.New("unknown system") 48 default: 49 return nil, fmt.Errorf("unsupported ecosystem: %v", system) 50 } 51 }