github.com/google/osv-scalibr@v0.4.1/annotator/osduplicate/rpm/rpm.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 rpm implements an annotator for language packages that have already been found in
    16  // RPM OS packages.
    17  package rpm
    18  
    19  import (
    20  	"time"
    21  
    22  	"github.com/google/osv-scalibr/annotator"
    23  	"github.com/google/osv-scalibr/plugin"
    24  )
    25  
    26  const (
    27  	// Name of the Annotator.
    28  	Name = "vex/os-duplicate/rpm"
    29  
    30  	defaultTimeout = 5 * time.Minute
    31  )
    32  
    33  // Config contains RPM specific configuration values
    34  type Config struct {
    35  	// Timeout is the timeout duration for parsing the RPM database.
    36  	Timeout time.Duration
    37  }
    38  
    39  // DefaultConfig returns the default configuration values for the Annotator.
    40  func DefaultConfig() Config {
    41  	return Config{
    42  		Timeout: defaultTimeout,
    43  	}
    44  }
    45  
    46  // Annotator adds annotations to language packages that have already been found in RPM OS packages.
    47  type Annotator struct {
    48  	Timeout time.Duration
    49  }
    50  
    51  // New returns a new Annotator.
    52  //
    53  // For most use cases, initialize with:
    54  // ```
    55  // a := New(DefaultConfig())
    56  // ```
    57  func New(cfg Config) *Annotator {
    58  	return &Annotator{
    59  		Timeout: cfg.Timeout,
    60  	}
    61  }
    62  
    63  // NewDefault returns the Annotator with the default config settings.
    64  func NewDefault() annotator.Annotator { return New(DefaultConfig()) }
    65  
    66  // Name of the annotator.
    67  func (Annotator) Name() string { return Name }
    68  
    69  // Version of the annotator.
    70  func (Annotator) Version() int { return 0 }
    71  
    72  // Requirements of the annotator.
    73  func (Annotator) Requirements() *plugin.Capabilities {
    74  	return &plugin.Capabilities{OS: plugin.OSLinux}
    75  }