@@ -9,19 +9,26 @@ import (
99 "log/slog"
1010 "strings"
1111
12+ "github.com/aws/aws-sdk-go-v2/aws"
1213 "github.com/aws/aws-sdk-go-v2/config"
1314 "github.com/aws/aws-sdk-go-v2/service/sts"
1415 "golang.org/x/sync/errgroup"
1516)
1617
1718// App represents a struct that provides functionality for interacting with the AWS services.
1819type App struct {
19- accountID string
20- runners []runner
21- stsClient stsClient
20+ accountID string
21+ runners []runner
22+ stsClient stsClient
23+ workerLimit int
2224}
2325
24- func newApp (ctx context.Context , check []runnerType , regions []string ) (* App , error ) {
26+ func newApp (
27+ ctx context.Context ,
28+ check []runnerType ,
29+ regions []string ,
30+ workerLimit int ,
31+ ) (* App , error ) {
2532 if len (regions ) == 0 {
2633 return nil , errEmptyRegion
2734 }
@@ -32,6 +39,10 @@ func newApp(ctx context.Context, check []runnerType, regions []string) (*App, er
3239
3340 regions = uniqRegions (regions )
3441
42+ if workerLimit < 1 {
43+ workerLimit = 1
44+ }
45+
3546 baseCfg , err := config .LoadDefaultConfig (ctx )
3647 if err != nil {
3748 return nil , fmt .Errorf ("failed to load aws config, %w" , err )
@@ -40,6 +51,18 @@ func newApp(ctx context.Context, check []runnerType, regions []string) (*App, er
4051 stsCfg := baseCfg .Copy ()
4152 stsCfg .Region = regions [0 ]
4253
54+ runners := setUpRunners (baseCfg , check , regions )
55+
56+ return & App {
57+ accountID : "" ,
58+ runners : runners ,
59+ stsClient : sts .NewFromConfig (stsCfg ),
60+ workerLimit : workerLimit ,
61+ }, nil
62+ }
63+
64+ // setUpRunners initializes and returns a list of runners based on the specified configuration, checks, and regions.
65+ func setUpRunners (baseCfg aws.Config , check []runnerType , regions []string ) []runner {
4366 runners := make ([]runner , 0 )
4467
4568 for _ , region := range regions {
@@ -64,18 +87,14 @@ func newApp(ctx context.Context, check []runnerType, regions []string) (*App, er
6487 }
6588 }
6689
67- return & App {
68- accountID : "" ,
69- runners : runners ,
70- stsClient : sts .NewFromConfig (stsCfg ),
71- }, nil
90+ return runners
7291}
7392
7493// Run executes the scan process on the target using all available runners,
7594// and returns the collected results or an error.
7695func (a * App ) Run (ctx context.Context , target string ) ([]Result , error ) {
7796 group , gCtx := errgroup .WithContext (ctx )
78- group .SetLimit (1 )
97+ group .SetLimit (a . workerLimit )
7998
8099 if strings .EqualFold (target , "self" ) {
81100 slog .Debug ("replacing self with account ID" ,
0 commit comments