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

     1  package flag
     2  
     3  var (
     4  	awsRegionFlag = Flag{
     5  		Name:       "region",
     6  		ConfigName: "cloud.aws.region",
     7  		Default:    "",
     8  		Usage:      "AWS Region to scan",
     9  	}
    10  	awsEndpointFlag = Flag{
    11  		Name:       "endpoint",
    12  		ConfigName: "cloud.aws.endpoint",
    13  		Default:    "",
    14  		Usage:      "AWS Endpoint override",
    15  	}
    16  	awsServiceFlag = Flag{
    17  		Name:       "service",
    18  		ConfigName: "cloud.aws.service",
    19  		Default:    []string{},
    20  		Usage:      "Only scan AWS Service(s) specified with this flag. Can specify multiple services using --service A --service B etc.",
    21  	}
    22  	awsSkipServicesFlag = Flag{
    23  		Name:       "skip-service",
    24  		ConfigName: "cloud.aws.skip-service",
    25  		Default:    []string{},
    26  		Usage:      "Skip selected AWS Service(s) specified with this flag. Can specify multiple services using --skip-service A --skip-service B etc.",
    27  	}
    28  	awsAccountFlag = Flag{
    29  		Name:       "account",
    30  		ConfigName: "cloud.aws.account",
    31  		Default:    "",
    32  		Usage:      "The AWS account to scan. It's useful to specify this when reviewing cached results for multiple accounts.",
    33  	}
    34  	awsARNFlag = Flag{
    35  		Name:       "arn",
    36  		ConfigName: "cloud.aws.arn",
    37  		Default:    "",
    38  		Usage:      "The AWS ARN to show results for. Useful to filter results once a scan is cached.",
    39  	}
    40  )
    41  
    42  type AWSFlagGroup struct {
    43  	Region       *Flag
    44  	Endpoint     *Flag
    45  	Services     *Flag
    46  	SkipServices *Flag
    47  	Account      *Flag
    48  	ARN          *Flag
    49  }
    50  
    51  type AWSOptions struct {
    52  	Region       string
    53  	Endpoint     string
    54  	Services     []string
    55  	SkipServices []string
    56  	Account      string
    57  	ARN          string
    58  }
    59  
    60  func NewAWSFlagGroup() *AWSFlagGroup {
    61  	return &AWSFlagGroup{
    62  		Region:       &awsRegionFlag,
    63  		Endpoint:     &awsEndpointFlag,
    64  		Services:     &awsServiceFlag,
    65  		SkipServices: &awsSkipServicesFlag,
    66  		Account:      &awsAccountFlag,
    67  		ARN:          &awsARNFlag,
    68  	}
    69  }
    70  
    71  func (f *AWSFlagGroup) Name() string {
    72  	return "AWS"
    73  }
    74  
    75  func (f *AWSFlagGroup) Flags() []*Flag {
    76  	return []*Flag{f.Region, f.Endpoint, f.Services, f.SkipServices, f.Account, f.ARN}
    77  }
    78  
    79  func (f *AWSFlagGroup) ToOptions() AWSOptions {
    80  	return AWSOptions{
    81  		Region:       getString(f.Region),
    82  		Endpoint:     getString(f.Endpoint),
    83  		Services:     getStringSlice(f.Services),
    84  		SkipServices: getStringSlice(f.SkipServices),
    85  		Account:      getString(f.Account),
    86  		ARN:          getString(f.ARN),
    87  	}
    88  }