github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/flag/cloud_flags.go (about)

     1  package flag
     2  
     3  import "time"
     4  
     5  var (
     6  	cloudUpdateCacheFlag = Flag{
     7  		Name:       "update-cache",
     8  		ConfigName: "cloud.update-cache",
     9  		Default:    false,
    10  		Usage:      "Update the cache for the applicable cloud provider instead of using cached results.",
    11  	}
    12  	cloudMaxCacheAgeFlag = Flag{
    13  		Name:       "max-cache-age",
    14  		ConfigName: "cloud.max-cache-age",
    15  		Default:    time.Hour * 24,
    16  		Usage:      "The maximum age of the cloud cache. Cached data will be requeried from the cloud provider if it is older than this.",
    17  	}
    18  )
    19  
    20  type CloudFlagGroup struct {
    21  	UpdateCache *Flag
    22  	MaxCacheAge *Flag
    23  }
    24  
    25  type CloudOptions struct {
    26  	MaxCacheAge time.Duration
    27  	UpdateCache bool
    28  }
    29  
    30  func NewCloudFlagGroup() *CloudFlagGroup {
    31  	return &CloudFlagGroup{
    32  		UpdateCache: &cloudUpdateCacheFlag,
    33  		MaxCacheAge: &cloudMaxCacheAgeFlag,
    34  	}
    35  }
    36  
    37  func (f *CloudFlagGroup) Name() string {
    38  	return "Cloud"
    39  }
    40  
    41  func (f *CloudFlagGroup) Flags() []*Flag {
    42  	return []*Flag{f.UpdateCache, f.MaxCacheAge}
    43  }
    44  
    45  func (f *CloudFlagGroup) ToOptions() CloudOptions {
    46  	return CloudOptions{
    47  		UpdateCache: getBool(f.UpdateCache),
    48  		MaxCacheAge: getDuration(f.MaxCacheAge),
    49  	}
    50  }