From 3d3cfc6c0c2c9d677778c9b5ddbd90b547c690a9 Mon Sep 17 00:00:00 2001 From: Joseph Barcia Date: Tue, 21 Apr 2026 16:44:08 +0000 Subject: [PATCH 1/3] Update GitHub Actions to Node 24 compatible versions - actions/checkout v4 -> v6 - actions/setup-go v4 -> v5 - go-version ^1.20 -> ^1.25 - Replace abandoned marvinpinto/action-automatic-releases with softprops/action-gh-release v2 Node.js 20 actions are deprecated and will be forced to Node 24 starting June 2, 2026, and removed September 16, 2026. --- .github/workflows/autorelease.yml | 15 ++++++--------- .github/workflows/codespell.yml | 2 +- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/workflows/autorelease.yml b/.github/workflows/autorelease.yml index df62f457..fef4c8c5 100644 --- a/.github/workflows/autorelease.yml +++ b/.github/workflows/autorelease.yml @@ -15,10 +15,10 @@ jobs: steps: - - name: Go 1.21 - uses: actions/setup-go@v4 + - name: Go 1.25 + uses: actions/setup-go@v5 with: - go-version: ^1.20 + go-version: ^1.25 id: go - id: install-secret-key @@ -28,7 +28,7 @@ jobs: gpg --list-secret-keys --keyid-format LONG - name: Check Out Code - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Git Fetch Tags run: git fetch --prune --unshallow --tags -f @@ -39,9 +39,6 @@ jobs: - name: Release binaries - uses: "marvinpinto/action-automatic-releases@latest" + uses: softprops/action-gh-release@v2 with: - repo_token: "${{ secrets.GITHUB_TOKEN }}" - prerelease: false - files: | - ./cloudfox/* + files: ./cloudfox/* diff --git a/.github/workflows/codespell.yml b/.github/workflows/codespell.yml index 5fdcfe1c..88902d7f 100644 --- a/.github/workflows/codespell.yml +++ b/.github/workflows/codespell.yml @@ -11,6 +11,6 @@ jobs: codespell: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - run: pip install --user codespell - run: codespell --ignore-words-list="aks,referers,invokable" --skip="*.sum" From 494443d7ce4c61140cf1a244cf28f6a720e6346c Mon Sep 17 00:00:00 2001 From: jbarciabf Date: Tue, 26 May 2026 10:36:17 -0400 Subject: [PATCH 2/3] Fix concurrent map access race in network-ports module (#129) The NetworkPortsModule cached EC2 NACLs and Security Groups in two per-region maps. The cache lookup read the maps without holding a lock while the cache population path took a write lock, producing a "concurrent map read and map write" runtime panic when multiple region goroutines hit the cache check concurrently. The panic reproduced reliably in low-density AWS accounts where every region goroutine raced through the cache check at the same instant. Take the read lock on the cache fast-path in both getEC2NACLsPerRegion and getEC2SecurityGroupsPerRegion. Move naclsMutex and securityGroupsMutex from package-level vars onto the module struct so concurrent module instances stop serializing on each other's locks. Convert CommandCounter from plain int fields with naked ++/-- to int64 fields with Incr/Decr/Load methods that use atomic.AddInt64 and atomic.LoadInt64 internally. Worker goroutines and the spinner goroutine were updating and reading the same counters without synchronization, producing torn integer writes that could show as off-by-one progress in the spinner. Plain int64 storage keeps the struct copyable so existing constructors and helpers that take modules by value continue to vet-clean. Add TestNetworkPortsCacheConcurrentAccess as a regression test. With the read lock removed, "go test -race" reports the mapaccess2_faststr read racing the locked write; with the fix in place the test passes. --- aws/access-keys.go | 4 +- aws/api-gws.go | 94 ++-- aws/buckets.go | 14 +- aws/cloudformation.go | 16 +- aws/codebuild.go | 4 +- aws/databases.go | 50 +- aws/directory-services.go | 8 +- aws/ecr.go | 22 +- aws/ecs-tasks.go | 36 +- aws/eks.go | 18 +- aws/elastic-network-interfaces.go | 20 +- aws/endpoints.go | 268 +++++------ aws/env-vars.go | 90 ++-- aws/filesystems.go | 32 +- aws/iam-simulator.go | 32 +- aws/instances.go | 34 +- aws/inventory.go | 670 +++++++++++++------------- aws/lambda.go | 18 +- aws/network-ports.go | 127 ++--- aws/network-ports_test.go | 67 +++ aws/org.go | 8 +- aws/outbound-assumed-roles.go | 18 +- aws/permissions.go | 2 +- aws/pmapper.go | 2 +- aws/principals.go | 16 +- aws/ram.go | 16 +- aws/resource-trusts.go | 104 ++-- aws/role-trusts.go | 4 +- aws/route53.go | 10 +- aws/secrets.go | 34 +- aws/sns.go | 12 +- aws/sqs.go | 14 +- aws/tags.go | 12 +- aws/workloads.go | 30 +- gcp/commands/appengine.go | 12 +- gcp/commands/artifact-registry.go | 6 +- gcp/commands/assetinventory.go | 8 +- gcp/commands/backupinventory.go | 6 +- gcp/commands/beyondcorp.go | 4 +- gcp/commands/bigquery.go | 6 +- gcp/commands/bigqueryenum.go | 2 +- gcp/commands/bigtable.go | 2 +- gcp/commands/bigtableenum.go | 2 +- gcp/commands/bucketenum.go | 6 +- gcp/commands/buckets.go | 6 +- gcp/commands/certmanager.go | 8 +- gcp/commands/cloudarmor.go | 4 +- gcp/commands/cloudbuild.go | 6 +- gcp/commands/cloudrun.go | 8 +- gcp/commands/cloudsql.go | 6 +- gcp/commands/compliancedashboard.go | 4 +- gcp/commands/composer.go | 2 +- gcp/commands/costsecurity.go | 14 +- gcp/commands/crossproject.go | 14 +- gcp/commands/dataexfiltration.go | 6 +- gcp/commands/dataflow.go | 2 +- gcp/commands/dataproc.go | 2 +- gcp/commands/dns.go | 8 +- gcp/commands/domainwidedelegation.go | 4 +- gcp/commands/endpoints.go | 4 +- gcp/commands/filestore.go | 2 +- gcp/commands/firewall.go | 10 +- gcp/commands/functions.go | 6 +- gcp/commands/gke.go | 6 +- gcp/commands/iam.go | 8 +- gcp/commands/iap.go | 2 +- gcp/commands/identityfederation.go | 4 +- gcp/commands/instances.go | 6 +- gcp/commands/keys.go | 4 +- gcp/commands/kms.go | 8 +- gcp/commands/lateralmovement.go | 4 +- gcp/commands/loadbalancers.go | 6 +- gcp/commands/logenum.go | 2 +- gcp/commands/logging.go | 8 +- gcp/commands/memorystore.go | 2 +- gcp/commands/monitoringalerts.go | 8 +- gcp/commands/networktopology.go | 12 +- gcp/commands/notebooks.go | 2 +- gcp/commands/organizations.go | 4 +- gcp/commands/orgpolicies.go | 2 +- gcp/commands/permissions.go | 8 +- gcp/commands/privateserviceconnect.go | 8 +- gcp/commands/publicaccess.go | 4 +- gcp/commands/pubsub.go | 8 +- gcp/commands/resourceiam.go | 6 +- gcp/commands/scheduler.go | 6 +- gcp/commands/secrets.go | 6 +- gcp/commands/securitycenter.go | 6 +- gcp/commands/serviceaccounts.go | 6 +- gcp/commands/serviceagents.go | 6 +- gcp/commands/sourcerepos.go | 6 +- gcp/commands/spanner.go | 4 +- gcp/commands/spannerenum.go | 2 +- gcp/commands/vpcnetworks.go | 8 +- gcp/commands/vpcsc.go | 6 +- gcp/commands/whoami.go | 16 +- gcp/commands/workloadidentity.go | 4 +- internal/aws.go | 32 +- internal/gcp/base.go | 12 +- 99 files changed, 1204 insertions(+), 1114 deletions(-) create mode 100644 aws/network-ports_test.go diff --git a/aws/access-keys.go b/aws/access-keys.go index b2480ec8..dcdb9fe8 100644 --- a/aws/access-keys.go +++ b/aws/access-keys.go @@ -161,7 +161,7 @@ func (m *AccessKeysModule) getAccessKeysForAllUsers() { ListUsers, err := sdk.CachedIamListUsers(m.IAMClient, aws.ToString(m.Caller.Account)) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } // added this to break out if there no users @@ -171,7 +171,7 @@ func (m *AccessKeysModule) getAccessKeysForAllUsers() { results, err := sdk.CachedIamListAccessKeys(m.IAMClient, aws.ToString(m.Caller.Account), aws.ToString(user.UserName)) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } diff --git a/aws/api-gws.go b/aws/api-gws.go index efbf735c..628adb5f 100644 --- a/aws/api-gws.go +++ b/aws/api-gws.go @@ -191,19 +191,19 @@ func (m *ApiGwModule) executeChecks(r string, wg *sync.WaitGroup, semaphore chan m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getAPIGatewayAPIsPerRegion(r, wg, semaphore, dataReceiver) - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getAPIGatewayVIPsPerRegion(r, wg, semaphore, dataReceiver) - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getAPIGatewayv2APIsPerRegion(r, wg, semaphore, dataReceiver) - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getAPIGatewayv2VIPsPerRegion(r, wg, semaphore, dataReceiver) } @@ -244,7 +244,7 @@ func (m *ApiGwModule) writeLoot(outputDirectory string, verbosity int) string { // err = os.WriteFile(f, []byte(out), 0644) // if err != nil { // m.modLog.Error(err.Error()) - // m.CommandCounter.Error++ + // m.CommandCounter.IncrError() // panic(err.Error()) // } @@ -263,8 +263,8 @@ func (m *ApiGwModule) writeLoot(outputDirectory string, verbosity int) string { func (m *ApiGwModule) getAPIGatewayAPIsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan ApiGateway) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -272,21 +272,21 @@ func (m *ApiGwModule) getAPIGatewayAPIsPerRegion(r string, wg *sync.WaitGroup, s defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. Items, err := sdk.CachedApiGatewayGetRestAPIs(m.APIGatewayClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } for _, api := range Items { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() for _, endpoint := range m.getEndpointsPerAPIGateway(r, api) { dataReceiver <- endpoint } @@ -295,8 +295,8 @@ func (m *ApiGwModule) getAPIGatewayAPIsPerRegion(r string, wg *sync.WaitGroup, s func (m *ApiGwModule) getAPIGatewayVIPsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan ApiGateway) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -304,16 +304,16 @@ func (m *ApiGwModule) getAPIGatewayVIPsPerRegion(r string, wg *sync.WaitGroup, s defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. Items, err := sdk.CachedApiGatewayGetRestAPIs(m.APIGatewayClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -322,7 +322,7 @@ func (m *ApiGwModule) getAPIGatewayVIPsPerRegion(r string, wg *sync.WaitGroup, s if err != nil { m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s", r)) m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -334,7 +334,7 @@ func (m *ApiGwModule) getAPIGatewayVIPsPerRegion(r string, wg *sync.WaitGroup, s if err != nil { m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s", r)) m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -347,7 +347,7 @@ func (m *ApiGwModule) getAPIGatewayVIPsPerRegion(r string, wg *sync.WaitGroup, s for _, api := range Items { if api.Id != nil && aws.ToString(api.Id) == aws.ToString(mapping.RestApiId) { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() endpoints := m.getEndpointsPerAPIGateway(r, api) for _, endpoint := range endpoints { @@ -376,8 +376,8 @@ func (m *ApiGwModule) getAPIGatewayVIPsPerRegion(r string, wg *sync.WaitGroup, s func (m *ApiGwModule) getEndpointsPerAPIGateway(r string, api apigatewayTypes.RestApi) []ApiGateway { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() var gateways []ApiGateway @@ -402,7 +402,7 @@ func (m *ApiGwModule) getEndpointsPerAPIGateway(r string, api apigatewayTypes.Re if err != nil { m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s", r)) m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return gateways } @@ -411,7 +411,7 @@ func (m *ApiGwModule) getEndpointsPerAPIGateway(r string, api apigatewayTypes.Re if err != nil { m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s", r)) m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } for _, stage := range GetStages.Item { @@ -427,7 +427,7 @@ func (m *ApiGwModule) getEndpointsPerAPIGateway(r string, api apigatewayTypes.Re if err != nil { m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s", r)) m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -454,8 +454,8 @@ func (m *ApiGwModule) getEndpointsPerAPIGateway(r string, api apigatewayTypes.Re func (m *ApiGwModule) getAPIGatewayv2APIsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan ApiGateway) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -463,20 +463,20 @@ func (m *ApiGwModule) getAPIGatewayv2APIsPerRegion(r string, wg *sync.WaitGroup, defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. Items, err := sdk.CachedAPIGatewayv2GetAPIs(m.APIGatewayv2Client, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } for _, api := range Items { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() for _, endpoint := range m.getEndpointsPerAPIGatewayv2(r, api) { dataReceiver <- endpoint } @@ -486,8 +486,8 @@ func (m *ApiGwModule) getAPIGatewayv2APIsPerRegion(r string, wg *sync.WaitGroup, func (m *ApiGwModule) getAPIGatewayv2VIPsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan ApiGateway) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -495,16 +495,16 @@ func (m *ApiGwModule) getAPIGatewayv2VIPsPerRegion(r string, wg *sync.WaitGroup, defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. Items, err := sdk.CachedAPIGatewayv2GetAPIs(m.APIGatewayv2Client, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -513,7 +513,7 @@ func (m *ApiGwModule) getAPIGatewayv2VIPsPerRegion(r string, wg *sync.WaitGroup, if err != nil { m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s", r)) m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } for _, item := range GetDomainNames { @@ -524,7 +524,7 @@ func (m *ApiGwModule) getAPIGatewayv2VIPsPerRegion(r string, wg *sync.WaitGroup, if err != nil { m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s", r)) m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -537,7 +537,7 @@ func (m *ApiGwModule) getAPIGatewayv2VIPsPerRegion(r string, wg *sync.WaitGroup, for _, api := range Items { if api.ApiId != nil && aws.ToString(api.ApiId) == aws.ToString(mapping.ApiId) { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() endpoints := m.getEndpointsPerAPIGatewayv2(r, api) for _, endpoint := range endpoints { var old string @@ -568,8 +568,8 @@ func (m *ApiGwModule) getAPIGatewayv2VIPsPerRegion(r string, wg *sync.WaitGroup, func (m *ApiGwModule) getEndpointsPerAPIGatewayv2(r string, api apigatewayV2Types.Api) []ApiGateway { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() var gateways []ApiGateway @@ -588,7 +588,7 @@ func (m *ApiGwModule) getEndpointsPerAPIGatewayv2(r string, api apigatewayV2Type if err != nil { m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s", r)) m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } for _, stage := range GetStages { @@ -603,7 +603,7 @@ func (m *ApiGwModule) getEndpointsPerAPIGatewayv2(r string, api apigatewayV2Type if err != nil { m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s", r)) m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } for _, stage := range stages { @@ -643,7 +643,7 @@ func (m *ApiGwModule) ApiGatewayApiKeyRequired(r string, ApiId *string, Resource if err != nil { m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s", r)) m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } else { return aws.ToBool(GetMethod.ApiKeyRequired) } diff --git a/aws/buckets.go b/aws/buckets.go index 7e4a9e38..44b8bf9a 100644 --- a/aws/buckets.go +++ b/aws/buckets.go @@ -88,7 +88,7 @@ func (m *BucketsModule) PrintBuckets(outputDirectory string, verbosity int) { go m.Receiver(dataReceiver, receiverDone) wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(wg, semaphore, dataReceiver) wg.Wait() @@ -203,11 +203,11 @@ func (m *BucketsModule) Receiver(receiver chan BucketRow, receiverDone chan bool func (m *BucketsModule) executeChecks(wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan BucketRow) { defer wg.Done() - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.createBucketsRows(m.output.Verbosity, wg, semaphore, dataReceiver) - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() } func (m *BucketsModule) writeLoot(outputDirectory string, verbosity int, profile string) { @@ -256,8 +256,8 @@ func (m *BucketsModule) writeLoot(outputDirectory string, verbosity int, profile func (m *BucketsModule) createBucketsRows(verbosity int, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan BucketRow) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -357,7 +357,7 @@ func (m *BucketsModule) storeAccessPolicy(bucket *BucketRow) { if err := m.storeFile(f, bucket.PolicyJSON); err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/aws/cloudformation.go b/aws/cloudformation.go index 76623f61..a23fe4d0 100644 --- a/aws/cloudformation.go +++ b/aws/cloudformation.go @@ -80,7 +80,7 @@ func (m *CloudformationModule) PrintCloudformationStacks(outputDirectory string, for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, semaphore, dataReceiver) } @@ -206,7 +206,7 @@ func (m *CloudformationModule) executeChecks(r string, wg *sync.WaitGroup, semap } for _, serviceRegion := range serviceRegions { if r == serviceRegion { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.createCFStackRowsPerRegion(r, wg, semaphore, dataReceiver) } @@ -231,7 +231,7 @@ func (m *CloudformationModule) writeLoot(outputDirectory string, verbosity int) err := os.MkdirAll(path, os.ModePerm) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } pullFile := filepath.Join(path, "cloudformation-data.txt") @@ -271,7 +271,7 @@ func (m *CloudformationModule) writeLoot(outputDirectory string, verbosity int) err = os.WriteFile(pullFile, []byte(out), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } if verbosity > 2 { @@ -288,8 +288,8 @@ func (m *CloudformationModule) writeLoot(outputDirectory string, verbosity int) func (m *CloudformationModule) createCFStackRowsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan CFStack) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -302,7 +302,7 @@ func (m *CloudformationModule) createCFStackRowsPerRegion(r string, wg *sync.Wai DescribeStacks, err := sdk.CachedCloudFormationDescribeStacks(m.CloudFormationClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } for _, stack := range DescribeStacks { @@ -314,7 +314,7 @@ func (m *CloudformationModule) createCFStackRowsPerRegion(r string, wg *sync.Wai stackTemplateBody, err = sdk.CachedCloudFormationGetTemplate(m.CloudFormationClient, aws.ToString(m.Caller.Account), r, stackName) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } dataReceiver <- CFStack{ diff --git a/aws/codebuild.go b/aws/codebuild.go index 2b4f1f79..a151bdea 100644 --- a/aws/codebuild.go +++ b/aws/codebuild.go @@ -87,7 +87,7 @@ func (m *CodeBuildModule) PrintCodeBuildProjects(outputDirectory string, verbosi for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, semaphore, dataReceiver) } @@ -224,7 +224,7 @@ func (m *CodeBuildModule) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getcodeBuildProjectsPerRegion(r, wg, semaphore, dataReceiver) } diff --git a/aws/databases.go b/aws/databases.go index b5186470..82784107 100644 --- a/aws/databases.go +++ b/aws/databases.go @@ -260,7 +260,7 @@ func (m *DatabasesModule) executeCheck(check check) { m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() check.wg.Add(1) go check.executor(check.region, check.wg, check.semaphore, check.dataReceiver) } @@ -324,7 +324,7 @@ func (m *DatabasesModule) writeLoot(outputDirectory string, verbosity int) strin // err = os.WriteFile(f, []byte(out), 0644) // if err != nil { // m.modLog.Error(err.Error()) - // m.CommandCounter.Error++ + // m.CommandCounter.IncrError() // panic(err.Error()) // } @@ -343,8 +343,8 @@ func (m *DatabasesModule) writeLoot(outputDirectory string, verbosity int) strin func (m *DatabasesModule) getRdsClustersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Database) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -352,13 +352,13 @@ func (m *DatabasesModule) getRdsClustersPerRegion(r string, wg *sync.WaitGroup, defer func() { <-semaphore }() - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() DBClusters, err := sdk.CachedRDSDescribeDBClusters(m.RDSClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -411,8 +411,8 @@ func (m *DatabasesModule) getRdsClustersPerRegion(r string, wg *sync.WaitGroup, func (m *DatabasesModule) getRdsInstancesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Database) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -420,14 +420,14 @@ func (m *DatabasesModule) getRdsInstancesPerRegion(r string, wg *sync.WaitGroup, defer func() { <-semaphore }() - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() DBInstances, err := sdk.CachedRDSDescribeDBInstances(m.RDSClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -480,8 +480,8 @@ func (m *DatabasesModule) getRdsInstancesPerRegion(r string, wg *sync.WaitGroup, func (m *DatabasesModule) getRedshiftDatabasesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Database) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -489,9 +489,9 @@ func (m *DatabasesModule) getRedshiftDatabasesPerRegion(r string, wg *sync.WaitG defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() awsService := "Redshift" protocol := "https" @@ -502,7 +502,7 @@ func (m *DatabasesModule) getRedshiftDatabasesPerRegion(r string, wg *sync.WaitG m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -532,8 +532,8 @@ func (m *DatabasesModule) getRedshiftDatabasesPerRegion(r string, wg *sync.WaitG func (m *DatabasesModule) getDynamoDBTablesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Database) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -541,15 +541,15 @@ func (m *DatabasesModule) getDynamoDBTablesPerRegion(r string, wg *sync.WaitGrou defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() awsService := "DynamoDB" Tables, err := sdk.CachedDynamoDBListTables(m.DynamoDBClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -558,7 +558,7 @@ func (m *DatabasesModule) getDynamoDBTablesPerRegion(r string, wg *sync.WaitGrou TableOutput, err := sdk.CachedDynamoDBDescribeTable(m.DynamoDBClient, aws.ToString(m.Caller.Account), r, table) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } size := aws.ToInt64(TableOutput.TableSizeBytes) diff --git a/aws/directory-services.go b/aws/directory-services.go index a27589d2..17d72dda 100644 --- a/aws/directory-services.go +++ b/aws/directory-services.go @@ -84,7 +84,7 @@ func (m *DirectoryModule) PrintDirectories(outputDirectory string, verbosity int for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, semaphore, dataReceiver) } @@ -203,7 +203,7 @@ func (m *DirectoryModule) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getDirectoriesPerRegion(r, wg, semaphore, dataReceiver) } @@ -223,8 +223,8 @@ func (m *DirectoryModule) Receiver(receiver chan Directory, receiverDone chan bo } func (m *DirectoryModule) getDirectoriesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Directory) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() diff --git a/aws/ecr.go b/aws/ecr.go index 90f6a9e9..9acc0585 100644 --- a/aws/ecr.go +++ b/aws/ecr.go @@ -84,7 +84,7 @@ func (m *ECRModule) PrintECR(outputDirectory string, verbosity int) { for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, semaphore, dataReceiver) } @@ -210,7 +210,7 @@ func (m *ECRModule) executeChecks(r string, wg *sync.WaitGroup, semaphore chan s m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getECRRecordsPerRegion(r, wg, semaphore, dataReceiver) } @@ -234,7 +234,7 @@ func (m *ECRModule) writeLoot(outputDirectory string, verbosity int) { err := os.MkdirAll(path, os.ModePerm) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } pullFile := filepath.Join(path, "ecr-pull-commands.txt") @@ -259,7 +259,7 @@ func (m *ECRModule) writeLoot(outputDirectory string, verbosity int) { err = os.WriteFile(pullFile, []byte(out), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } if verbosity > 2 { @@ -277,8 +277,8 @@ func (m *ECRModule) writeLoot(outputDirectory string, verbosity int) { func (m *ECRModule) getECRRecordsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Repository) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -290,7 +290,7 @@ func (m *ECRModule) getECRRecordsPerRegion(r string, wg *sync.WaitGroup, semapho Repositories, err := sdk.CachedECRDescribeRepositories(m.ECRClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -302,7 +302,7 @@ func (m *ECRModule) getECRRecordsPerRegion(r string, wg *sync.WaitGroup, semapho images, err := sdk.CachedECRDescribeImages(m.ECRClient, aws.ToString(m.Caller.Account), r, repoName) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } @@ -350,7 +350,7 @@ func (m *ECRModule) getECRRecordsPerRegion(r string, wg *sync.WaitGroup, semapho // var repositories []types.Repository // Repositories, err := sdk.CachedECRDescribeRepositories(m.ECRClient, aws.ToString(m.Caller.Account), r) // if err != nil { -// m.CommandCounter.Error++ +// m.CommandCounter.IncrError() // return nil, err // } @@ -364,7 +364,7 @@ func (m *ECRModule) getECRRecordsPerRegion(r string, wg *sync.WaitGroup, semapho // ImageDetails, err := sdk.CachedECRDescribeImages(m.ECRClient, aws.ToString(m.Caller.Account), r, repoName) // if err != nil { -// m.CommandCounter.Error++ +// m.CommandCounter.IncrError() // return nil, err // } // images = append(images, ImageDetails...) @@ -375,7 +375,7 @@ func (m *ECRModule) getECRRepositoryPolicy(r string, repository string) (policy. var repoPolicy policy.Policy Policy, err := sdk.CachedECRGetRepositoryPolicy(m.ECRClient, aws.ToString(m.Caller.Account), r, repository) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return repoPolicy, err } repoPolicy, err = policy.ParseJSONPolicy([]byte(Policy)) diff --git a/aws/ecs-tasks.go b/aws/ecs-tasks.go index 6146acef..4c6caedb 100644 --- a/aws/ecs-tasks.go +++ b/aws/ecs-tasks.go @@ -100,7 +100,7 @@ func (m *ECSTasksModule) ECSTasks(outputDirectory string, verbosity int) { for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, dataReceiver) } @@ -254,7 +254,7 @@ func (m *ECSTasksModule) writeLoot(outputDirectory string) { err := os.MkdirAll(path, os.ModePerm) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } privateIPsFilename := filepath.Join(path, "ecs-tasks-PrivateIPs.txt") publicIPsFilename := filepath.Join(path, "ecs-tasks-PublicIPs.txt") @@ -274,12 +274,12 @@ func (m *ECSTasksModule) writeLoot(outputDirectory string) { err = os.WriteFile(privateIPsFilename, []byte(privateIPs), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } err = os.WriteFile(publicIPsFilename, []byte(publicIPs), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } for _, task := range m.MappedECSTasks { @@ -288,14 +288,14 @@ func (m *ECSTasksModule) writeLoot(outputDirectory string) { err := os.MkdirAll(path, os.ModePerm) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } taskDefinitionFilename := filepath.Join(path, task.TaskDefinitionName+".json") err = os.WriteFile(taskDefinitionFilename, []byte(task.TaskDefinitionContent), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } } @@ -321,12 +321,12 @@ func (m *ECSTasksModule) executeChecks(r string, wg *sync.WaitGroup, dataReceive } if res { - m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() m.getListClusters(r, dataReceiver) - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() } } @@ -335,7 +335,7 @@ func (m *ECSTasksModule) getListClusters(region string, dataReceiver chan Mapped ClusterArns, err := sdk.CachedECSListClusters(m.ECSClient, aws.ToString(m.Caller.Account), region) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -349,7 +349,7 @@ func (m *ECSTasksModule) getListTasks(clusterARN string, region string, dataRece TaskArns, err := sdk.CachedECSListTasks(m.ECSClient, aws.ToString(m.Caller.Account), region, clusterARN) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -374,7 +374,7 @@ func (m *ECSTasksModule) loadTasksData(clusterARN string, taskARNs []string, reg Tasks, err := sdk.CachedECSDescribeTasks(m.ECSClient, aws.ToString(m.Caller.Account), region, clusterARN, taskARNs) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -388,7 +388,7 @@ func (m *ECSTasksModule) loadTasksData(clusterARN string, taskARNs []string, reg publicIPs, err := m.loadPublicIPs(eniIDs, region) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -397,7 +397,7 @@ func (m *ECSTasksModule) loadTasksData(clusterARN string, taskARNs []string, reg taskDefinition, err := sdk.CachedECSDescribeTaskDefinition(m.ECSClient, aws.ToString(m.Caller.Account), region, aws.ToString(task.TaskDefinitionArn)) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } mappedTask := MappedECSTask{ @@ -446,7 +446,7 @@ func (m *ECSTasksModule) describeTaskDefinition(taskDefinitionArn string, region ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return types.TaskDefinition{}, err } return *DescribeTaskDefinition.TaskDefinition, nil @@ -466,7 +466,7 @@ func (m *ECSTasksModule) loadAllPublicIPs(eniIDs []string, region string) (map[s publicIPs, err := m.loadPublicIPs(eniIDs[i:j], region) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return nil, fmt.Errorf("getting elastic network interfaces: %s", err) } diff --git a/aws/eks.go b/aws/eks.go index 6e793eb7..c1f5de41 100644 --- a/aws/eks.go +++ b/aws/eks.go @@ -102,7 +102,7 @@ func (m *EKSModule) EKS(outputDirectory string, verbosity int) { for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, semaphore, dataReceiver) } @@ -255,7 +255,7 @@ func (m *EKSModule) executeChecks(r string, wg *sync.WaitGroup, semaphore chan s m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getEKSRecordsPerRegion(r, wg, semaphore, dataReceiver) } @@ -279,7 +279,7 @@ func (m *EKSModule) writeLoot(outputDirectory string, verbosity int) { err := os.MkdirAll(path, os.ModePerm) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } pullFile := filepath.Join(path, "eks-kubeconfig-commands.txt") @@ -303,7 +303,7 @@ func (m *EKSModule) writeLoot(outputDirectory string, verbosity int) { err = os.WriteFile(pullFile, []byte(out), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } if verbosity > 2 { @@ -322,8 +322,8 @@ func (m *EKSModule) writeLoot(outputDirectory string, verbosity int) { func (m *EKSModule) getEKSRecordsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Cluster) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -336,7 +336,7 @@ func (m *EKSModule) getEKSRecordsPerRegion(r string, wg *sync.WaitGroup, semapho clusters, err := sdk.CachedEKSListClusters(m.EKSClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -347,7 +347,7 @@ func (m *EKSModule) getEKSRecordsPerRegion(r string, wg *sync.WaitGroup, semapho clusterDetails, err := sdk.CachedEKSDescribeCluster(m.EKSClient, aws.ToString(m.Caller.Account), clusterName, r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } //nodeGroups = append(nodeGroups, DescribeCluster.Cluster.) @@ -373,7 +373,7 @@ func (m *EKSModule) getEKSRecordsPerRegion(r string, wg *sync.WaitGroup, semapho nodeGroupDetails, err := sdk.CachedEKSDescribeNodeGroup(m.EKSClient, aws.ToString(m.Caller.Account), clusterName, nodeGroup, r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } role = aws.ToString(nodeGroupDetails.NodeRole) diff --git a/aws/elastic-network-interfaces.go b/aws/elastic-network-interfaces.go index 69ea40bc..e7f74aac 100644 --- a/aws/elastic-network-interfaces.go +++ b/aws/elastic-network-interfaces.go @@ -73,7 +73,7 @@ func (m *ElasticNetworkInterfacesModule) ElasticNetworkInterfaces(outputDirector for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, dataReceiver) } @@ -199,7 +199,7 @@ func (m *ElasticNetworkInterfacesModule) writeLoot(outputDirectory string) { err := os.MkdirAll(path, os.ModePerm) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } privateIPsFilename := filepath.Join(path, "elastic-network-interfaces-PrivateIPs.txt") publicIPsFilename := filepath.Join(path, "elastic-network-interfaces-PublicIPs.txt") @@ -219,12 +219,12 @@ func (m *ElasticNetworkInterfacesModule) writeLoot(outputDirectory string) { err = os.WriteFile(privateIPsFilename, []byte(privateIPs), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } err = os.WriteFile(publicIPsFilename, []byte(publicIPs), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } fmt.Printf("[%s][%s] Loot written to [%s]\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), privateIPsFilename) @@ -246,12 +246,12 @@ func (m *ElasticNetworkInterfacesModule) executeChecks(r string, wg *sync.WaitGr m.modLog.Error(err) } if res { - m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() m.getDescribeNetworkInterfaces(r, dataReceiver) - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() } } @@ -272,7 +272,7 @@ func (m *ElasticNetworkInterfacesModule) getDescribeNetworkInterfaces(region str // ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } diff --git a/aws/endpoints.go b/aws/endpoints.go index efb4a891..db9b3994 100644 --- a/aws/endpoints.go +++ b/aws/endpoints.go @@ -280,7 +280,7 @@ func (m *EndpointsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getLambdaFunctionsPerRegion(r, wg, semaphore, dataReceiver) } @@ -289,7 +289,7 @@ func (m *EndpointsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getEksClustersPerRegion(r, wg, semaphore, dataReceiver) } @@ -298,7 +298,7 @@ func (m *EndpointsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getMqBrokersPerRegion(r, wg, semaphore, dataReceiver) } @@ -307,7 +307,7 @@ func (m *EndpointsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getOpenSearchPerRegion(r, wg, semaphore, dataReceiver) } @@ -316,7 +316,7 @@ func (m *EndpointsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getGrafanaEndPointsPerRegion(r, wg, semaphore, dataReceiver) } @@ -325,11 +325,11 @@ func (m *EndpointsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getELBv2ListenersPerRegion(r, wg, semaphore, dataReceiver) - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getELBListenersPerRegion(r, wg, semaphore, dataReceiver) } @@ -338,19 +338,19 @@ func (m *EndpointsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getAPIGatewayAPIsPerRegion(r, wg, semaphore, dataReceiver) - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getAPIGatewayVIPsPerRegion(r, wg, semaphore, dataReceiver) - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getAPIGatewayv2APIsPerRegion(r, wg, semaphore, dataReceiver) - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getAPIGatewayv2VIPsPerRegion(r, wg, semaphore, dataReceiver) } @@ -359,7 +359,7 @@ func (m *EndpointsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getRdsClustersPerRegion(r, wg, semaphore, dataReceiver) } @@ -368,13 +368,13 @@ func (m *EndpointsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getRedshiftEndPointsPerRegion(r, wg, semaphore, dataReceiver) } //apprunner is not supported by the aws json so we have to call it in every region - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getAppRunnerEndpointsPerRegion(r, wg, semaphore, dataReceiver) @@ -383,7 +383,7 @@ func (m *EndpointsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getLightsailContainerEndpointsPerRegion(r, wg, semaphore, dataReceiver) } @@ -394,7 +394,7 @@ func (m *EndpointsModule) writeLoot(outputDirectory string, verbosity int) { err := os.MkdirAll(path, os.ModePerm) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() panic(err.Error()) } f := filepath.Join(path, "endpoints-UrlsOnly.txt") @@ -408,7 +408,7 @@ func (m *EndpointsModule) writeLoot(outputDirectory string, verbosity int) { err = os.WriteFile(f, []byte(out), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() panic(err.Error()) } @@ -425,8 +425,8 @@ func (m *EndpointsModule) writeLoot(outputDirectory string, verbosity int) { func (m *EndpointsModule) getLambdaFunctionsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -434,16 +434,16 @@ func (m *EndpointsModule) getLambdaFunctionsPerRegion(r string, wg *sync.WaitGro defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var public string Functions, err := sdk.CachedLambdaListFunctions(m.LambdaClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -455,7 +455,7 @@ func (m *EndpointsModule) getLambdaFunctionsPerRegion(r string, wg *sync.WaitGro m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } endpoint := aws.ToString(FunctionDetails.FunctionUrl) @@ -482,8 +482,8 @@ func (m *EndpointsModule) getLambdaFunctionsPerRegion(r string, wg *sync.WaitGro func (m *EndpointsModule) getEksClustersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -491,15 +491,15 @@ func (m *EndpointsModule) getEksClustersPerRegion(r string, wg *sync.WaitGroup, defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. Clusters, err := sdk.CachedEKSListClusters(m.EKSClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -511,7 +511,7 @@ func (m *EndpointsModule) getEksClustersPerRegion(r string, wg *sync.WaitGroup, m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } var endpoint string @@ -545,8 +545,8 @@ func (m *EndpointsModule) getEksClustersPerRegion(r string, wg *sync.WaitGroup, func (m *EndpointsModule) getMqBrokersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -554,14 +554,14 @@ func (m *EndpointsModule) getMqBrokersPerRegion(r string, wg *sync.WaitGroup, se defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() BrokerSummaries, err := sdk.CachedMQListBrokers(m.MQClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -584,7 +584,7 @@ func (m *EndpointsModule) getMqBrokersPerRegion(r string, wg *sync.WaitGroup, se m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } if aws.ToBool(BrokerDetails.PubliclyAccessible) { @@ -611,8 +611,8 @@ func (m *EndpointsModule) getMqBrokersPerRegion(r string, wg *sync.WaitGroup, se func (m *EndpointsModule) getOpenSearchPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -620,14 +620,14 @@ func (m *EndpointsModule) getOpenSearchPerRegion(r string, wg *sync.WaitGroup, s defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() DomainNames, err := sdk.CachedOpenSearchListDomainNames(m.OpenSearchClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -641,7 +641,7 @@ func (m *EndpointsModule) getOpenSearchPerRegion(r string, wg *sync.WaitGroup, s m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -663,7 +663,7 @@ func (m *EndpointsModule) getOpenSearchPerRegion(r string, wg *sync.WaitGroup, s domainConfig, err := sdk.CachedOpenSearchDescribeDomainConfig(m.OpenSearchClient, aws.ToString(m.Caller.Account), r, name) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } if aws.ToBool(domainConfig.AdvancedSecurityOptions.Options.Enabled) { @@ -697,8 +697,8 @@ func (m *EndpointsModule) getOpenSearchPerRegion(r string, wg *sync.WaitGroup, s func (m *EndpointsModule) getGrafanaEndPointsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -706,14 +706,14 @@ func (m *EndpointsModule) getGrafanaEndPointsPerRegion(r string, wg *sync.WaitGr defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() ListWorkspaces, err := sdk.CachedGrafanaListWorkspaces(m.GrafanaClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -743,8 +743,8 @@ func (m *EndpointsModule) getGrafanaEndPointsPerRegion(r string, wg *sync.WaitGr func (m *EndpointsModule) getELBv2ListenersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -752,16 +752,16 @@ func (m *EndpointsModule) getELBv2ListenersPerRegion(r string, wg *sync.WaitGrou defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. awsService := "ELBv2" LoadBalancers, err := sdk.CachedELBv2DescribeLoadBalancers(m.ELBv2Client, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -787,7 +787,7 @@ func (m *EndpointsModule) getELBv2ListenersPerRegion(r string, wg *sync.WaitGrou m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } if scheme == "internet-facing" { @@ -823,8 +823,8 @@ func (m *EndpointsModule) getELBv2ListenersPerRegion(r string, wg *sync.WaitGrou func (m *EndpointsModule) getELBListenersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -832,16 +832,16 @@ func (m *EndpointsModule) getELBListenersPerRegion(r string, wg *sync.WaitGroup, defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() awsService := "ELB" LoadBalancerDescriptions, err := sdk.CachedELBDescribeLoadBalancers(m.ELBClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } var public string @@ -883,8 +883,8 @@ func (m *EndpointsModule) getELBListenersPerRegion(r string, wg *sync.WaitGroup, func (m *EndpointsModule) getAPIGatewayAPIsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -892,16 +892,16 @@ func (m *EndpointsModule) getAPIGatewayAPIsPerRegion(r string, wg *sync.WaitGrou defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. Items, err := sdk.CachedApiGatewayGetRestAPIs(m.APIGatewayClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -914,8 +914,8 @@ func (m *EndpointsModule) getAPIGatewayAPIsPerRegion(r string, wg *sync.WaitGrou func (m *EndpointsModule) getAPIGatewayVIPsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -923,15 +923,15 @@ func (m *EndpointsModule) getAPIGatewayVIPsPerRegion(r string, wg *sync.WaitGrou defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() Items, err := sdk.CachedApiGatewayGetRestAPIs(m.APIGatewayClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -942,7 +942,7 @@ func (m *EndpointsModule) getAPIGatewayVIPsPerRegion(r string, wg *sync.WaitGrou m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } for _, item := range GetDomainNames { @@ -955,7 +955,7 @@ func (m *EndpointsModule) getAPIGatewayVIPsPerRegion(r string, wg *sync.WaitGrou m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1020,7 +1020,7 @@ func (m *EndpointsModule) getEndpointsPerAPIGateway(r string, api apigatewayType m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } GetResources, err := sdk.CachedApiGatewayGetResources(m.APIGatewayClient, aws.ToString(m.Caller.Account), r, id) @@ -1030,7 +1030,7 @@ func (m *EndpointsModule) getEndpointsPerAPIGateway(r string, api apigatewayType m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } for _, stage := range GetStages.Item { @@ -1059,8 +1059,8 @@ func (m *EndpointsModule) getEndpointsPerAPIGateway(r string, api apigatewayType func (m *EndpointsModule) getAPIGatewayv2APIsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -1068,16 +1068,16 @@ func (m *EndpointsModule) getAPIGatewayv2APIsPerRegion(r string, wg *sync.WaitGr defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. Items, err := sdk.CachedAPIGatewayv2GetAPIs(m.APIGatewayv2Client, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } for _, api := range Items { @@ -1090,8 +1090,8 @@ func (m *EndpointsModule) getAPIGatewayv2APIsPerRegion(r string, wg *sync.WaitGr func (m *EndpointsModule) getAPIGatewayv2VIPsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -1099,15 +1099,15 @@ func (m *EndpointsModule) getAPIGatewayv2VIPsPerRegion(r string, wg *sync.WaitGr defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() Items, err := sdk.CachedAPIGatewayv2GetAPIs(m.APIGatewayv2Client, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1118,7 +1118,7 @@ func (m *EndpointsModule) getAPIGatewayv2VIPsPerRegion(r string, wg *sync.WaitGr m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } for _, item := range GetDomainNames { @@ -1131,7 +1131,7 @@ func (m *EndpointsModule) getAPIGatewayv2VIPsPerRegion(r string, wg *sync.WaitGr m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1193,7 +1193,7 @@ func (m *EndpointsModule) getEndpointsPerAPIGatewayv2(r string, api apigatewayV2 m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } for _, stage := range GetStages { @@ -1211,7 +1211,7 @@ func (m *EndpointsModule) getEndpointsPerAPIGatewayv2(r string, api apigatewayV2 m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } for _, stage := range stages { @@ -1246,8 +1246,8 @@ func (m *EndpointsModule) getEndpointsPerAPIGatewayv2(r string, api apigatewayV2 func (m *EndpointsModule) getRdsClustersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -1255,9 +1255,9 @@ func (m *EndpointsModule) getRdsClustersPerRegion(r string, wg *sync.WaitGroup, defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() DBInstances, err := sdk.CachedRDSDescribeDBInstances(m.RDSClient, aws.ToString(m.Caller.Account), r) if err != nil { @@ -1265,7 +1265,7 @@ func (m *EndpointsModule) getRdsClustersPerRegion(r string, wg *sync.WaitGroup, m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1300,8 +1300,8 @@ func (m *EndpointsModule) getRdsClustersPerRegion(r string, wg *sync.WaitGroup, func (m *EndpointsModule) getRedshiftEndPointsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -1309,9 +1309,9 @@ func (m *EndpointsModule) getRedshiftEndPointsPerRegion(r string, wg *sync.WaitG defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() awsService := "Redshift" protocol := "https" @@ -1323,7 +1323,7 @@ func (m *EndpointsModule) getRedshiftEndPointsPerRegion(r string, wg *sync.WaitG m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1360,8 +1360,8 @@ UNUSED CODE - PLEASE REVIEW AND DELETE IF IT DOESN'T APPLY func (m *EndpointsModule) getS3EndpointsPerRegion(wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -1369,9 +1369,9 @@ UNUSED CODE - PLEASE REVIEW AND DELETE IF IT DOESN'T APPLY defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // This for loop exits at the end dependeding on whether the output hits its last page (see pagination control block at the end of the loop). ListBuckets, _ := m.S3Client.ListBuckets( @@ -1434,8 +1434,8 @@ UNUSED CODE - PLEASE REVIEW AND DELETE IF IT DOESN'T APPLY */ func (m *EndpointsModule) getCloudfrontEndpoints(wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -1443,9 +1443,9 @@ func (m *EndpointsModule) getCloudfrontEndpoints(wg *sync.WaitGroup, semaphore c defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var PaginationControl *string var awsService = "Cloudfront" @@ -1466,7 +1466,7 @@ func (m *EndpointsModule) getCloudfrontEndpoints(wg *sync.WaitGroup, semaphore c m.Errors = append(m.Errors, fmt.Sprintf(" Error: Region: %s, Service: %s, Operation: %s", r, oe.Service(), oe.Operation())) } m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } if ListDistributions.DistributionList.Quantity == nil { @@ -1546,8 +1546,8 @@ func (m *EndpointsModule) getCloudfrontEndpoints(wg *sync.WaitGroup, semaphore c func (m *EndpointsModule) getAppRunnerEndpointsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -1555,15 +1555,15 @@ func (m *EndpointsModule) getAppRunnerEndpointsPerRegion(r string, wg *sync.Wait defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() ServiceSummaryList, err := sdk.CachedAppRunnerListServices(m.AppRunnerClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } for _, service := range ServiceSummaryList { @@ -1590,7 +1590,7 @@ func (m *EndpointsModule) getAppRunnerEndpointsPerRegion(r string, wg *sync.Wait ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1614,7 +1614,7 @@ func (m *EndpointsModule) getAppRunnerEndpointsPerRegion(r string, wg *sync.Wait ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } if DescribeCustomDomains.DNSTarget != nil { @@ -1667,8 +1667,8 @@ func (m *EndpointsModule) appRunnerDescribeCustomDomain(r string, serviceArn str func (m *EndpointsModule) getLightsailContainerEndpointsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Endpoint) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -1676,9 +1676,9 @@ func (m *EndpointsModule) getLightsailContainerEndpointsPerRegion(r string, wg * defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var public = "True" var protocol = "https" var port int32 = 443 @@ -1687,7 +1687,7 @@ func (m *EndpointsModule) getLightsailContainerEndpointsPerRegion(r string, wg * if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } if len(containerServices) > 0 { diff --git a/aws/env-vars.go b/aws/env-vars.go index 1f994ccc..bbef2b5b 100644 --- a/aws/env-vars.go +++ b/aws/env-vars.go @@ -105,7 +105,7 @@ func (m *EnvsModule) PrintEnvs(outputDirectory string, verbosity int) { for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, semaphore, dataReceiver) } @@ -290,7 +290,7 @@ func (m *EnvsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore chan } res, _ := servicemap.IsServiceInRegion("ecs", r) if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getECSEnvironmentVariablesPerRegion(r, wg, semaphore, dataReceiver) } @@ -300,13 +300,13 @@ func (m *EnvsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore chan m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getLambdaEnvironmentVariablesPerRegion(r, wg, semaphore, dataReceiver) } // AppRunner is not supported in the aws service region catalog so we have to run it in all regions - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getAppRunnerEnvironmentVariablesPerRegion(r, wg, semaphore, dataReceiver) @@ -315,7 +315,7 @@ func (m *EnvsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore chan m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getLightsailEnvironmentVariablesPerRegion(r, wg, semaphore, dataReceiver) } @@ -325,7 +325,7 @@ func (m *EnvsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore chan m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getSagemakerEnvironmentVariablesPerRegion(r, wg, semaphore, dataReceiver) } @@ -334,8 +334,8 @@ func (m *EnvsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore chan func (m *EnvsModule) getECSEnvironmentVariablesPerRegion(region string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan EnvironmentVariable) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -343,9 +343,9 @@ func (m *EnvsModule) getECSEnvironmentVariablesPerRegion(region string, wg *sync defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. //var PaginationMarker *string @@ -364,7 +364,7 @@ func (m *EnvsModule) getECSEnvironmentVariablesPerRegion(region string, wg *sync ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } for _, containerDefinition := range DescribeTaskDefinition.TaskDefinition.ContainerDefinitions { @@ -390,7 +390,7 @@ func (m *EnvsModule) getTaskDefinitionFamilies(region string) []string { ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -425,8 +425,8 @@ func (m *EnvsModule) getECSEnvironmentVariablesPerDefinition(taskDefinition ecsT func (m *EnvsModule) getLambdaEnvironmentVariablesPerRegion(region string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan EnvironmentVariable) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -434,14 +434,14 @@ func (m *EnvsModule) getLambdaEnvironmentVariablesPerRegion(region string, wg *s defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() Functions, err := sdk.CachedLambdaListFunctions(m.LambdaClient, aws.ToString(m.Caller.Account), region) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -467,8 +467,8 @@ func (m *EnvsModule) getLambdaEnvironmentVariablesPerFunction(function lambdaTyp func (m *EnvsModule) getAppRunnerEnvironmentVariablesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan EnvironmentVariable) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -476,16 +476,16 @@ func (m *EnvsModule) getAppRunnerEnvironmentVariablesPerRegion(r string, wg *syn defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() ServiceSummaryList, err := sdk.CachedAppRunnerListServices(m.AppRunnerClient, aws.ToString(m.Caller.Account), r) if err != nil { //modLog.Error(err.Error()) m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } if len(ServiceSummaryList) > 0 { @@ -506,7 +506,7 @@ func (m *EnvsModule) getAppRunnerEnvironmentVariablesPerRegion(r string, wg *syn ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -530,8 +530,8 @@ func (m *EnvsModule) getAppRunnerEnvironmentVariablesPerRegion(r string, wg *syn func (m *EnvsModule) getLightsailEnvironmentVariablesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan EnvironmentVariable) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -539,16 +539,16 @@ func (m *EnvsModule) getLightsailEnvironmentVariablesPerRegion(r string, wg *syn defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() awsService := "Lightsail [Container]" ContainerServices, err := sdk.CachedLightsailGetContainerServices(m.LightsailClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -574,8 +574,8 @@ func (m *EnvsModule) getLightsailEnvironmentVariablesPerRegion(r string, wg *syn func (m *EnvsModule) getSagemakerEnvironmentVariablesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan EnvironmentVariable) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -583,9 +583,9 @@ func (m *EnvsModule) getSagemakerEnvironmentVariablesPerRegion(r string, wg *syn defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() awsService := "Sagemaker" var PaginationControl *string @@ -603,7 +603,7 @@ func (m *EnvsModule) getSagemakerEnvironmentVariablesPerRegion(r string, wg *syn ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -621,7 +621,7 @@ func (m *EnvsModule) getSagemakerEnvironmentVariablesPerRegion(r string, wg *syn ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -665,7 +665,7 @@ func (m *EnvsModule) getSagemakerEnvironmentVariablesPerRegion(r string, wg *syn ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -683,7 +683,7 @@ func (m *EnvsModule) getSagemakerEnvironmentVariablesPerRegion(r string, wg *syn ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -726,7 +726,7 @@ func (m *EnvsModule) getSagemakerEnvironmentVariablesPerRegion(r string, wg *syn ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -744,7 +744,7 @@ func (m *EnvsModule) getSagemakerEnvironmentVariablesPerRegion(r string, wg *syn ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -788,7 +788,7 @@ func (m *EnvsModule) getSagemakerEnvironmentVariablesPerRegion(r string, wg *syn ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -805,7 +805,7 @@ func (m *EnvsModule) getSagemakerEnvironmentVariablesPerRegion(r string, wg *syn ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } diff --git a/aws/filesystems.go b/aws/filesystems.go index 17fcccb3..3d4ed710 100644 --- a/aws/filesystems.go +++ b/aws/filesystems.go @@ -245,7 +245,7 @@ func (m *FilesystemsModule) writeLoot(outputDirectory string, verbosity int) { if err != nil { sharedLogger.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } f := filepath.Join(path, "filesystems-mount-commands.txt") @@ -283,7 +283,7 @@ func (m *FilesystemsModule) writeLoot(outputDirectory string, verbosity int) { if err != nil { sharedLogger.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } fmt.Printf("[%s][%s] Loot written to [%s]\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), f) if verbosity > 2 { @@ -297,20 +297,20 @@ func (m *FilesystemsModule) writeLoot(outputDirectory string, verbosity int) { func (m *FilesystemsModule) getEFSSharesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan FilesystemObject) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() - m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var policy string DescribeFileSystems, err := sdk.CachedDescribeFileSystems(m.EFSClient, aws.ToString(m.Caller.Account), r) if err != nil { sharedLogger.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -336,7 +336,7 @@ func (m *FilesystemsModule) getEFSSharesPerRegion(r string, wg *sync.WaitGroup, DescribeMountTargets, err := sdk.CachedDescribeMountTargets(m.EFSClient, aws.ToString(m.Caller.Account), r, id) if err != nil { sharedLogger.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -349,7 +349,7 @@ func (m *FilesystemsModule) getEFSSharesPerRegion(r string, wg *sync.WaitGroup, if err != nil { sharedLogger.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() dataReceiver <- FilesystemObject{ AWSService: awsService, Region: r, @@ -381,14 +381,14 @@ func (m *FilesystemsModule) getEFSSharesPerRegion(r string, wg *sync.WaitGroup, func (m *FilesystemsModule) getFSxSharesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan FilesystemObject) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() - m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var PaginationMarker *string var PaginationMarker2 *string @@ -410,7 +410,7 @@ func (m *FilesystemsModule) getFSxSharesPerRegion(r string, wg *sync.WaitGroup, if err != nil { sharedLogger.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } diff --git a/aws/iam-simulator.go b/aws/iam-simulator.go index ea3d87fe..6971b8dc 100644 --- a/aws/iam-simulator.go +++ b/aws/iam-simulator.go @@ -276,7 +276,7 @@ func (m *IamSimulatorModule) writeLoot(outputDirectory string, verbosity int, pm err := os.MkdirAll(path, os.ModePerm) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } outFile := filepath.Join(path, "iam-simulator-pmapper-commands.txt") @@ -292,7 +292,7 @@ func (m *IamSimulatorModule) writeLoot(outputDirectory string, verbosity int, pm err = os.WriteFile(outFile, []byte(out), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } if verbosity > 2 { @@ -329,18 +329,18 @@ func (m *IamSimulatorModule) executeChecks(wg *sync.WaitGroup, resource string, func (m *IamSimulatorModule) getIAMUsers(wg *sync.WaitGroup, actions []string, resource string, dataReceiver chan SimulatorResult) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() - m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() ListUsers, err := sdk.CachedIamListUsers(m.IAMClient, aws.ToString(m.Caller.Account)) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -369,19 +369,19 @@ func (m *IamSimulatorModule) getIAMUsers(wg *sync.WaitGroup, actions []string, r func (m *IamSimulatorModule) getIAMRoles(wg *sync.WaitGroup, actions []string, resource string, dataReceiver chan SimulatorResult) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() - m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. ListRoles, err := sdk.CachedIamListRoles(m.IAMClient, aws.ToString(m.Caller.Account)) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -419,7 +419,7 @@ func (m *IamSimulatorModule) getPolicySimulatorResult(principal *string, actionN if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() m.modLog.Error(fmt.Sprintf("Failed to query actions for %s\n\n", aws.ToString(principal))) return } @@ -464,7 +464,7 @@ func (m *IamSimulatorModule) isPrincipalAnAdmin(principal *string) bool { ) if err != nil { m.modLog.Error(err) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() m.modLog.Errorf("Failed admin check on %s", aws.ToString(principal)) return false } diff --git a/aws/instances.go b/aws/instances.go index 2ee0e0d1..7fc52a2a 100644 --- a/aws/instances.go +++ b/aws/instances.go @@ -122,7 +122,7 @@ func (m *InstancesModule) Instances(filter string, outputDirectory string, verbo for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(instancesToSearch, region, wg, dataReceiver) } @@ -182,7 +182,7 @@ func (m *InstancesModule) printInstancesUserDataAttributesOnly(outputDirectory s err := os.MkdirAll(path, os.ModePerm) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } userDataFileName := filepath.Join(path, fmt.Sprintf("%s.txt", m.output.CallingModule)) @@ -214,7 +214,7 @@ func (m *InstancesModule) printInstancesUserDataAttributesOnly(outputDirectory s err = os.WriteFile(userDataFileName, []byte(userDataOut), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } fmt.Printf("[%s][%s] Loot written to [%s]\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), userDataFileName) } else { @@ -345,7 +345,7 @@ func (m *InstancesModule) writeLoot(outputDirectory string, verbosity int) { err := os.MkdirAll(path, os.ModePerm) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } privateIPsFilename := filepath.Join(path, "instances-ec2PrivateIPs.txt") publicIPsFilename := filepath.Join(path, "instances-ec2PublicIPs.txt") @@ -396,22 +396,22 @@ func (m *InstancesModule) writeLoot(outputDirectory string, verbosity int) { err = os.WriteFile(privateIPsFilename, []byte(privateIPs), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } err = os.WriteFile(publicIPsFilename, []byte(publicIPs), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } err = os.WriteFile(ssmCommandsFilename, []byte(ssmCommands), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } err = os.WriteFile(ec2InstanceConnectCommandsFilename, []byte(ec2InstanceConnectCommands), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } fmt.Printf("[%s][%s] Loot written to [%s]\n", cyan(m.output.CallingModule), cyan(m.AWSProfile), privateIPsFilename) @@ -448,17 +448,17 @@ func (m *InstancesModule) executeChecks(instancesToSearch []string, r string, wg res, err := servicemap.IsServiceInRegion("ec2", r) if err != nil { m.modLog.Errorf("Error checking if EC2 is available in region %s: %v", r, err) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } m.modLog.Debugf("ServiceMap check for EC2 in region %s: result=%v, error=%v", r, res, err) if res { - m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() m.getDescribeInstances(instancesToSearch, r, dataReceiver) - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() } else { m.modLog.Infof("Skipping region %s: EC2 not available or check failed", r) } @@ -469,7 +469,7 @@ func (m *InstancesModule) getInstanceUserDataAttribute(instanceID *string, regio if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return nil, err } else { if UserData == "" { @@ -489,7 +489,7 @@ func (m *InstancesModule) getDescribeInstances(instancesToSearch []string, regio Instances, err := sdk.CachedEC2DescribeInstances(m.EC2Client, aws.ToString(m.Caller.Account), region) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -588,7 +588,7 @@ func (m *InstancesModule) getRolesFromInstanceProfiles() { if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } for _, instanceProfile := range ListInstanceProfiles.InstanceProfiles { diff --git a/aws/inventory.go b/aws/inventory.go index ef87cb07..22dcd116 100644 --- a/aws/inventory.go +++ b/aws/inventory.go @@ -226,9 +226,9 @@ func (m *Inventory2Module) PrintInventoryPerRegion(outputDirectory string, verbo for _, region := range m.AWSRegions { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, semaphore, dataReceiver) } @@ -381,7 +381,7 @@ func (m *Inventory2Module) writeLoot(outputDirectory string, verbosity int) { err := os.MkdirAll(path, os.ModePerm) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } lootFile := filepath.Join(path, "inventory.txt") var out string @@ -393,7 +393,7 @@ func (m *Inventory2Module) writeLoot(outputDirectory string, verbosity int) { err = os.WriteFile(lootFile, []byte(out), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } if verbosity > 2 { @@ -433,7 +433,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore } // AppRunner is not supported in the aws service region catalog so we have to run it in all regions - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getAppRunnerServicesPerRegion(r, wg, semaphore) @@ -442,11 +442,11 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getAPIGatewayvAPIsPerRegion(r, wg, semaphore) - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getAPIGatewayv2APIsPerRegion(r, wg, semaphore) } @@ -456,7 +456,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getAthenaDatabasesPerRegion(r, wg, semaphore) // wg.Add(1) @@ -468,7 +468,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getCloud9EnvironmentsPerRegion(r, wg, semaphore) } @@ -478,7 +478,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getCloudFormationStacksPerRegion(r, wg, semaphore) } @@ -488,7 +488,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getCodeArtifactDomainsPerRegion(r, wg, semaphore) } @@ -498,7 +498,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getCodeBuildProjectsPerRegion(r, wg, semaphore) } @@ -508,7 +508,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getCodeCommitRepositoriesPerRegion(r, wg, semaphore) } @@ -518,7 +518,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getCodeDeployApplicationsPerRegion(r, wg, semaphore) wg.Add(1) @@ -531,7 +531,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getDataPipelinePipelinesPerRegion(r, wg, semaphore) } @@ -541,7 +541,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getDynamoDBTablesPerRegion(r, wg, semaphore) } @@ -551,7 +551,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getEc2InstancesPerRegion(r, wg, semaphore) wg.Add(1) @@ -567,7 +567,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getEcsTasksPerRegion(r, wg, semaphore) wg.Add(1) @@ -582,7 +582,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getEcrRepositoriesPerRegion(r, wg, semaphore) } @@ -592,7 +592,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getEksClustersPerRegion(r, wg, semaphore) wg.Add(1) @@ -604,11 +604,11 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getELBv2ListenersPerRegion(r, wg, semaphore) - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getELBListenersPerRegion(r, wg, semaphore) } @@ -618,7 +618,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getElasticacheClustersPerRegion(r, wg, semaphore) } @@ -628,7 +628,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getElasticBeanstalkApplicationsPerRegion(r, wg, semaphore) } @@ -638,7 +638,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getEMRClustersPerRegion(r, wg, semaphore) wg.Add(1) @@ -650,7 +650,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getOpenSearchPerRegion(r, wg, semaphore) } @@ -660,7 +660,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getGrafanaWorkspacesPerRegion(r, wg, semaphore) } @@ -670,7 +670,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getGlueDevEndpointsPerRegion(r, wg, semaphore) wg.Add(1) @@ -687,7 +687,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getKinesisDatastreamsPerRegion(r, wg, semaphore) } @@ -697,7 +697,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getLambdaFunctionsPerRegion(r, wg, semaphore) @@ -708,7 +708,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getLightsailInstancesAndContainersPerRegion(r, wg, semaphore) } @@ -718,7 +718,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getMqBrokersPerRegion(r, wg, semaphore) } @@ -728,7 +728,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getRdsClustersPerRegion(r, wg, semaphore) } @@ -738,7 +738,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getRedshiftClustersPerRegion(r, wg, semaphore) } @@ -748,7 +748,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getSecretsManagerSecretsPerRegion(r, wg, semaphore) } @@ -758,7 +758,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getSNSTopicsPerRegion(r, wg, semaphore) } @@ -768,7 +768,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getSQSQueuesPerRegion(r, wg, semaphore) } @@ -778,7 +778,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getSSMParametersPerRegion(r, wg, semaphore) } @@ -788,7 +788,7 @@ func (m *Inventory2Module) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getStepFunctionsPerRegion(r, wg, semaphore) } @@ -803,16 +803,16 @@ func (m *Inventory2Module) PrintTotalResources(AWSOutputType string) { func (m *Inventory2Module) getLambdaFunctionsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "Lambda Functions" var resourceNames []string @@ -820,7 +820,7 @@ func (m *Inventory2Module) getLambdaFunctionsPerRegion(r string, wg *sync.WaitGr ListFunctions, err := sdk.CachedLambdaListFunctions(m.LambdaClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -844,17 +844,17 @@ func (m *Inventory2Module) getLambdaFunctionsPerRegion(r string, wg *sync.WaitGr func (m *Inventory2Module) getAthenaDatabasesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "Athena Databases" @@ -863,7 +863,7 @@ func (m *Inventory2Module) getAthenaDatabasesPerRegion(r string, wg *sync.WaitGr ListDataCatalogs, err := sdk.CachedAthenaListDataCatalogs(m.AthenaClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -872,7 +872,7 @@ func (m *Inventory2Module) getAthenaDatabasesPerRegion(r string, wg *sync.WaitGr ListDatabases, err := sdk.CachedAthenaListDatabases(m.AthenaClient, aws.ToString(m.Caller.Account), r, aws.ToString(dc.CatalogName)) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -898,17 +898,17 @@ func (m *Inventory2Module) getAthenaDatabasesPerRegion(r string, wg *sync.WaitGr // func (m *Inventory2Module) getAthenaDataCatalogsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { // defer func() { // wg.Done() -// m.CommandCounter.Executing-- -// m.CommandCounter.Complete++ +// m.CommandCounter.DecrExecuting() +// m.CommandCounter.IncrComplete() // }() // semaphore <- struct{}{} // defer func() { // <-semaphore // }() -// // m.CommandCounter.Total++ -// m.CommandCounter.Pending-- -// m.CommandCounter.Executing++ +// // m.CommandCounter.IncrTotal() +// m.CommandCounter.DecrPending() +// m.CommandCounter.IncrExecuting() // var totalCountThisServiceThisRegion = 0 // var service = "Athena Data Catalogs" @@ -917,7 +917,7 @@ func (m *Inventory2Module) getAthenaDatabasesPerRegion(r string, wg *sync.WaitGr // ListDataCatalogs, err := sdk.CachedAthenaListDataCatalogs(m.AthenaClient, aws.ToString(m.Caller.Account), r) // if err != nil { // m.modLog.Error(err.Error()) -// m.CommandCounter.Error++ +// m.CommandCounter.IncrError() // return // } @@ -943,16 +943,16 @@ func (m *Inventory2Module) getAthenaDatabasesPerRegion(r string, wg *sync.WaitGr func (m *Inventory2Module) getEc2InstancesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "EC2 Instances" @@ -963,7 +963,7 @@ func (m *Inventory2Module) getEc2InstancesPerRegion(r string, wg *sync.WaitGroup if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -988,16 +988,16 @@ func (m *Inventory2Module) getEc2InstancesPerRegion(r string, wg *sync.WaitGroup func (m *Inventory2Module) getEc2ImagesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "EC2 AMIs" @@ -1008,7 +1008,7 @@ func (m *Inventory2Module) getEc2ImagesPerRegion(r string, wg *sync.WaitGroup, s if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1032,16 +1032,16 @@ func (m *Inventory2Module) getEc2ImagesPerRegion(r string, wg *sync.WaitGroup, s func (m *Inventory2Module) getEc2SnapshotsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "EC2 Snapshots" @@ -1052,7 +1052,7 @@ func (m *Inventory2Module) getEc2SnapshotsPerRegion(r string, wg *sync.WaitGroup if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1076,16 +1076,16 @@ func (m *Inventory2Module) getEc2SnapshotsPerRegion(r string, wg *sync.WaitGroup func (m *Inventory2Module) getEc2VolumesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "EC2 Volumes" @@ -1096,7 +1096,7 @@ func (m *Inventory2Module) getEc2VolumesPerRegion(r string, wg *sync.WaitGroup, if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1120,16 +1120,16 @@ func (m *Inventory2Module) getEc2VolumesPerRegion(r string, wg *sync.WaitGroup, func (m *Inventory2Module) getEksClustersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "EKS Clusters" @@ -1138,7 +1138,7 @@ func (m *Inventory2Module) getEksClustersPerRegion(r string, wg *sync.WaitGroup, ListClusters, err := sdk.CachedEKSListClusters(m.EKSClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1163,16 +1163,16 @@ func (m *Inventory2Module) getEksClustersPerRegion(r string, wg *sync.WaitGroup, func (m *Inventory2Module) getEKSNodeGroupsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "EKS Cluster NodeGroups" @@ -1181,7 +1181,7 @@ func (m *Inventory2Module) getEKSNodeGroupsPerRegion(r string, wg *sync.WaitGrou ListClusters, err := sdk.CachedEKSListClusters(m.EKSClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1189,7 +1189,7 @@ func (m *Inventory2Module) getEKSNodeGroupsPerRegion(r string, wg *sync.WaitGrou NodeGroups, err := sdk.CachedEKSListNodeGroups(m.EKSClient, aws.ToString(m.Caller.Account), r, cluster) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } // Add this page of resources to the total count @@ -1214,16 +1214,16 @@ func (m *Inventory2Module) getEKSNodeGroupsPerRegion(r string, wg *sync.WaitGrou func (m *Inventory2Module) getCloudFormationStacksPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "CloudFormation Stacks" @@ -1233,7 +1233,7 @@ func (m *Inventory2Module) getCloudFormationStacksPerRegion(r string, wg *sync.W if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1259,16 +1259,16 @@ func (m *Inventory2Module) getCloudFormationStacksPerRegion(r string, wg *sync.W func (m *Inventory2Module) getElasticacheClustersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "Elasticache Clusters" @@ -1278,7 +1278,7 @@ func (m *Inventory2Module) getElasticacheClustersPerRegion(r string, wg *sync.Wa if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1302,16 +1302,16 @@ func (m *Inventory2Module) getElasticacheClustersPerRegion(r string, wg *sync.Wa func (m *Inventory2Module) getElasticBeanstalkApplicationsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "ElasticBeanstalk Applications" @@ -1321,7 +1321,7 @@ func (m *Inventory2Module) getElasticBeanstalkApplicationsPerRegion(r string, wg if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1346,16 +1346,16 @@ func (m *Inventory2Module) getElasticBeanstalkApplicationsPerRegion(r string, wg func (m *Inventory2Module) getEMRClustersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "EMR Clusters" @@ -1365,7 +1365,7 @@ func (m *Inventory2Module) getEMRClustersPerRegion(r string, wg *sync.WaitGroup, if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1389,16 +1389,16 @@ func (m *Inventory2Module) getEMRClustersPerRegion(r string, wg *sync.WaitGroup, func (m *Inventory2Module) GetEMRInstancesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "EMR Instances" @@ -1408,7 +1408,7 @@ func (m *Inventory2Module) GetEMRInstancesPerRegion(r string, wg *sync.WaitGroup if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1418,7 +1418,7 @@ func (m *Inventory2Module) GetEMRInstancesPerRegion(r string, wg *sync.WaitGroup if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1443,16 +1443,16 @@ func (m *Inventory2Module) GetEMRInstancesPerRegion(r string, wg *sync.WaitGroup func (m *Inventory2Module) getSecretsManagerSecretsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "SecretsManager Secrets" @@ -1462,7 +1462,7 @@ func (m *Inventory2Module) getSecretsManagerSecretsPerRegion(r string, wg *sync. if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1487,16 +1487,16 @@ func (m *Inventory2Module) getSecretsManagerSecretsPerRegion(r string, wg *sync. func (m *Inventory2Module) getRdsClustersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "RDS DB Instances" @@ -1505,7 +1505,7 @@ func (m *Inventory2Module) getRdsClustersPerRegion(r string, wg *sync.WaitGroup, DescribeDBInstances, err := sdk.CachedRDSDescribeDBInstances(m.RDSClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1528,16 +1528,16 @@ func (m *Inventory2Module) getRdsClustersPerRegion(r string, wg *sync.WaitGroup, func (m *Inventory2Module) getAPIGatewayvAPIsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "APIGateway RestAPIs" @@ -1547,7 +1547,7 @@ func (m *Inventory2Module) getAPIGatewayvAPIsPerRegion(r string, wg *sync.WaitGr if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1571,16 +1571,16 @@ func (m *Inventory2Module) getAPIGatewayvAPIsPerRegion(r string, wg *sync.WaitGr func (m *Inventory2Module) getAPIGatewayv2APIsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "APIGatewayv2 APIs" @@ -1590,7 +1590,7 @@ func (m *Inventory2Module) getAPIGatewayv2APIsPerRegion(r string, wg *sync.WaitG if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1614,15 +1614,15 @@ func (m *Inventory2Module) getAPIGatewayv2APIsPerRegion(r string, wg *sync.WaitG func (m *Inventory2Module) getELBv2ListenersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "ELBv2 Load Balancers" var resourceNames []string @@ -1630,7 +1630,7 @@ func (m *Inventory2Module) getELBv2ListenersPerRegion(r string, wg *sync.WaitGro DescribeLoadBalancers, err := sdk.CachedELBv2DescribeLoadBalancers(m.ELBv2Client, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1654,16 +1654,16 @@ func (m *Inventory2Module) getELBv2ListenersPerRegion(r string, wg *sync.WaitGro func (m *Inventory2Module) getELBListenersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "ELB Load Balancers" @@ -1673,7 +1673,7 @@ func (m *Inventory2Module) getELBListenersPerRegion(r string, wg *sync.WaitGroup if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1697,16 +1697,16 @@ func (m *Inventory2Module) getELBListenersPerRegion(r string, wg *sync.WaitGroup func (m *Inventory2Module) getMqBrokersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "MQ Brokers" var resourceNames []string @@ -1714,7 +1714,7 @@ func (m *Inventory2Module) getMqBrokersPerRegion(r string, wg *sync.WaitGroup, s ListBrokers, err := sdk.CachedMQListBrokers(m.MQClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1737,16 +1737,16 @@ func (m *Inventory2Module) getMqBrokersPerRegion(r string, wg *sync.WaitGroup, s func (m *Inventory2Module) getOpenSearchPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "OpenSearch DomainNames" @@ -1755,7 +1755,7 @@ func (m *Inventory2Module) getOpenSearchPerRegion(r string, wg *sync.WaitGroup, ListDomainNames, err := sdk.CachedOpenSearchListDomainNames(m.OpenSearchClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1780,16 +1780,16 @@ func (m *Inventory2Module) getOpenSearchPerRegion(r string, wg *sync.WaitGroup, func (m *Inventory2Module) getGrafanaWorkspacesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "Grafana Workspaces" @@ -1800,7 +1800,7 @@ func (m *Inventory2Module) getGrafanaWorkspacesPerRegion(r string, wg *sync.Wait if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1824,16 +1824,16 @@ func (m *Inventory2Module) getGrafanaWorkspacesPerRegion(r string, wg *sync.Wait func (m *Inventory2Module) getAppRunnerServicesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "AppRunner Services" @@ -1844,7 +1844,7 @@ func (m *Inventory2Module) getAppRunnerServicesPerRegion(r string, wg *sync.Wait if err != nil { //modLog.Error(err.Error()) m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1867,16 +1867,16 @@ func (m *Inventory2Module) getAppRunnerServicesPerRegion(r string, wg *sync.Wait func (m *Inventory2Module) getLightsailInstancesAndContainersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "Lightsail Instances/Containers" @@ -1886,7 +1886,7 @@ func (m *Inventory2Module) getLightsailInstancesAndContainersPerRegion(r string, if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } else { // Add this page of resources to the total count @@ -1902,7 +1902,7 @@ func (m *Inventory2Module) getLightsailInstancesAndContainersPerRegion(r string, if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1926,16 +1926,16 @@ func (m *Inventory2Module) getLightsailInstancesAndContainersPerRegion(r string, func (m *Inventory2Module) getSSMParametersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "SSM Parameters" var resourceNames []string @@ -1944,7 +1944,7 @@ func (m *Inventory2Module) getSSMParametersPerRegion(r string, wg *sync.WaitGrou if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -1969,16 +1969,16 @@ func (m *Inventory2Module) getSSMParametersPerRegion(r string, wg *sync.WaitGrou func (m *Inventory2Module) getEcsTasksPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "ECS Tasks" @@ -1988,7 +1988,7 @@ func (m *Inventory2Module) getEcsTasksPerRegion(r string, wg *sync.WaitGroup, se if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } for _, cluster := range Clusters { @@ -1997,7 +1997,7 @@ func (m *Inventory2Module) getEcsTasksPerRegion(r string, wg *sync.WaitGroup, se if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } // Add this page of resources to the total count @@ -2022,16 +2022,16 @@ func (m *Inventory2Module) getEcsTasksPerRegion(r string, wg *sync.WaitGroup, se func (m *Inventory2Module) getEcsServicesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "ECS Services" @@ -2041,7 +2041,7 @@ func (m *Inventory2Module) getEcsServicesPerRegion(r string, wg *sync.WaitGroup, if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } for _, cluster := range Clusters { @@ -2050,7 +2050,7 @@ func (m *Inventory2Module) getEcsServicesPerRegion(r string, wg *sync.WaitGroup, if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } // Add this page of resources to the total count @@ -2076,16 +2076,16 @@ func (m *Inventory2Module) getEcsServicesPerRegion(r string, wg *sync.WaitGroup, func (m *Inventory2Module) getEcsClustersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "ECS Clusters" @@ -2095,7 +2095,7 @@ func (m *Inventory2Module) getEcsClustersPerRegion(r string, wg *sync.WaitGroup, if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2120,16 +2120,16 @@ func (m *Inventory2Module) getEcrRepositoriesPerRegion(r string, wg *sync.WaitGr // Don't use this method as a template for future ones. There is a one off in the way the NextToken is handled. defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "ECR Repositories" @@ -2139,7 +2139,7 @@ func (m *Inventory2Module) getEcrRepositoriesPerRegion(r string, wg *sync.WaitGr if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2164,16 +2164,16 @@ func (m *Inventory2Module) getGlueDevEndpointsPerRegion(r string, wg *sync.WaitG // Don't use this method as a template for future ones. There is a one off in the way the NextToken is handled. defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "Glue Dev Endpoints" var resourceNames []string @@ -2182,7 +2182,7 @@ func (m *Inventory2Module) getGlueDevEndpointsPerRegion(r string, wg *sync.WaitG if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2207,16 +2207,16 @@ func (m *Inventory2Module) getGlueDevEndpointsPerRegion(r string, wg *sync.WaitG func (m *Inventory2Module) getGlueJobsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "Glue Jobs" @@ -2226,7 +2226,7 @@ func (m *Inventory2Module) getGlueJobsPerRegion(r string, wg *sync.WaitGroup, se if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2251,16 +2251,16 @@ func (m *Inventory2Module) getGlueJobsPerRegion(r string, wg *sync.WaitGroup, se func (m *Inventory2Module) getGlueDatabasesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "Glue Databases" @@ -2269,7 +2269,7 @@ func (m *Inventory2Module) getGlueDatabasesPerRegion(r string, wg *sync.WaitGrou Databases, err := sdk.CachedGlueGetDatabases(m.GlueClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2298,16 +2298,16 @@ func (m *Inventory2Module) getGlueDatabasesPerRegion(r string, wg *sync.WaitGrou func (m *Inventory2Module) getGlueTablesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "Glue Jobs" @@ -2316,7 +2316,7 @@ func (m *Inventory2Module) getGlueTablesPerRegion(r string, wg *sync.WaitGroup, Databases, err := sdk.CachedGlueGetDatabases(m.GlueClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2324,7 +2324,7 @@ func (m *Inventory2Module) getGlueTablesPerRegion(r string, wg *sync.WaitGroup, TableNames, err := sdk.CachedGlueGetTables(m.GlueClient, aws.ToString(m.Caller.Account), r, aws.ToString(database.Name)) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2351,16 +2351,16 @@ func (m *Inventory2Module) getGlueTablesPerRegion(r string, wg *sync.WaitGroup, func (m *Inventory2Module) getKinesisDatastreamsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "Kinesis Data Streams" @@ -2369,7 +2369,7 @@ func (m *Inventory2Module) getKinesisDatastreamsPerRegion(r string, wg *sync.Wai Datastreams, err := sdk.CachedKinesisListStreams(m.KinesisClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2394,16 +2394,16 @@ func (m *Inventory2Module) getKinesisDatastreamsPerRegion(r string, wg *sync.Wai func (m *Inventory2Module) getSNSTopicsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var totalCountThisServiceThisRegion = 0 var service = "SNS Topics" @@ -2413,7 +2413,7 @@ func (m *Inventory2Module) getSNSTopicsPerRegion(r string, wg *sync.WaitGroup, s if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2435,16 +2435,16 @@ func (m *Inventory2Module) getSNSTopicsPerRegion(r string, wg *sync.WaitGroup, s func (m *Inventory2Module) getSQSQueuesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "SQS Queues" var resourceNames []string @@ -2453,7 +2453,7 @@ func (m *Inventory2Module) getSQSQueuesPerRegion(r string, wg *sync.WaitGroup, s if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2477,16 +2477,16 @@ func (m *Inventory2Module) getSQSQueuesPerRegion(r string, wg *sync.WaitGroup, s func (m *Inventory2Module) getDynamoDBTablesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "DynamoDB Tables" var resourceNames []string @@ -2494,7 +2494,7 @@ func (m *Inventory2Module) getDynamoDBTablesPerRegion(r string, wg *sync.WaitGro TableNames, err := sdk.CachedDynamoDBListTables(m.DynamoDBClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2520,16 +2520,16 @@ func (m *Inventory2Module) getDynamoDBTablesPerRegion(r string, wg *sync.WaitGro func (m *Inventory2Module) getRedshiftClustersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "Redshift Clusters" var resourceNames []string @@ -2537,7 +2537,7 @@ func (m *Inventory2Module) getRedshiftClustersPerRegion(r string, wg *sync.WaitG Clusters, err := sdk.CachedRedShiftDescribeClusters(m.RedshiftClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2563,16 +2563,16 @@ func (m *Inventory2Module) getRedshiftClustersPerRegion(r string, wg *sync.WaitG func (m *Inventory2Module) getCodeArtifactDomainsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "CodeArtifact Domains" var resourceNames []string @@ -2580,7 +2580,7 @@ func (m *Inventory2Module) getCodeArtifactDomainsPerRegion(r string, wg *sync.Wa Domains, err := sdk.CachedCodeArtifactListDomains(m.CodeArtifactClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2606,16 +2606,16 @@ func (m *Inventory2Module) getCodeArtifactDomainsPerRegion(r string, wg *sync.Wa func (m *Inventory2Module) getCodeBuildProjectsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "CodeBuild Projects" var resourceNames []string @@ -2623,7 +2623,7 @@ func (m *Inventory2Module) getCodeBuildProjectsPerRegion(r string, wg *sync.Wait projects, err := sdk.CachedCodeBuildListProjects(m.CodeBuildClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2649,16 +2649,16 @@ func (m *Inventory2Module) getCodeBuildProjectsPerRegion(r string, wg *sync.Wait func (m *Inventory2Module) getCodeCommitRepositoriesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "CodeCommit Repositories" var resourceNames []string @@ -2666,7 +2666,7 @@ func (m *Inventory2Module) getCodeCommitRepositoriesPerRegion(r string, wg *sync repos, err := sdk.CachedCodeCommitListRepositories(m.CodeCommitClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2690,16 +2690,16 @@ func (m *Inventory2Module) getCodeCommitRepositoriesPerRegion(r string, wg *sync func (m *Inventory2Module) getCodeDeployApplicationsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "CodeDeploy Applications" var resourceNames []string @@ -2707,7 +2707,7 @@ func (m *Inventory2Module) getCodeDeployApplicationsPerRegion(r string, wg *sync apps, err := sdk.CachedCodeDeployListApplications(m.CodeDeployClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2732,16 +2732,16 @@ func (m *Inventory2Module) getCodeDeployApplicationsPerRegion(r string, wg *sync func (m *Inventory2Module) getCodeDeployDeploymentsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "CodeDeploy Deployments" var resourceNames []string @@ -2749,7 +2749,7 @@ func (m *Inventory2Module) getCodeDeployDeploymentsPerRegion(r string, wg *sync. deployments, err := sdk.CachedCodeDeployListDeployments(m.CodeDeployClient, aws.ToString(m.Caller.Account), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2774,16 +2774,16 @@ func (m *Inventory2Module) getCodeDeployDeploymentsPerRegion(r string, wg *sync. func (m *Inventory2Module) getDataPipelinePipelinesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "DataPipeline Pipelines" var resourceNames []string @@ -2792,7 +2792,7 @@ func (m *Inventory2Module) getDataPipelinePipelinesPerRegion(r string, wg *sync. if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2817,16 +2817,16 @@ func (m *Inventory2Module) getDataPipelinePipelinesPerRegion(r string, wg *sync. func (m *Inventory2Module) getStepFunctionsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() semaphore <- struct{}{} defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "StepFunctions State Machines" var resourceNames []string @@ -2835,7 +2835,7 @@ func (m *Inventory2Module) getStepFunctionsPerRegion(r string, wg *sync.WaitGrou if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2859,15 +2859,15 @@ func (m *Inventory2Module) getStepFunctionsPerRegion(r string, wg *sync.WaitGrou func (m *Inventory2Module) getCloud9EnvironmentsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}) { defer func() { wg.Done() - m.CommandCounter.Executing-- + m.CommandCounter.DecrExecuting() }() semaphore <- struct{}{} defer func() { <-semaphore }() - m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() var totalCountThisServiceThisRegion = 0 var service = "Cloud9 Environments" var resourceNames []string @@ -2876,7 +2876,7 @@ func (m *Inventory2Module) getCloud9EnvironmentsPerRegion(r string, wg *sync.Wai if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2913,7 +2913,7 @@ func (m *Inventory2Module) getBuckets(verbosity int, dataReceiver chan GlobalRes if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2957,7 +2957,7 @@ func (m *Inventory2Module) getCloudfrontDistros(verbosity int, dataReceiver chan if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -2997,7 +2997,7 @@ func (m *Inventory2Module) getIAMUsers(verbosity int, dataReceiver chan GlobalRe if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } total = total + len(Users) @@ -3034,7 +3034,7 @@ func (m *Inventory2Module) getIAMRoles(verbosity int, dataReceiver chan GlobalRe if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } total = total + len(Roles) @@ -3073,7 +3073,7 @@ func (m *Inventory2Module) getIAMGroups(verbosity int, dataReceiver chan GlobalR if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } total = total + len(Groups) @@ -3112,7 +3112,7 @@ func (m *Inventory2Module) getIAMAccessKeys(verbosity int, dataReceiver chan Glo if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -3122,7 +3122,7 @@ func (m *Inventory2Module) getIAMAccessKeys(verbosity int, dataReceiver chan Glo if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } total = total + len(AccessKeys) @@ -3162,7 +3162,7 @@ func (m *Inventory2Module) getRoute53Zones(verbosity int, dataReceiver chan Glob if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } total = total + len(Zones) @@ -3200,7 +3200,7 @@ func (m *Inventory2Module) getRoute53Records(verbosity int, dataReceiver chan Gl if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -3209,7 +3209,7 @@ func (m *Inventory2Module) getRoute53Records(verbosity int, dataReceiver chan Gl if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } total = total + len(Records) diff --git a/aws/lambda.go b/aws/lambda.go index 4d633074..309ed168 100644 --- a/aws/lambda.go +++ b/aws/lambda.go @@ -105,7 +105,7 @@ func (m *LambdasModule) PrintLambdas(outputDirectory string, verbosity int) { for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, semaphore, dataReceiver) } @@ -241,7 +241,7 @@ func (m *LambdasModule) executeChecks(r string, wg *sync.WaitGroup, semaphore ch m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getLambdasPerRegion(r, wg, semaphore, dataReceiver) } @@ -265,7 +265,7 @@ func (m *LambdasModule) writeLoot(outputDirectory string, verbosity int) { err := os.MkdirAll(path, os.ModePerm) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } pullFile := filepath.Join(path, "lambda-get-function-commands.txt") @@ -289,7 +289,7 @@ func (m *LambdasModule) writeLoot(outputDirectory string, verbosity int) { err = os.WriteFile(pullFile, []byte(out), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } if verbosity > 2 { @@ -306,8 +306,8 @@ func (m *LambdasModule) writeLoot(outputDirectory string, verbosity int) { func (m *LambdasModule) getLambdasPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Lambda) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -319,7 +319,7 @@ func (m *LambdasModule) getLambdasPerRegion(r string, wg *sync.WaitGroup, semaph functions, err := m.listFunctions(r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } for _, function := range functions { @@ -360,7 +360,7 @@ func (m *LambdasModule) listFunctions(r string) ([]types.FunctionConfiguration, ) if err != nil { sharedLogger.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return functions, err } functions = append(functions, ListFunctions.Functions...) @@ -389,7 +389,7 @@ func (m *LambdasModule) getResourcePolicy(r string, functionName string) (policy ) if err != nil { sharedLogger.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return projectPolicy, err } diff --git a/aws/network-ports.go b/aws/network-ports.go index 5709ac4a..cd234347 100644 --- a/aws/network-ports.go +++ b/aws/network-ports.go @@ -50,9 +50,6 @@ var ( # Make sure the host you scan IPv6 from has an IPv6 network interface. ############################################# ` - - naclsMutex = sync.RWMutex{} - securityGroupsMutex = sync.RWMutex{} ) type NetworkPortsModule struct { @@ -77,11 +74,13 @@ type NetworkPortsModule struct { ServiceMap *awsservicemap.AwsServiceMap // Shared service map to avoid repeated HTTP requests // Main module data - IPv4_Private []NetworkService - IPv4_Public []NetworkService - IPv6 []NetworkService - nacls map[string]*[]ec2_types.NetworkAcl - securityGroups map[string]*[]ec2_types.SecurityGroup + IPv4_Private []NetworkService + IPv4_Public []NetworkService + IPv6 []NetworkService + nacls map[string]*[]ec2_types.NetworkAcl + securityGroups map[string]*[]ec2_types.SecurityGroup + naclsMutex sync.RWMutex + securityGroupsMutex sync.RWMutex CommandCounter internal.CommandCounter // Used to store output data for pretty printing @@ -172,7 +171,7 @@ func (m *NetworkPortsModule) PrintNetworkPorts(outputDirectory string) { for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, dataReceiver) } @@ -287,7 +286,7 @@ func (m *NetworkPortsModule) executeChecks(r string, wg *sync.WaitGroup, dataRec m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() m.getEC2NetworkPortsPerRegion(r, dataReceiver) } @@ -296,7 +295,7 @@ func (m *NetworkPortsModule) executeChecks(r string, wg *sync.WaitGroup, dataRec m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() m.getECSNetworkPortsPerRegion(r, dataReceiver) } @@ -305,7 +304,7 @@ func (m *NetworkPortsModule) executeChecks(r string, wg *sync.WaitGroup, dataRec m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() m.getEFSNetworkPortsPerRegion(r, dataReceiver) } @@ -314,7 +313,7 @@ func (m *NetworkPortsModule) executeChecks(r string, wg *sync.WaitGroup, dataRec m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() m.getElastiCacheNetworkPortsPerRegion(r, dataReceiver) } @@ -323,7 +322,7 @@ func (m *NetworkPortsModule) executeChecks(r string, wg *sync.WaitGroup, dataRec m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() m.getLBNetworkPortsPerRegion(r, dataReceiver) } @@ -332,7 +331,7 @@ func (m *NetworkPortsModule) executeChecks(r string, wg *sync.WaitGroup, dataRec m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() m.getLightsailNetworkPortsPerRegion(r, dataReceiver) } @@ -341,7 +340,7 @@ func (m *NetworkPortsModule) executeChecks(r string, wg *sync.WaitGroup, dataRec m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() m.getRdsNetworkPortsPerRegion(r, dataReceiver) } @@ -429,8 +428,8 @@ func (m *NetworkPortsModule) writeLootFile(filename string, bannner string, ipv4 func (m *NetworkPortsModule) getEC2NetworkPortsPerRegion(r string, dataReceiver chan NetworkServices) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() securityGroups := m.getEC2SecurityGroupsPerRegion(r) nacls := m.getEC2NACLsPerRegion(r) @@ -533,8 +532,8 @@ func (m *NetworkPortsModule) getEC2NetworkPortsPerRegion(r string, dataReceiver func (m *NetworkPortsModule) getECSNetworkPortsPerRegion(r string, dataReceiver chan NetworkServices) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() securityGroups := m.getEC2SecurityGroupsPerRegion(r) nacls := m.getEC2NACLsPerRegion(r) @@ -548,7 +547,7 @@ func (m *NetworkPortsModule) getECSNetworkPortsPerRegion(r string, dataReceiver service, err := m.describeECSService(serviceArn, &clusterArn, r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -585,7 +584,7 @@ func (m *NetworkPortsModule) getECSNetworkPortsPerRegion(r string, dataReceiver task, err := m.describeECSTask(taskArn, &clusterArn, r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -668,8 +667,8 @@ func (m *NetworkPortsModule) getECSNetworkPortsPerRegion(r string, dataReceiver func (m *NetworkPortsModule) getEFSNetworkPortsPerRegion(r string, dataReceiver chan NetworkServices) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() securityGroups := m.getEC2SecurityGroupsPerRegion(r) nacls := m.getEC2NACLsPerRegion(r) @@ -731,8 +730,8 @@ func (m *NetworkPortsModule) getEFSNetworkPortsPerRegion(r string, dataReceiver func (m *NetworkPortsModule) getElastiCacheNetworkPortsPerRegion(r string, dataReceiver chan NetworkServices) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() securityGroups := m.getEC2SecurityGroupsPerRegion(r) nacls := m.getEC2NACLsPerRegion(r) @@ -843,8 +842,8 @@ func (m *NetworkPortsModule) getElastiCacheNetworkPortsPerRegion(r string, dataR func (m *NetworkPortsModule) getLBNetworkPortsPerRegion(r string, dataReceiver chan NetworkServices) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() securityGroups := m.getEC2SecurityGroupsPerRegion(r) nacls := m.getEC2NACLsPerRegion(r) @@ -959,8 +958,8 @@ func (m *NetworkPortsModule) getLBNetworkPortsPerRegion(r string, dataReceiver c func (m *NetworkPortsModule) getLightsailNetworkPortsPerRegion(r string, dataReceiver chan NetworkServices) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() instances := m.getLightsailInstancesPerRegion(r) @@ -1070,8 +1069,8 @@ func (m *NetworkPortsModule) getLightsailNetworkPortsPerRegion(r string, dataRec func (m *NetworkPortsModule) getRdsNetworkPortsPerRegion(r string, dataReceiver chan NetworkServices) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() }() securityGroups := m.getEC2SecurityGroupsPerRegion(r) nacls := m.getEC2NACLsPerRegion(r) @@ -1143,13 +1142,16 @@ func (m *NetworkPortsModule) getRdsNetworkPortsPerRegion(r string, dataReceiver } func (m *NetworkPortsModule) getEC2SecurityGroupsPerRegion(region string) []ec2_types.SecurityGroup { + m.securityGroupsMutex.RLock() + cached, ok := m.securityGroups[region] + m.securityGroupsMutex.RUnlock() + if ok && cached != nil { + return *cached + } + var securityGroups []ec2_types.SecurityGroup var PaginationControl *string - if m.securityGroups[region] != nil { - return *m.securityGroups[region] - } - for { DescribeSecurityGroups, err := m.EC2Client.DescribeSecurityGroups( context.TODO(), @@ -1162,7 +1164,7 @@ func (m *NetworkPortsModule) getEC2SecurityGroupsPerRegion(region string) []ec2_ ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1176,9 +1178,9 @@ func (m *NetworkPortsModule) getEC2SecurityGroupsPerRegion(region string) []ec2_ } } - securityGroupsMutex.Lock() + m.securityGroupsMutex.Lock() m.securityGroups[region] = &securityGroups - securityGroupsMutex.Unlock() + m.securityGroupsMutex.Unlock() return securityGroups } @@ -1215,13 +1217,16 @@ func (m *NetworkPortsModule) parseSecurityGroup(group ec2_types.SecurityGroup) S } func (m *NetworkPortsModule) getEC2NACLsPerRegion(region string) []ec2_types.NetworkAcl { + m.naclsMutex.RLock() + cached, ok := m.nacls[region] + m.naclsMutex.RUnlock() + if ok && cached != nil { + return *cached + } + var nacls []ec2_types.NetworkAcl var PaginationControl *string - if m.nacls[region] != nil { - return *m.nacls[region] - } - for { DescribeNetworkAcls, err := m.EC2Client.DescribeNetworkAcls( context.TODO(), @@ -1234,7 +1239,7 @@ func (m *NetworkPortsModule) getEC2NACLsPerRegion(region string) []ec2_types.Net ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1248,9 +1253,9 @@ func (m *NetworkPortsModule) getEC2NACLsPerRegion(region string) []ec2_types.Net } } - naclsMutex.Lock() + m.naclsMutex.Lock() m.nacls[region] = &nacls - naclsMutex.Unlock() + m.naclsMutex.Unlock() return nacls } @@ -1320,7 +1325,7 @@ func (m *NetworkPortsModule) getEC2InstancesPerRegion(region string) []ec2_types ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1359,7 +1364,7 @@ func (m *NetworkPortsModule) getEC2NetworkInterfacesPerRegion(interfaceId string ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1394,7 +1399,7 @@ func (m *NetworkPortsModule) getECSClustersPerRegion(region string) []string { ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1430,7 +1435,7 @@ func (m *NetworkPortsModule) getECSServicesPerRegion(clusterArn *string, region ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1493,7 +1498,7 @@ func (m *NetworkPortsModule) getECSTasksPerRegion(service *string, clusterArn *s ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1553,7 +1558,7 @@ func (m *NetworkPortsModule) getEFSSharesPerRegion(region string) []efs_types.Fi ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1589,7 +1594,7 @@ func (m *NetworkPortsModule) getEFSMountTargetsPerRegion(filesystem *string, reg ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1624,7 +1629,7 @@ func (m *NetworkPortsModule) getElastiCacheClustersPerRegion(region string) []el ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1659,7 +1664,7 @@ func (m *NetworkPortsModule) getElastiCacheSubnetGroupsPerRegion(region string) ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1694,7 +1699,7 @@ func (m *NetworkPortsModule) getElastiCacheReplicationGroupsPerRegion(region str ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1729,7 +1734,7 @@ func (m *NetworkPortsModule) getLightsailInstancesPerRegion(region string) []lig ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1764,7 +1769,7 @@ func (m *NetworkPortsModule) getLoadBalancersPerRegion(region string) []elbv2_ty ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1800,7 +1805,7 @@ func (m *NetworkPortsModule) getLBListenerPorts(arn *string, region string) ([]i ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1850,7 +1855,7 @@ func (m *NetworkPortsModule) getRdsClustersPerRegion(region string) []rds_types. ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -1885,7 +1890,7 @@ func (m *NetworkPortsModule) getRdsInstancesPerRegion(region string) []rds_types ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } diff --git a/aws/network-ports_test.go b/aws/network-ports_test.go new file mode 100644 index 00000000..1e8d1658 --- /dev/null +++ b/aws/network-ports_test.go @@ -0,0 +1,67 @@ +package aws + +import ( + "fmt" + "sync" + "testing" + + ec2_types "github.com/aws/aws-sdk-go-v2/service/ec2/types" +) + +// TestNetworkPortsCacheConcurrentAccess is a regression test for issue #129. +// Pre-fix, the cache lookup in getEC2NACLsPerRegion and getEC2SecurityGroupsPerRegion +// read m.nacls / m.securityGroups without holding a mutex while writes from +// other goroutines were locked, producing a "concurrent map read and map write" +// panic under load. Run with `go test -race ./aws/...` to verify the lock fix. +func TestNetworkPortsCacheConcurrentAccess(t *testing.T) { + m := &NetworkPortsModule{ + nacls: make(map[string]*[]ec2_types.NetworkAcl), + securityGroups: make(map[string]*[]ec2_types.SecurityGroup), + } + + // Pre-populate one region so reader goroutines hit the cached fast-path + // without needing a live EC2 client. + cachedNACLs := []ec2_types.NetworkAcl{} + m.nacls["cached"] = &cachedNACLs + cachedSGs := []ec2_types.SecurityGroup{} + m.securityGroups["cached"] = &cachedSGs + + var wg sync.WaitGroup + const readers = 100 + for i := 0; i < readers; i++ { + wg.Add(2) + go func() { + defer wg.Done() + _ = m.getEC2NACLsPerRegion("cached") + }() + go func() { + defer wg.Done() + _ = m.getEC2SecurityGroupsPerRegion("cached") + }() + } + + // Writer goroutines populate uncached regions directly through the mutex, + // mirroring what the live functions do after a successful AWS fetch. The + // readers above must not race with these writes. + const writers = 10 + for i := 0; i < writers; i++ { + region := fmt.Sprintf("uncached-%d", i) + wg.Add(2) + go func(r string) { + defer wg.Done() + sl := []ec2_types.NetworkAcl{} + m.naclsMutex.Lock() + m.nacls[r] = &sl + m.naclsMutex.Unlock() + }(region) + go func(r string) { + defer wg.Done() + sl := []ec2_types.SecurityGroup{} + m.securityGroupsMutex.Lock() + m.securityGroups[r] = &sl + m.securityGroupsMutex.Unlock() + }(region) + } + + wg.Wait() +} diff --git a/aws/org.go b/aws/org.go index 626116b7..351c46db 100644 --- a/aws/org.go +++ b/aws/org.go @@ -191,7 +191,7 @@ func (m *OrgModule) ProcessMultipleAccounts(AWSProfiles []string, version string for _, profile := range AWSProfiles { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.FindMgmtAccounts(profile, version, wg, semaphore, dataReceiver) wg.Wait() @@ -244,7 +244,7 @@ func (m *OrgModule) FindMgmtAccounts(profile string, version string, wg *sync.Wa DescribeOrganization, err := sdk.CachedOrganizationsDescribeOrganization(m.OrganizationsClient, aws.ToString(m.Caller.Account)) if err != nil { m.modLog.Errorf("Failed to describe organization: %s", err) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -273,7 +273,7 @@ func (m *OrgModule) addOrgAccounts() { accounts, err := sdk.CachedOrganizationsListAccounts(m.OrganizationsClient, aws.ToString(m.Caller.Account)) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } for _, account := range accounts { @@ -292,7 +292,7 @@ func (m *OrgModule) addOrgAccount() { DescribeOrganization, err := sdk.CachedOrganizationsDescribeOrganization(m.OrganizationsClient, aws.ToString(m.Caller.Account)) if err != nil { sharedLogger.Errorf("Failed to describe organization: %s", err) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } m.Accounts = append(m.Accounts, Account{ diff --git a/aws/outbound-assumed-roles.go b/aws/outbound-assumed-roles.go index c673f74d..69bb9b53 100644 --- a/aws/outbound-assumed-roles.go +++ b/aws/outbound-assumed-roles.go @@ -171,7 +171,7 @@ func (m *OutboundAssumedRolesModule) PrintOutboundRoleTrusts(days int, outputDir for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, semaphore, dataReceiver) } @@ -308,10 +308,10 @@ func (m *OutboundAssumedRolesModule) executeChecks(r string, wg *sync.WaitGroup, } if res { // wg.Add(1) - // m.CommandCounter.Total++ + // m.CommandCounter.IncrTotal() // m.getAssumeRoleLogEntriesPerRegion(r, wg, semaphore, dataReceiver) wg.Add(1) - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() m.getCrossAccountBatchGetImageEntriesPerRegion(r, wg, semaphore, dataReceiver) } @@ -319,8 +319,8 @@ func (m *OutboundAssumedRolesModule) executeChecks(r string, wg *sync.WaitGroup, func (m *OutboundAssumedRolesModule) getAssumeRoleLogEntriesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan OutboundAssumeRoleEntry) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -358,7 +358,7 @@ func (m *OutboundAssumedRolesModule) getAssumeRoleLogEntriesPerRegion(r string, ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -412,8 +412,8 @@ func (m *OutboundAssumedRolesModule) getAssumeRoleLogEntriesPerRegion(r string, // get cross account batch get image entries func (m *OutboundAssumedRolesModule) getCrossAccountBatchGetImageEntriesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan OutboundAssumeRoleEntry) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -451,7 +451,7 @@ func (m *OutboundAssumedRolesModule) getCrossAccountBatchGetImageEntriesPerRegio ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } diff --git a/aws/permissions.go b/aws/permissions.go index 51f7e644..4ae52454 100644 --- a/aws/permissions.go +++ b/aws/permissions.go @@ -197,7 +197,7 @@ func (m *IamPermissionsModule) GetGAAD() { GAAD, err := sdk.CachedIAMGetAccountAuthorizationDetails(m.IAMClient, aws.ToString(m.Caller.Account)) if err != nil { m.modLog.Error(err) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } diff --git a/aws/pmapper.go b/aws/pmapper.go index 33684816..d1756ae6 100644 --- a/aws/pmapper.go +++ b/aws/pmapper.go @@ -446,7 +446,7 @@ func (m *PmapperModule) writeLoot(outputDirectory string, verbosity int) string err := os.MkdirAll(path, os.ModePerm) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() panic(err.Error()) } lootFilePath := filepath.Join(path, "pmapper.txt") diff --git a/aws/principals.go b/aws/principals.go index e00340ad..0cfae2fc 100644 --- a/aws/principals.go +++ b/aws/principals.go @@ -97,7 +97,7 @@ func (m *IamPrincipalsModule) PrintIamPrincipals(outputDirectory string, verbosi // done := make(chan bool) // go internal.SpinUntil(m.output.CallingModule, &m.CommandCounter, done) // wg.Add(1) - // m.CommandCounter.Pending++ + // m.CommandCounter.IncrPending() //m.executeChecks(wg) // wg.Wait() // done <- true @@ -237,13 +237,13 @@ func (m *IamPrincipalsModule) PrintIamPrincipals(outputDirectory string, verbosi /* UNUSED CODE BLOCK - PLEASE REVIEW AND DELETE IF APPLICABLE func (m *IamPrincipalsModule) executeChecks(wg *sync.WaitGroup) { defer wg.Done() - m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() m.getIAMUsers() m.getIAMRoles() - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() } */ @@ -256,7 +256,7 @@ func (m *IamPrincipalsModule) addIAMUsersToTable() { ListUsers, err := sdk.CachedIamListUsers(m.IAMClient, aws.ToString(m.Caller.Account)) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } for _, user := range ListUsers { @@ -288,7 +288,7 @@ func (m *IamPrincipalsModule) addIAMRolesToTable() { ListRoles, err := sdk.CachedIamListRoles(m.IAMClient, aws.ToString(m.Caller.Account)) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } for _, role := range ListRoles { diff --git a/aws/ram.go b/aws/ram.go index b8b14ffa..12679815 100644 --- a/aws/ram.go +++ b/aws/ram.go @@ -79,7 +79,7 @@ func (m *RAMModule) PrintRAM(outputDirectory string, verbosity int) { for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, dataReceiver) } @@ -191,12 +191,12 @@ func (m *RAMModule) executeChecks(r string, wg *sync.WaitGroup, dataReceiver cha m.modLog.Error(err) } if res { - m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() m.getRAMResourcesPerRegion(r, dataReceiver) - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() } } @@ -235,7 +235,7 @@ func (m *RAMModule) getRAMResourcesPerRegion(r string, dataReceiver chan Resourc ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -259,7 +259,7 @@ func (m *RAMModule) getRAMResourcesPerRegion(r string, dataReceiver chan Resourc ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } diff --git a/aws/resource-trusts.go b/aws/resource-trusts.go index 6d9ed55b..bb6bdc84 100644 --- a/aws/resource-trusts.go +++ b/aws/resource-trusts.go @@ -104,7 +104,7 @@ func (m *ResourceTrustsModule) PrintResources(outputDirectory string, verbosity for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, semaphore, dataReceiver, includeKms) } @@ -217,7 +217,7 @@ func (m *ResourceTrustsModule) executeChecks(r string, wg *sync.WaitGroup, semap m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getSNSTopicsPerRegion(r, wg, semaphore, dataReceiver) } @@ -227,7 +227,7 @@ func (m *ResourceTrustsModule) executeChecks(r string, wg *sync.WaitGroup, semap m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getSQSQueuesPerRegion(r, wg, semaphore, dataReceiver) } @@ -237,7 +237,7 @@ func (m *ResourceTrustsModule) executeChecks(r string, wg *sync.WaitGroup, semap m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getECRRecordsPerRegion(r, wg, semaphore, dataReceiver) } @@ -247,7 +247,7 @@ func (m *ResourceTrustsModule) executeChecks(r string, wg *sync.WaitGroup, semap m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getCodeBuildResourcePoliciesPerRegion(r, wg, semaphore, dataReceiver) } @@ -257,7 +257,7 @@ func (m *ResourceTrustsModule) executeChecks(r string, wg *sync.WaitGroup, semap m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getLambdaPolicyPerRegion(r, wg, semaphore, dataReceiver) } @@ -267,7 +267,7 @@ func (m *ResourceTrustsModule) executeChecks(r string, wg *sync.WaitGroup, semap m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getEFSfilesystemPoliciesPerRegion(r, wg, semaphore, dataReceiver) } @@ -277,7 +277,7 @@ func (m *ResourceTrustsModule) executeChecks(r string, wg *sync.WaitGroup, semap m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getSecretsManagerSecretsPoliciesPerRegion(r, wg, semaphore, dataReceiver) } @@ -287,7 +287,7 @@ func (m *ResourceTrustsModule) executeChecks(r string, wg *sync.WaitGroup, semap m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getGlueResourcePoliciesPerRegion(r, wg, semaphore, dataReceiver) } @@ -298,7 +298,7 @@ func (m *ResourceTrustsModule) executeChecks(r string, wg *sync.WaitGroup, semap m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getKMSPoliciesPerRegion(r, wg, semaphore, dataReceiver) } @@ -310,7 +310,7 @@ func (m *ResourceTrustsModule) executeChecks(r string, wg *sync.WaitGroup, semap m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getAPIGatewayPoliciesPerRegion(r, wg, semaphore, dataReceiver) } @@ -322,7 +322,7 @@ func (m *ResourceTrustsModule) executeChecks(r string, wg *sync.WaitGroup, semap m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getVPCEndpointPoliciesPerRegion(r, wg, semaphore, dataReceiver) } @@ -334,7 +334,7 @@ func (m *ResourceTrustsModule) executeChecks(r string, wg *sync.WaitGroup, semap m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getOpenSearchPoliciesPerRegion(r, wg, semaphore, dataReceiver) } @@ -356,8 +356,8 @@ func (m *ResourceTrustsModule) Receiver(receiver chan Resource2, receiverDone ch func (m *ResourceTrustsModule) getSNSTopicsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Resource2) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -378,7 +378,7 @@ func (m *ResourceTrustsModule) getSNSTopicsPerRegion(r string, wg *sync.WaitGrou topic, err := cloudFoxSNSClient.getTopicWithAttributes(aws.ToString(t.TopicArn), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } parsedArn, err := arn.Parse(aws.ToString(t.TopicArn)) @@ -433,8 +433,8 @@ func (m *ResourceTrustsModule) getSNSTopicsPerRegion(r string, wg *sync.WaitGrou func (m *ResourceTrustsModule) getS3Buckets(wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Resource2) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -516,8 +516,8 @@ func (m *ResourceTrustsModule) getS3Buckets(wg *sync.WaitGroup, semaphore chan s func (m *ResourceTrustsModule) getSQSQueuesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Resource2) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -539,7 +539,7 @@ func (m *ResourceTrustsModule) getSQSQueuesPerRegion(r string, wg *sync.WaitGrou queue, err := cloudFoxSQSClient.getQueueWithAttributes(q, r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } @@ -578,8 +578,8 @@ func (m *ResourceTrustsModule) getSQSQueuesPerRegion(r string, wg *sync.WaitGrou func (m *ResourceTrustsModule) getECRRecordsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Resource2) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -601,7 +601,7 @@ func (m *ResourceTrustsModule) getECRRecordsPerRegion(r string, wg *sync.WaitGro repoPolicy, err := cloudFoxECRClient.getECRRepositoryPolicy(r, aws.ToString(repo.RepositoryName)) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } @@ -642,8 +642,8 @@ func (m *ResourceTrustsModule) getECRRecordsPerRegion(r string, wg *sync.WaitGro func (m *ResourceTrustsModule) getCodeBuildResourcePoliciesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Resource2) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -666,7 +666,7 @@ func (m *ResourceTrustsModule) getCodeBuildResourcePoliciesPerRegion(r string, w project, err := sdk.CachedCodeBuildBatchGetProjects(cloudFoxCodeBuildClient.CodeBuildClient, aws.ToString(cloudFoxCodeBuildClient.Caller.Account), r, p) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } @@ -716,8 +716,8 @@ func (m *ResourceTrustsModule) getCodeBuildResourcePoliciesPerRegion(r string, w func (m *ResourceTrustsModule) getLambdaPolicyPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Resource2) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -739,7 +739,7 @@ func (m *ResourceTrustsModule) getLambdaPolicyPerRegion(r string, wg *sync.WaitG functionPolicy, err := cloudFoxLambdaClient.getResourcePolicy(r, aws.ToString(f.FunctionName)) if err != nil { sharedLogger.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } @@ -781,8 +781,8 @@ func (m *ResourceTrustsModule) getLambdaPolicyPerRegion(r string, wg *sync.WaitG func (m *ResourceTrustsModule) getEFSfilesystemPoliciesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Resource2) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -804,7 +804,7 @@ func (m *ResourceTrustsModule) getEFSfilesystemPoliciesPerRegion(r string, wg *s fsPolicy, err := sdk.CachedDescribeFileSystemPolicy(cloudFoxEFSClient.EFSClient, aws.ToString(fs.FileSystemId), r, aws.ToString(m.Caller.Account)) if err != nil { sharedLogger.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } @@ -851,8 +851,8 @@ func (m *ResourceTrustsModule) getEFSfilesystemPoliciesPerRegion(r string, wg *s // It takes the region to search in, the WaitGroup to use, the semaphore to use, and the dataReceiver channel to send results to. func (m *ResourceTrustsModule) getSecretsManagerSecretsPoliciesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Resource2) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -874,7 +874,7 @@ func (m *ResourceTrustsModule) getSecretsManagerSecretsPoliciesPerRegion(r strin secretPolicy, err := sdk.CachedSecretsManagerGetResourcePolicy(cloudFoxSecretsManagerClient, aws.ToString(s.ARN), r, aws.ToString(m.Caller.Account)) if err != nil { sharedLogger.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } @@ -921,8 +921,8 @@ func (m *ResourceTrustsModule) getSecretsManagerSecretsPoliciesPerRegion(r strin // It takes the region to search in, the WaitGroup to use, the semaphore to use, and the dataReceiver channel to send results to. func (m *ResourceTrustsModule) getKMSPoliciesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Resource2) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() semaphore <- struct{}{} @@ -942,7 +942,7 @@ func (m *ResourceTrustsModule) getKMSPoliciesPerRegion(r string, wg *sync.WaitGr keyPolicy, err := sdk.CachedKMSGetKeyPolicy(*m.KMSClient, aws.ToString(m.Caller.Account), r, aws.ToString(key.KeyId)) if err != nil { sharedLogger.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } @@ -985,8 +985,8 @@ func (m *ResourceTrustsModule) getKMSPoliciesPerRegion(r string, wg *sync.WaitGr func (m *ResourceTrustsModule) getAPIGatewayPoliciesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Resource2) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() semaphore <- struct{}{} @@ -1016,7 +1016,7 @@ func (m *ResourceTrustsModule) getAPIGatewayPoliciesPerRegion(r string, wg *sync restAPIPolicy, err := policy.ParseJSONPolicy([]byte(policyJson)) if err != nil { sharedLogger.Error(fmt.Errorf("parsing policy (%s) as JSON: %s", aws.ToString(restAPI.Name), err)) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } @@ -1063,8 +1063,8 @@ func (m *ResourceTrustsModule) getAPIGatewayPoliciesPerRegion(r string, wg *sync func (m *ResourceTrustsModule) getVPCEndpointPoliciesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Resource2) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() semaphore <- struct{}{} @@ -1086,7 +1086,7 @@ func (m *ResourceTrustsModule) getVPCEndpointPoliciesPerRegion(r string, wg *syn vpcEndpointPolicy, err := policy.ParseJSONPolicy([]byte(vpcEndpointPolicyJson)) if err != nil { sharedLogger.Error(fmt.Errorf("parsing policy (%s) as JSON: %s", aws.ToString(vpcEndpoint.VpcEndpointId), err)) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } @@ -1133,8 +1133,8 @@ func (m *ResourceTrustsModule) getVPCEndpointPoliciesPerRegion(r string, wg *syn func (m *ResourceTrustsModule) getOpenSearchPoliciesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Resource2) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() semaphore <- struct{}{} @@ -1153,7 +1153,7 @@ func (m *ResourceTrustsModule) getOpenSearchPoliciesPerRegion(r string, wg *sync openSearchDomainConfig, err := sdk.CachedOpenSearchDescribeDomainConfig(*m.OpenSearchClient, aws.ToString(m.Caller.Account), r, aws.ToString(openSearchDomain.DomainName)) if err != nil { sharedLogger.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } @@ -1167,7 +1167,7 @@ func (m *ResourceTrustsModule) getOpenSearchPoliciesPerRegion(r string, wg *sync openSearchDomainStatus, err := sdk.CachedOpenSearchDescribeDomain(*m.OpenSearchClient, aws.ToString(m.Caller.Account), r, aws.ToString(openSearchDomain.DomainName)) if err != nil { sharedLogger.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } @@ -1179,7 +1179,7 @@ func (m *ResourceTrustsModule) getOpenSearchPoliciesPerRegion(r string, wg *sync openSearchDomainPolicy, err := policy.ParseJSONPolicy([]byte(policyJson)) if err != nil { sharedLogger.Error(fmt.Errorf("parsing policy (%s) as JSON: %s", aws.ToString(openSearchDomainStatus.ARN), err)) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() continue } @@ -1226,8 +1226,8 @@ func (m *ResourceTrustsModule) getOpenSearchPoliciesPerRegion(r string, wg *sync func (m *ResourceTrustsModule) getGlueResourcePoliciesPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Resource2) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() diff --git a/aws/role-trusts.go b/aws/role-trusts.go index 8785e5b1..cd33bb2d 100644 --- a/aws/role-trusts.go +++ b/aws/role-trusts.go @@ -590,14 +590,14 @@ func (m *RoleTrustsModule) getAllRoleTrusts() { ListRoles, err := sdk.CachedIamListRoles(m.IAMClient, aws.ToString(m.Caller.Account)) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } for _, role := range ListRoles { trustsdoc, err := policy.ParseRoleTrustPolicyDocument(role) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } diff --git a/aws/route53.go b/aws/route53.go index 652d76db..46c579c3 100644 --- a/aws/route53.go +++ b/aws/route53.go @@ -146,7 +146,7 @@ func (m *Route53Module) writeLoot(outputDirectory string, verbosity int) { err := os.MkdirAll(path, os.ModePerm) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() panic(err.Error()) } route53ARecordsPublicZonesFileName := filepath.Join(path, "route53-A-records-public-Zones.txt") @@ -168,7 +168,7 @@ func (m *Route53Module) writeLoot(outputDirectory string, verbosity int) { err = os.WriteFile(route53ARecordsPublicZonesFileName, []byte(route53APublicRecords), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() panic(err.Error()) } @@ -186,7 +186,7 @@ func (m *Route53Module) writeLoot(outputDirectory string, verbosity int) { err = os.WriteFile(route53ARecordsPrivateZonesFileName, []byte(route53APrivateRecords), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() panic(err.Error()) } @@ -212,7 +212,7 @@ func (m *Route53Module) getRoute53Records() { if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -228,7 +228,7 @@ func (m *Route53Module) getRoute53Records() { if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } for _, record := range Records { diff --git a/aws/secrets.go b/aws/secrets.go index 5a610f6e..14d4fe4c 100644 --- a/aws/secrets.go +++ b/aws/secrets.go @@ -82,7 +82,7 @@ func (m *SecretsModule) PrintSecrets(outputDirectory string, verbosity int) { for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, semaphore, dataReceiver) } @@ -205,7 +205,7 @@ func (m *SecretsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore ch m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getSecretsManagerSecretsPerRegion(r, wg, semaphore, dataReceiver) } @@ -214,7 +214,7 @@ func (m *SecretsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore ch m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getSSMParametersPerRegion(r, wg, semaphore, dataReceiver) } @@ -226,7 +226,7 @@ func (m *SecretsModule) writeLoot(outputDirectory string, verbosity int) { err := os.MkdirAll(path, os.ModePerm) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } pullFile := filepath.Join(path, "pull-secrets-commands.txt") @@ -249,7 +249,7 @@ func (m *SecretsModule) writeLoot(outputDirectory string, verbosity int) { err = os.WriteFile(pullFile, []byte(out), 0644) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } if verbosity > 2 { @@ -266,8 +266,8 @@ func (m *SecretsModule) writeLoot(outputDirectory string, verbosity int) { func (m *SecretsModule) getSecretsManagerSecretsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Secret) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -275,9 +275,9 @@ func (m *SecretsModule) getSecretsManagerSecretsPerRegion(r string, wg *sync.Wai defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var PaginationControl *string for { @@ -292,7 +292,7 @@ func (m *SecretsModule) getSecretsManagerSecretsPerRegion(r string, wg *sync.Wai ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -324,8 +324,8 @@ func (m *SecretsModule) getSecretsManagerSecretsPerRegion(r string, wg *sync.Wai func (m *SecretsModule) getSSMParametersPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Secret) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -333,9 +333,9 @@ func (m *SecretsModule) getSSMParametersPerRegion(r string, wg *sync.WaitGroup, defer func() { <-semaphore }() - // m.CommandCounter.Total++ - m.CommandCounter.Pending-- - m.CommandCounter.Executing++ + // m.CommandCounter.IncrTotal() + m.CommandCounter.DecrPending() + m.CommandCounter.IncrExecuting() // "PaginationMarker" is a control variable used for output continuity, as AWS return the output in pages. var PaginationControl *string @@ -351,7 +351,7 @@ func (m *SecretsModule) getSSMParametersPerRegion(r string, wg *sync.WaitGroup, ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } diff --git a/aws/sns.go b/aws/sns.go index 8c8d57df..d40970aa 100644 --- a/aws/sns.go +++ b/aws/sns.go @@ -96,7 +96,7 @@ func (m *SNSModule) PrintSNS(outputDirectory string, verbosity int) { for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, semaphore, dataReceiver) } @@ -205,7 +205,7 @@ func (m *SNSModule) executeChecks(r string, wg *sync.WaitGroup, semaphore chan s m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getSNSTopicsPerRegion(r, wg, semaphore, dataReceiver) } @@ -288,8 +288,8 @@ func (m *SNSModule) writeLoot(outputDirectory string, verbosity int, profile str func (m *SNSModule) getSNSTopicsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan SNSTopic) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -308,7 +308,7 @@ func (m *SNSModule) getSNSTopicsPerRegion(r string, wg *sync.WaitGroup, semaphor topic, err := m.getTopicWithAttributes(aws.ToString(t.TopicArn), r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } parsedArn, err := arn.Parse(aws.ToString(t.TopicArn)) @@ -427,7 +427,7 @@ func (m *SNSModule) storeAccessPolicy(topic *SNSTopic) { if err := m.storeFile(f, topic.PolicyJSON); err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/aws/sqs.go b/aws/sqs.go index 3f735a7d..b0557c94 100644 --- a/aws/sqs.go +++ b/aws/sqs.go @@ -99,7 +99,7 @@ func (m *SQSModule) PrintSQS(outputDirectory string, verbosity int) { for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, semaphore, dataReceiver) } @@ -207,7 +207,7 @@ func (m *SQSModule) executeChecks(r string, wg *sync.WaitGroup, semaphore chan s m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getSQSRecordsPerRegion(r, wg, semaphore, dataReceiver) } @@ -287,8 +287,8 @@ func (m *SQSModule) writeLoot(outputDirectory string, verbosity int, profile str func (m *SQSModule) getSQSRecordsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Queue) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -301,7 +301,7 @@ func (m *SQSModule) getSQSRecordsPerRegion(r string, wg *sync.WaitGroup, semapho if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -309,7 +309,7 @@ func (m *SQSModule) getSQSRecordsPerRegion(r string, wg *sync.WaitGroup, semapho queue, err := m.getQueueWithAttributes(url, r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } @@ -437,7 +437,7 @@ func (m *SQSModule) storeAccessPolicy(queue *Queue) { if err := m.storeFile(f, queue.PolicyJSON); err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/aws/tags.go b/aws/tags.go index e32aba2b..b2e0607a 100644 --- a/aws/tags.go +++ b/aws/tags.go @@ -88,7 +88,7 @@ func (m *TagsModule) PrintTags(outputDirectory string, verbosity int) { for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, semaphore, dataReceiver) } @@ -246,7 +246,7 @@ func (m *TagsModule) countUniqueResourcesWithTags() int { func (m *TagsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Tag) { defer wg.Done() - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) m.getTagsPerRegion(r, wg, semaphore, dataReceiver) } @@ -266,8 +266,8 @@ func (m *TagsModule) Receiver(receiver chan Tag, receiverDone chan bool) { func (m *TagsModule) getTagsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Tag) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -280,7 +280,7 @@ func (m *TagsModule) getTagsPerRegion(r string, wg *sync.WaitGroup, semaphore ch resources, err := m.getResources(r) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } //var parsedArn types.Arn for _, resource := range resources { @@ -337,7 +337,7 @@ func (m *TagsModule) getResources(r string) ([]types.ResourceTagMapping, error) ) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return resources, err } diff --git a/aws/workloads.go b/aws/workloads.go index 5096880a..f9a52318 100644 --- a/aws/workloads.go +++ b/aws/workloads.go @@ -109,7 +109,7 @@ func (m *WorkloadsModule) PrintWorkloads(outputDirectory string, verbosity int) for _, region := range m.AWSRegions { wg.Add(1) - m.CommandCounter.Pending++ + m.CommandCounter.IncrPending() go m.executeChecks(region, wg, semaphore, dataReceiver) } @@ -281,14 +281,14 @@ func (m *WorkloadsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore res, _ := servicemap.IsServiceInRegion("ec2", r) if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getEC2WorkloadsPerRegion(r, wg, semaphore, dataReceiver) } res, _ = servicemap.IsServiceInRegion("ecs", r) if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getECSWorkloadsPerRegion(r, wg, semaphore, dataReceiver) } @@ -298,13 +298,13 @@ func (m *WorkloadsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore m.modLog.Error(err) } if res { - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getLambdaWorkloadsPerRegion(r, wg, semaphore, dataReceiver) } // AppRunner is not supported in the aws service region catalog so we have to run it in all regions - m.CommandCounter.Total++ + m.CommandCounter.IncrTotal() wg.Add(1) go m.getAppRunnerWorkloadsPerRegion(r, wg, semaphore, dataReceiver) @@ -312,8 +312,8 @@ func (m *WorkloadsModule) executeChecks(r string, wg *sync.WaitGroup, semaphore func (m *WorkloadsModule) getEC2WorkloadsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Workload) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -369,8 +369,8 @@ func (m *WorkloadsModule) getEC2WorkloadsPerRegion(r string, wg *sync.WaitGroup, func (m *WorkloadsModule) getECSWorkloadsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Workload) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -395,7 +395,7 @@ func (m *WorkloadsModule) getECSWorkloadsPerRegion(r string, wg *sync.WaitGroup, Tasks, err := sdk.CachedECSDescribeTasks(m.ECSClient, aws.ToString(m.Caller.Account), r, cluster, taskARNs) if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() return } @@ -424,8 +424,8 @@ func (m *WorkloadsModule) getECSWorkloadsPerRegion(r string, wg *sync.WaitGroup, func (m *WorkloadsModule) getLambdaWorkloadsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Workload) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -457,8 +457,8 @@ func (m *WorkloadsModule) getLambdaWorkloadsPerRegion(r string, wg *sync.WaitGro func (m *WorkloadsModule) getAppRunnerWorkloadsPerRegion(r string, wg *sync.WaitGroup, semaphore chan struct{}, dataReceiver chan Workload) { defer func() { - m.CommandCounter.Executing-- - m.CommandCounter.Complete++ + m.CommandCounter.DecrExecuting() + m.CommandCounter.IncrComplete() wg.Done() }() @@ -543,7 +543,7 @@ func (m *WorkloadsModule) getRolesFromInstanceProfiles() { if err != nil { m.modLog.Error(err.Error()) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() break } for _, instanceProfile := range ListInstanceProfiles.InstanceProfiles { diff --git a/gcp/commands/appengine.go b/gcp/commands/appengine.go index 47d88a3a..62ef6dfb 100644 --- a/gcp/commands/appengine.go +++ b/gcp/commands/appengine.go @@ -200,7 +200,7 @@ func (m *AppEngineModule) processProject(ctx context.Context, projectID string, app, err := aeService.Apps.Get(projectID).Do() if err != nil { if !strings.Contains(err.Error(), "404") { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_APPENGINE_MODULE_NAME, fmt.Sprintf("Could not get App Engine app in project %s", projectID)) } @@ -251,7 +251,7 @@ func (m *AppEngineModule) processProject(ctx context.Context, projectID string, func (m *AppEngineModule) enumerateServices(ctx context.Context, projectID string, aeService *appengine.APIService, logger internal.Logger) { services, err := aeService.Apps.Services.List(projectID).Do() if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_APPENGINE_MODULE_NAME, fmt.Sprintf("Could not enumerate App Engine services in project %s", projectID)) return @@ -288,7 +288,7 @@ func (m *AppEngineModule) enumerateServices(ctx context.Context, projectID strin func (m *AppEngineModule) enumerateVersions(ctx context.Context, projectID, serviceID, ingressSettings string, aeService *appengine.APIService, logger internal.Logger) { versions, err := aeService.Apps.Services.Versions.List(projectID, serviceID).Do() if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_APPENGINE_MODULE_NAME, fmt.Sprintf("Could not enumerate App Engine versions for service %s", serviceID)) return @@ -362,7 +362,7 @@ func (m *AppEngineModule) enumerateVersions(ctx context.Context, projectID, serv func (m *AppEngineModule) enumerateFirewallRules(ctx context.Context, projectID string, aeService *appengine.APIService, logger internal.Logger) { rules, err := aeService.Apps.Firewall.IngressRules.List(projectID).Do() if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_APPENGINE_MODULE_NAME, fmt.Sprintf("Could not enumerate App Engine firewall rules in project %s", projectID)) return @@ -776,7 +776,7 @@ func (m *AppEngineModule) writeHierarchicalOutput(ctx context.Context, logger in ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), GCP_APPENGINE_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -823,6 +823,6 @@ func (m *AppEngineModule) writeFlatOutput(ctx context.Context, logger internal.L ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), GCP_APPENGINE_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/artifact-registry.go b/gcp/commands/artifact-registry.go index 844b19d4..5133506f 100644 --- a/gcp/commands/artifact-registry.go +++ b/gcp/commands/artifact-registry.go @@ -146,7 +146,7 @@ func (m *ArtifactRegistryModule) processProject(ctx context.Context, projectID s ars := ArtifactRegistryService.New(m.client) result, err := ars.RepositoriesAndArtifacts(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_ARTIFACT_RESGISTRY_MODULE_NAME, fmt.Sprintf("Could not enumerate artifact registries in project %s", projectID)) return @@ -525,7 +525,7 @@ func (m *ArtifactRegistryModule) writeHierarchicalOutput(ctx context.Context, lo ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_ARTIFACT_RESGISTRY_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -583,6 +583,6 @@ func (m *ArtifactRegistryModule) writeFlatOutput(ctx context.Context, logger int ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_ARTIFACT_RESGISTRY_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/assetinventory.go b/gcp/commands/assetinventory.go index 849cc991..cbe271bf 100644 --- a/gcp/commands/assetinventory.go +++ b/gcp/commands/assetinventory.go @@ -257,7 +257,7 @@ func (m *AssetInventoryModule) processProject(ctx context.Context, projectID str svc := assetservice.New() assets, err := svc.ListAssets(projectID, assetTypes) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_ASSET_INVENTORY_MODULE_NAME, fmt.Sprintf("Could not enumerate assets in project %s", projectID)) return @@ -283,7 +283,7 @@ func (m *AssetInventoryModule) processProjectIAM(ctx context.Context, projectID svc := assetservice.New() assets, err := svc.ListAssetsWithIAM(projectID, assetTypes) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_ASSET_INVENTORY_MODULE_NAME, fmt.Sprintf("Could not enumerate assets with IAM in project %s", projectID)) return @@ -309,7 +309,7 @@ func (m *AssetInventoryModule) processProjectCounts(ctx context.Context, project svc := assetservice.New() counts, err := svc.GetAssetTypeCounts(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_ASSET_INVENTORY_MODULE_NAME, fmt.Sprintf("Could not count assets in project %s", projectID)) return @@ -374,7 +374,7 @@ func (m *AssetInventoryModule) processProjectWithDependencies(ctx context.Contex break } if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() parsedErr := gcpinternal.ParseGCPError(err, "cloudasset.googleapis.com") gcpinternal.HandleGCPError(parsedErr, logger, globals.GCP_ASSET_INVENTORY_MODULE_NAME, fmt.Sprintf("Could not enumerate assets in project %s", projectID)) diff --git a/gcp/commands/backupinventory.go b/gcp/commands/backupinventory.go index b06d4019..66fd7c7f 100644 --- a/gcp/commands/backupinventory.go +++ b/gcp/commands/backupinventory.go @@ -283,7 +283,7 @@ func (m *BackupInventoryModule) enumerateDisks(ctx context.Context, projectID st }) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_BACKUPINVENTORY_MODULE_NAME, fmt.Sprintf("Could not enumerate disks in project %s", projectID)) } @@ -376,7 +376,7 @@ func (m *BackupInventoryModule) enumerateSnapshots(ctx context.Context, projectI }) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_BACKUPINVENTORY_MODULE_NAME, fmt.Sprintf("Could not enumerate snapshots in project %s", projectID)) } @@ -445,7 +445,7 @@ func (m *BackupInventoryModule) trackSnapshotProtection(projectID string) { func (m *BackupInventoryModule) enumerateSQLBackups(ctx context.Context, projectID string, sqlService *sqladmin.Service, logger internal.Logger) { instances, err := sqlService.Instances.List(projectID).Do() if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_BACKUPINVENTORY_MODULE_NAME, fmt.Sprintf("Could not enumerate SQL instances in project %s", projectID)) return diff --git a/gcp/commands/beyondcorp.go b/gcp/commands/beyondcorp.go index 59ec47df..73a1e9d8 100644 --- a/gcp/commands/beyondcorp.go +++ b/gcp/commands/beyondcorp.go @@ -132,7 +132,7 @@ func (m *BeyondCorpModule) processProject(ctx context.Context, projectID string, // Get app connectors connectors, err := svc.ListAppConnectors(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_BEYONDCORP_MODULE_NAME, fmt.Sprintf("Could not list app connectors in project %s", projectID)) } @@ -146,7 +146,7 @@ func (m *BeyondCorpModule) processProject(ctx context.Context, projectID string, // Get app connections connections, err := svc.ListAppConnections(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_BEYONDCORP_MODULE_NAME, fmt.Sprintf("Could not list app connections in project %s", projectID)) } diff --git a/gcp/commands/bigquery.go b/gcp/commands/bigquery.go index d7b211a5..3ec6bf9d 100644 --- a/gcp/commands/bigquery.go +++ b/gcp/commands/bigquery.go @@ -129,7 +129,7 @@ func (m *BigQueryModule) processProject(ctx context.Context, projectID string, l bqService := BigQueryService.New() result, err := bqService.BigqueryDatasetsAndTables(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_BIGQUERY_MODULE_NAME, fmt.Sprintf("Could not enumerate BigQuery in project %s", projectID)) return @@ -425,7 +425,7 @@ func (m *BigQueryModule) writeHierarchicalOutput(ctx context.Context, logger int ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_BIGQUERY_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -479,6 +479,6 @@ func (m *BigQueryModule) writeFlatOutput(ctx context.Context, logger internal.Lo ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_BIGQUERY_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/bigqueryenum.go b/gcp/commands/bigqueryenum.go index 7bbedfbf..f7502fa1 100644 --- a/gcp/commands/bigqueryenum.go +++ b/gcp/commands/bigqueryenum.go @@ -128,7 +128,7 @@ func (m *BigQueryEnumModule) processProject(ctx context.Context, projectID strin resources, err := svc.EnumerateSensitiveResources(projectID, m.MaxTables, m.SampleData, m.MaxRows) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_BIGQUERYENUM_MODULE_NAME, fmt.Sprintf("Could not scan BigQuery in project %s", projectID)) return diff --git a/gcp/commands/bigtable.go b/gcp/commands/bigtable.go index ae1df557..d981b405 100644 --- a/gcp/commands/bigtable.go +++ b/gcp/commands/bigtable.go @@ -118,7 +118,7 @@ func (m *BigtableModule) processProject(ctx context.Context, projectID string, l svc := bigtableservice.New() result, err := svc.ListInstances(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_BIGTABLE_MODULE_NAME, fmt.Sprintf("Could not enumerate Bigtable instances in project %s", projectID)) return diff --git a/gcp/commands/bigtableenum.go b/gcp/commands/bigtableenum.go index a8cac26e..e7f83d83 100644 --- a/gcp/commands/bigtableenum.go +++ b/gcp/commands/bigtableenum.go @@ -103,7 +103,7 @@ func (m *BigtableEnumModule) processProject(ctx context.Context, projectID strin resources, err := svc.EnumerateSensitiveResources(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_BIGTABLEENUM_MODULE_NAME, fmt.Sprintf("Could not scan Bigtable in project %s", projectID)) return diff --git a/gcp/commands/bucketenum.go b/gcp/commands/bucketenum.go index 7bc9e505..99bdefb0 100644 --- a/gcp/commands/bucketenum.go +++ b/gcp/commands/bucketenum.go @@ -214,7 +214,7 @@ func (m *BucketEnumModule) processProject(ctx context.Context, projectID string, // Get list of buckets buckets, err := svc.GetBucketsList(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_STORAGEENUM_MODULE_NAME, fmt.Sprintf("Could not enumerate buckets in project %s", projectID)) return @@ -230,7 +230,7 @@ func (m *BucketEnumModule) processProject(ctx context.Context, projectID string, for _, bucketName := range buckets { objects, err := svc.EnumerateAllBucketObjects(bucketName, projectID, m.MaxObjects) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_STORAGEENUM_MODULE_NAME, fmt.Sprintf("Could not enumerate bucket %s in project %s", bucketName, projectID)) continue @@ -263,7 +263,7 @@ func (m *BucketEnumModule) processProject(ctx context.Context, projectID string, for _, bucketName := range buckets { files, err := svc.EnumerateBucketSensitiveFiles(bucketName, projectID, m.MaxObjects) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_STORAGEENUM_MODULE_NAME, fmt.Sprintf("Could not scan bucket %s in project %s", bucketName, projectID)) continue diff --git a/gcp/commands/buckets.go b/gcp/commands/buckets.go index d0b0df9f..6cf6dbe4 100644 --- a/gcp/commands/buckets.go +++ b/gcp/commands/buckets.go @@ -155,7 +155,7 @@ func (m *BucketsModule) processProject(ctx context.Context, projectID string, lo cs := CloudStorageService.New() buckets, err := cs.Buckets(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_STORAGE_MODULE_NAME, fmt.Sprintf("Could not enumerate buckets in project %s", projectID)) return @@ -305,7 +305,7 @@ func (m *BucketsModule) writeHierarchicalOutput(ctx context.Context, logger inte ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_STORAGE_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -357,7 +357,7 @@ func (m *BucketsModule) writeFlatOutput(ctx context.Context, logger internal.Log ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_STORAGE_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/certmanager.go b/gcp/commands/certmanager.go index 0e279059..bd77b5d8 100644 --- a/gcp/commands/certmanager.go +++ b/gcp/commands/certmanager.go @@ -167,7 +167,7 @@ func (m *CertManagerModule) processProject(ctx context.Context, projectID string // Get Certificate Manager certs certs, err := svc.GetCertificates(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_CERTMANAGER_MODULE_NAME, fmt.Sprintf("Could not enumerate certificates in project %s", projectID)) } @@ -175,7 +175,7 @@ func (m *CertManagerModule) processProject(ctx context.Context, projectID string // Get classic SSL certs sslCerts, err := svc.GetSSLCertificates(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_CERTMANAGER_MODULE_NAME, fmt.Sprintf("Could not enumerate SSL certificates in project %s", projectID)) } @@ -183,7 +183,7 @@ func (m *CertManagerModule) processProject(ctx context.Context, projectID string // Get certificate maps certMaps, err := svc.GetCertificateMaps(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_CERTMANAGER_MODULE_NAME, fmt.Sprintf("Could not enumerate certificate maps in project %s", projectID)) } @@ -377,6 +377,6 @@ func (m *CertManagerModule) writeFlatOutput(ctx context.Context, logger internal "project", m.ProjectIDs, scopeNames, m.Account, output) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_CERTMANAGER_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/cloudarmor.go b/gcp/commands/cloudarmor.go index a722bde7..18aff308 100644 --- a/gcp/commands/cloudarmor.go +++ b/gcp/commands/cloudarmor.go @@ -133,7 +133,7 @@ func (m *CloudArmorModule) processProject(ctx context.Context, projectID string, // Get security policies policies, err := svc.GetSecurityPolicies(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_CLOUDARMOR_MODULE_NAME, fmt.Sprintf("Could not enumerate Cloud Armor security policies in project %s", projectID)) } @@ -141,7 +141,7 @@ func (m *CloudArmorModule) processProject(ctx context.Context, projectID string, // Get unprotected LBs unprotectedLBs, err := svc.GetUnprotectedLoadBalancers(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_CLOUDARMOR_MODULE_NAME, fmt.Sprintf("Could not enumerate unprotected load balancers in project %s", projectID)) } diff --git a/gcp/commands/cloudbuild.go b/gcp/commands/cloudbuild.go index 02ba4d49..b434e933 100644 --- a/gcp/commands/cloudbuild.go +++ b/gcp/commands/cloudbuild.go @@ -126,7 +126,7 @@ func (m *CloudBuildModule) processProject(ctx context.Context, projectID string, // Get triggers triggers, err := cbSvc.ListTriggers(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_CLOUDBUILD_MODULE_NAME, fmt.Sprintf("Could not enumerate Cloud Build triggers in project %s", projectID)) } @@ -134,7 +134,7 @@ func (m *CloudBuildModule) processProject(ctx context.Context, projectID string, // Get recent builds builds, err := cbSvc.ListBuilds(projectID, 20) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_CLOUDBUILD_MODULE_NAME, fmt.Sprintf("Could not enumerate Cloud Build builds in project %s", projectID)) } @@ -518,6 +518,6 @@ func (m *CloudBuildModule) writeFlatOutput(ctx context.Context, logger internal. ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_CLOUDBUILD_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/cloudrun.go b/gcp/commands/cloudrun.go index 2bca99ee..62fb413c 100644 --- a/gcp/commands/cloudrun.go +++ b/gcp/commands/cloudrun.go @@ -176,7 +176,7 @@ func (m *CloudRunModule) processProject(ctx context.Context, projectID string, l // Get services services, err := cs.Services(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_CLOUDRUN_MODULE_NAME, fmt.Sprintf("Could not enumerate Cloud Run services in project %s", projectID)) } else { @@ -191,7 +191,7 @@ func (m *CloudRunModule) processProject(ctx context.Context, projectID string, l // Get jobs jobs, err := cs.Jobs(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_CLOUDRUN_MODULE_NAME, fmt.Sprintf("Could not enumerate Cloud Run jobs in project %s", projectID)) } else { @@ -391,7 +391,7 @@ func (m *CloudRunModule) writeHierarchicalOutput(ctx context.Context, logger int ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_CLOUDRUN_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -436,7 +436,7 @@ func (m *CloudRunModule) writeFlatOutput(ctx context.Context, logger internal.Lo ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_CLOUDRUN_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/cloudsql.go b/gcp/commands/cloudsql.go index 0bb1dc58..5e4766d4 100644 --- a/gcp/commands/cloudsql.go +++ b/gcp/commands/cloudsql.go @@ -147,7 +147,7 @@ func (m *CloudSQLModule) processProject(ctx context.Context, projectID string, l cs := CloudSQLService.New() instances, err := cs.Instances(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_CLOUDSQL_MODULE_NAME, fmt.Sprintf("Could not enumerate Cloud SQL in project %s", projectID)) return @@ -403,7 +403,7 @@ func (m *CloudSQLModule) writeHierarchicalOutput(ctx context.Context, logger int ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_CLOUDSQL_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -453,7 +453,7 @@ func (m *CloudSQLModule) writeFlatOutput(ctx context.Context, logger internal.Lo ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_CLOUDSQL_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/compliancedashboard.go b/gcp/commands/compliancedashboard.go index e081ed08..d3ca77ac 100644 --- a/gcp/commands/compliancedashboard.go +++ b/gcp/commands/compliancedashboard.go @@ -1852,7 +1852,7 @@ func (m *ComplianceDashboardModule) writeHierarchicalOutput(ctx context.Context, err := internal.HandleHierarchicalOutputSmart("gcp", m.Format, m.Verbosity, m.WrapTable, pathBuilder, outputData) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), GCP_COMPLIANCEDASHBOARD_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -1979,7 +1979,7 @@ func (m *ComplianceDashboardModule) writeFlatOutput(ctx context.Context, logger output, ) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_COMPLIANCEDASHBOARD_MODULE_NAME, "Could not write output") } diff --git a/gcp/commands/composer.go b/gcp/commands/composer.go index 39bb7979..b4449b9b 100644 --- a/gcp/commands/composer.go +++ b/gcp/commands/composer.go @@ -104,7 +104,7 @@ func (m *ComposerModule) processProject(ctx context.Context, projectID string, l svc := composerservice.New() environments, err := svc.ListEnvironments(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_COMPOSER_MODULE_NAME, fmt.Sprintf("Could not enumerate Composer environments in project %s", projectID)) return diff --git a/gcp/commands/costsecurity.go b/gcp/commands/costsecurity.go index ee718aec..6895db17 100644 --- a/gcp/commands/costsecurity.go +++ b/gcp/commands/costsecurity.go @@ -259,7 +259,7 @@ func (m *CostSecurityModule) analyzeComputeInstances(ctx context.Context, projec }) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_COSTSECURITY_MODULE_NAME, fmt.Sprintf("Could not enumerate compute instances in project %s", projectID)) } @@ -525,7 +525,7 @@ func (m *CostSecurityModule) findOrphanedDisks(ctx context.Context, projectID st }) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_COSTSECURITY_MODULE_NAME, fmt.Sprintf("Could not enumerate disks in project %s", projectID)) } @@ -583,7 +583,7 @@ func (m *CostSecurityModule) findOrphanedIPs(ctx context.Context, projectID stri }) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_COSTSECURITY_MODULE_NAME, fmt.Sprintf("Could not enumerate addresses in project %s", projectID)) } @@ -592,7 +592,7 @@ func (m *CostSecurityModule) findOrphanedIPs(ctx context.Context, projectID stri func (m *CostSecurityModule) analyzeSQLInstances(ctx context.Context, projectID string, sqlService *sqladmin.Service, logger internal.Logger) { instances, err := sqlService.Instances.List(projectID).Do() if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_COSTSECURITY_MODULE_NAME, fmt.Sprintf("Could not enumerate SQL instances in project %s", projectID)) return @@ -642,7 +642,7 @@ func (m *CostSecurityModule) analyzeSQLInstances(ctx context.Context, projectID func (m *CostSecurityModule) analyzeStorageBuckets(ctx context.Context, projectID string, storageService *storage.Service, logger internal.Logger) { buckets, err := storageService.Buckets.List(projectID).Do() if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_COSTSECURITY_MODULE_NAME, fmt.Sprintf("Could not enumerate storage buckets in project %s", projectID)) return @@ -1011,7 +1011,7 @@ func (m *CostSecurityModule) writeHierarchicalOutput(ctx context.Context, logger err := internal.HandleHierarchicalOutputSmart("gcp", m.Format, m.Verbosity, m.WrapTable, pathBuilder, outputData) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), GCP_COSTSECURITY_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -1166,6 +1166,6 @@ func (m *CostSecurityModule) writeFlatOutput(ctx context.Context, logger interna ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), GCP_COSTSECURITY_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/crossproject.go b/gcp/commands/crossproject.go index d0fd1e62..621ba8f1 100644 --- a/gcp/commands/crossproject.go +++ b/gcp/commands/crossproject.go @@ -142,7 +142,7 @@ func (m *CrossProjectModule) Execute(ctx context.Context, logger internal.Logger // Analyze cross-project bindings bindings, err := svc.AnalyzeCrossProjectAccess(m.ProjectIDs, m.OrgCache) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_CROSSPROJECT_MODULE_NAME, "Could not analyze cross-project access") } else { @@ -152,7 +152,7 @@ func (m *CrossProjectModule) Execute(ctx context.Context, logger internal.Logger // Get cross-project service accounts sas, err := svc.GetCrossProjectServiceAccounts(m.ProjectIDs) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_CROSSPROJECT_MODULE_NAME, "Could not get cross-project service accounts") } else { @@ -162,7 +162,7 @@ func (m *CrossProjectModule) Execute(ctx context.Context, logger internal.Logger // Find lateral movement paths paths, err := svc.FindLateralMovementPaths(m.ProjectIDs, m.OrgCache) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_CROSSPROJECT_MODULE_NAME, "Could not find lateral movement paths") } else { @@ -172,7 +172,7 @@ func (m *CrossProjectModule) Execute(ctx context.Context, logger internal.Logger // Find cross-project logging sinks sinks, err := svc.FindCrossProjectLoggingSinks(m.ProjectIDs) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_CROSSPROJECT_MODULE_NAME, "Could not find cross-project logging sinks") } else { @@ -182,7 +182,7 @@ func (m *CrossProjectModule) Execute(ctx context.Context, logger internal.Logger // Find cross-project Pub/Sub exports pubsubExports, err := svc.FindCrossProjectPubSubExports(m.ProjectIDs) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_CROSSPROJECT_MODULE_NAME, "Could not find cross-project Pub/Sub exports") } else { @@ -606,7 +606,7 @@ func (m *CrossProjectModule) writeHierarchicalOutput(ctx context.Context, logger err := internal.HandleHierarchicalOutputSmart("gcp", m.Format, m.Verbosity, m.WrapTable, pathBuilder, outputData) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_CROSSPROJECT_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -656,7 +656,7 @@ func (m *CrossProjectModule) writeFlatOutput(ctx context.Context, logger interna ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output for project %s: %v", targetProject, err), globals.GCP_CROSSPROJECT_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } } diff --git a/gcp/commands/dataexfiltration.go b/gcp/commands/dataexfiltration.go index 3475c8db..a26dabbe 100755 --- a/gcp/commands/dataexfiltration.go +++ b/gcp/commands/dataexfiltration.go @@ -703,7 +703,7 @@ func (m *DataExfiltrationModule) processProject(ctx context.Context, projectID s func (m *DataExfiltrationModule) findPublicSnapshots(ctx context.Context, projectID string, logger internal.Logger) { computeService, err := compute.NewService(ctx) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_DATAEXFILTRATION_MODULE_NAME, fmt.Sprintf("Could not create Compute service in project %s", projectID)) return @@ -848,7 +848,7 @@ func (m *DataExfiltrationModule) findPublicImages(ctx context.Context, projectID func (m *DataExfiltrationModule) findPublicBuckets(ctx context.Context, projectID string, logger internal.Logger) { storageService, err := storage.NewService(ctx) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_DATAEXFILTRATION_MODULE_NAME, fmt.Sprintf("Could not create Storage service in project %s", projectID)) return @@ -1705,6 +1705,6 @@ func (m *DataExfiltrationModule) writeFlatOutput(ctx context.Context, logger int ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), GCP_DATAEXFILTRATION_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/dataflow.go b/gcp/commands/dataflow.go index a2a5c31b..6d565371 100644 --- a/gcp/commands/dataflow.go +++ b/gcp/commands/dataflow.go @@ -103,7 +103,7 @@ func (m *DataflowModule) processProject(ctx context.Context, projectID string, l svc := dataflowservice.New() jobs, err := svc.ListJobs(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_DATAFLOW_MODULE_NAME, fmt.Sprintf("Could not list Dataflow jobs in project %s", projectID)) return diff --git a/gcp/commands/dataproc.go b/gcp/commands/dataproc.go index 85e6fbaa..320b527c 100644 --- a/gcp/commands/dataproc.go +++ b/gcp/commands/dataproc.go @@ -104,7 +104,7 @@ func (m *DataprocModule) processProject(ctx context.Context, projectID string, l clusters, err := svc.ListClusters(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_DATAPROC_MODULE_NAME, fmt.Sprintf("Could not list Dataproc clusters in project %s", projectID)) return diff --git a/gcp/commands/dns.go b/gcp/commands/dns.go index 2172faed..e9238902 100644 --- a/gcp/commands/dns.go +++ b/gcp/commands/dns.go @@ -177,7 +177,7 @@ func (m *DNSModule) processProject(ctx context.Context, projectID string, logger // Get zones zones, err := ds.Zones(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_DNS_MODULE_NAME, fmt.Sprintf("Could not enumerate DNS zones in project %s", projectID)) return @@ -204,7 +204,7 @@ func (m *DNSModule) processProject(ctx context.Context, projectID string, logger // Get records for each zone (outside of lock to avoid holding mutex across API call) records, err := ds.Records(projectID, zone.Name) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_DNS_MODULE_NAME, fmt.Sprintf("Could not enumerate DNS records in zone %s", zone.Name)) continue @@ -486,7 +486,7 @@ func (m *DNSModule) writeHierarchicalOutput(ctx context.Context, logger internal ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_DNS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -545,6 +545,6 @@ func (m *DNSModule) writeFlatOutput(ctx context.Context, logger internal.Logger) ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_DNS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/domainwidedelegation.go b/gcp/commands/domainwidedelegation.go index 818c737b..30f2fa97 100755 --- a/gcp/commands/domainwidedelegation.go +++ b/gcp/commands/domainwidedelegation.go @@ -144,7 +144,7 @@ func (m *DomainWideDelegationModule) processProject(ctx context.Context, project svc := domainwidedelegationservice.New() accounts, err := svc.GetDWDServiceAccounts(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_DOMAINWIDEDELEGATION_MODULE_NAME, fmt.Sprintf("Could not check DWD service accounts in project %s", projectID)) return @@ -753,6 +753,6 @@ func (m *DomainWideDelegationModule) writeFlatOutput(ctx context.Context, logger ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_DOMAINWIDEDELEGATION_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/endpoints.go b/gcp/commands/endpoints.go index 9ae3a094..461cc5c0 100755 --- a/gcp/commands/endpoints.go +++ b/gcp/commands/endpoints.go @@ -167,7 +167,7 @@ func (m *EndpointsModule) processProject(ctx context.Context, projectID string, computeService, err := compute.NewService(ctx) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, "endpoints", fmt.Sprintf("Could not create Compute service in project %s", projectID)) } else { @@ -1532,6 +1532,6 @@ func (m *EndpointsModule) writeFlatOutput(ctx context.Context, logger internal.L ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), "endpoints") - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/filestore.go b/gcp/commands/filestore.go index 374e67de..e28a0832 100644 --- a/gcp/commands/filestore.go +++ b/gcp/commands/filestore.go @@ -86,7 +86,7 @@ func (m *FilestoreModule) processProject(ctx context.Context, projectID string, svc := filestoreservice.New() instances, err := svc.ListInstances(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_FILESTORE_MODULE_NAME, fmt.Sprintf("Could not enumerate Filestore instances in project %s", projectID)) return diff --git a/gcp/commands/firewall.go b/gcp/commands/firewall.go index 10c541f4..3c6e7116 100644 --- a/gcp/commands/firewall.go +++ b/gcp/commands/firewall.go @@ -187,7 +187,7 @@ func (m *FirewallModule) processProject(ctx context.Context, projectID string, l var err error networks, err = ns.Networks(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_FIREWALL_MODULE_NAME, fmt.Sprintf("Could not enumerate networks in project %s", projectID)) } @@ -195,7 +195,7 @@ func (m *FirewallModule) processProject(ctx context.Context, projectID string, l // Get subnets subnets, err = ns.Subnets(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_FIREWALL_MODULE_NAME, fmt.Sprintf("Could not enumerate subnets in project %s", projectID)) } @@ -203,7 +203,7 @@ func (m *FirewallModule) processProject(ctx context.Context, projectID string, l // Get firewall rules rules, err = ns.FirewallRulesEnhanced(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_FIREWALL_MODULE_NAME, fmt.Sprintf("Could not enumerate firewall rules in project %s", projectID)) } @@ -530,7 +530,7 @@ func (m *FirewallModule) writeHierarchicalOutput(ctx context.Context, logger int ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_FIREWALL_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -576,7 +576,7 @@ func (m *FirewallModule) writeFlatOutput(ctx context.Context, logger internal.Lo ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_FIREWALL_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/functions.go b/gcp/commands/functions.go index dd317818..6eab01f7 100755 --- a/gcp/commands/functions.go +++ b/gcp/commands/functions.go @@ -148,7 +148,7 @@ func (m *FunctionsModule) processProject(ctx context.Context, projectID string, fs := FunctionsService.New() functions, err := fs.Functions(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_FUNCTIONS_MODULE_NAME, fmt.Sprintf("Could not enumerate functions in project %s", projectID)) return @@ -329,7 +329,7 @@ func (m *FunctionsModule) writeHierarchicalOutput(ctx context.Context, logger in ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_FUNCTIONS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -372,7 +372,7 @@ func (m *FunctionsModule) writeFlatOutput(ctx context.Context, logger internal.L ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_FUNCTIONS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/gke.go b/gcp/commands/gke.go index 5c0aea3a..b597b765 100755 --- a/gcp/commands/gke.go +++ b/gcp/commands/gke.go @@ -166,7 +166,7 @@ func (m *GKEModule) processProject(ctx context.Context, projectID string, logger gs := GKEService.New() clusters, nodePools, err := gs.Clusters(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_GKE_MODULE_NAME, fmt.Sprintf("Could not enumerate GKE clusters in project %s", projectID)) return @@ -295,7 +295,7 @@ func (m *GKEModule) writeHierarchicalOutput(ctx context.Context, logger internal ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_GKE_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -340,7 +340,7 @@ func (m *GKEModule) writeFlatOutput(ctx context.Context, logger internal.Logger) ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_GKE_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/iam.go b/gcp/commands/iam.go index fc168948..e9effd04 100755 --- a/gcp/commands/iam.go +++ b/gcp/commands/iam.go @@ -171,7 +171,7 @@ func (m *IAMModule) Execute(ctx context.Context, logger internal.Logger) { iamService := IAMService.New() iamData, err := iamService.CombinedIAMEnhanced(ctx, m.ProjectIDs, m.ProjectNames) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_IAM_MODULE_NAME, "Failed to enumerate IAM") return } @@ -964,7 +964,7 @@ func (m *IAMModule) writeHierarchicalOutput(ctx context.Context, logger internal err := internal.HandleHierarchicalOutputSmart("gcp", m.Format, m.Verbosity, m.WrapTable, pathBuilder, outputData) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_IAM_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -1041,7 +1041,7 @@ func (m *IAMModule) writeHierarchicalOutputTee(ctx context.Context, logger inter err := internal.HandleHierarchicalOutputTee(config) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing tee streaming output: %v", err), globals.GCP_IAM_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -1330,6 +1330,6 @@ func (m *IAMModule) writeFlatOutput(ctx context.Context, logger internal.Logger) ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_IAM_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/iap.go b/gcp/commands/iap.go index b9fe0229..12cba07c 100644 --- a/gcp/commands/iap.go +++ b/gcp/commands/iap.go @@ -99,7 +99,7 @@ func (m *IAPModule) processProject(ctx context.Context, projectID string, logger // Get tunnel destination groups groups, err := svc.ListTunnelDestGroups(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_IAP_MODULE_NAME, fmt.Sprintf("Could not enumerate IAP tunnel groups in project %s", projectID)) } else { diff --git a/gcp/commands/identityfederation.go b/gcp/commands/identityfederation.go index 24652071..43eef128 100644 --- a/gcp/commands/identityfederation.go +++ b/gcp/commands/identityfederation.go @@ -376,7 +376,7 @@ func (m *IdentityFederationModule) writeHierarchicalOutput(ctx context.Context, ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_IDENTITY_FEDERATION_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -420,7 +420,7 @@ func (m *IdentityFederationModule) writeFlatOutput(ctx context.Context, logger i ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_IDENTITY_FEDERATION_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/instances.go b/gcp/commands/instances.go index 7cd9d8de..307af392 100644 --- a/gcp/commands/instances.go +++ b/gcp/commands/instances.go @@ -142,7 +142,7 @@ func (m *InstancesModule) processProject(ctx context.Context, projectID string, ces := ComputeEngineService.New() instances, projectMeta, err := ces.InstancesWithMetadata(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_INSTANCES_MODULE_NAME, fmt.Sprintf("Could not enumerate instances in project %s", projectID)) return @@ -582,7 +582,7 @@ func (m *InstancesModule) writeHierarchicalOutput(ctx context.Context, logger in ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_INSTANCES_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -663,7 +663,7 @@ func (m *InstancesModule) writeFlatOutput(ctx context.Context, logger internal.L ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_INSTANCES_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/keys.go b/gcp/commands/keys.go index c234f276..729e9f21 100755 --- a/gcp/commands/keys.go +++ b/gcp/commands/keys.go @@ -523,7 +523,7 @@ func (m *KeysModule) writeHierarchicalOutput(ctx context.Context, logger interna ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_KEYS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -569,6 +569,6 @@ func (m *KeysModule) writeFlatOutput(ctx context.Context, logger internal.Logger ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_KEYS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/kms.go b/gcp/commands/kms.go index af23e7d5..03dd201b 100644 --- a/gcp/commands/kms.go +++ b/gcp/commands/kms.go @@ -170,7 +170,7 @@ func (m *KMSModule) processProject(ctx context.Context, projectID string, logger // Get key rings keyRings, err := ks.KeyRings(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_KMS_MODULE_NAME, fmt.Sprintf("Could not enumerate KMS key rings in project %s", projectID)) return @@ -179,7 +179,7 @@ func (m *KMSModule) processProject(ctx context.Context, projectID string, logger // Get crypto keys keys, err := ks.CryptoKeys(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_KMS_MODULE_NAME, fmt.Sprintf("Could not enumerate KMS keys in project %s", projectID)) } @@ -449,7 +449,7 @@ func (m *KMSModule) writeHierarchicalOutput(ctx context.Context, logger internal ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_KMS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -512,7 +512,7 @@ func (m *KMSModule) writeFlatOutput(ctx context.Context, logger internal.Logger) ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_KMS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/lateralmovement.go b/gcp/commands/lateralmovement.go index e59cb6b2..126186f6 100755 --- a/gcp/commands/lateralmovement.go +++ b/gcp/commands/lateralmovement.go @@ -399,7 +399,7 @@ func (m *LateralMovementModule) findImpersonationChains(ctx context.Context, pro // Get all service accounts (without keys - not needed for impersonation analysis) serviceAccounts, err := iamService.ServiceAccountsBasic(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_LATERALMOVEMENT_MODULE_NAME, fmt.Sprintf("Could not get service accounts in project %s", projectID)) return @@ -1009,6 +1009,6 @@ func (m *LateralMovementModule) writeFlatOutput(ctx context.Context, logger inte ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), GCP_LATERALMOVEMENT_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/loadbalancers.go b/gcp/commands/loadbalancers.go index 1de55423..285a8bd2 100755 --- a/gcp/commands/loadbalancers.go +++ b/gcp/commands/loadbalancers.go @@ -133,7 +133,7 @@ func (m *LoadBalancersModule) processProject(ctx context.Context, projectID stri // Get load balancers lbs, err := svc.ListLoadBalancers(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_LOADBALANCERS_MODULE_NAME, fmt.Sprintf("Could not list load balancers in project %s", projectID)) } else { @@ -148,7 +148,7 @@ func (m *LoadBalancersModule) processProject(ctx context.Context, projectID stri // Get SSL policies sslPolicies, err := svc.ListSSLPolicies(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_LOADBALANCERS_MODULE_NAME, fmt.Sprintf("Could not list SSL policies in project %s", projectID)) } else { @@ -160,7 +160,7 @@ func (m *LoadBalancersModule) processProject(ctx context.Context, projectID stri // Get backend services backends, err := svc.ListBackendServices(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_LOADBALANCERS_MODULE_NAME, fmt.Sprintf("Could not list backend services in project %s", projectID)) } else { diff --git a/gcp/commands/logenum.go b/gcp/commands/logenum.go index ff645138..7f30fffe 100644 --- a/gcp/commands/logenum.go +++ b/gcp/commands/logenum.go @@ -130,7 +130,7 @@ func (m *LogEnumModule) processProject(ctx context.Context, projectID string, lo entries, err := svc.EnumerateSensitiveLogs(projectID, m.Hours, m.MaxEntries, m.LogNameFilter) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_LOGGINGENUM_MODULE_NAME, fmt.Sprintf("Could not scan logs in project %s", projectID)) return diff --git a/gcp/commands/logging.go b/gcp/commands/logging.go index 38e61632..b4f6d1f5 100644 --- a/gcp/commands/logging.go +++ b/gcp/commands/logging.go @@ -175,7 +175,7 @@ func (m *LoggingModule) processProject(ctx context.Context, projectID string, lo // Get sinks sinks, err := ls.Sinks(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_LOGGING_MODULE_NAME, fmt.Sprintf("Could not enumerate logging sinks in project %s", projectID)) } else { @@ -185,7 +185,7 @@ func (m *LoggingModule) processProject(ctx context.Context, projectID string, lo // Get metrics metrics, err := ls.Metrics(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_LOGGING_MODULE_NAME, fmt.Sprintf("Could not enumerate log metrics in project %s", projectID)) } else { @@ -545,7 +545,7 @@ func (m *LoggingModule) writeHierarchicalOutput(ctx context.Context, logger inte ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_LOGGING_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -616,7 +616,7 @@ func (m *LoggingModule) writeFlatOutput(ctx context.Context, logger internal.Log ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_LOGGING_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/memorystore.go b/gcp/commands/memorystore.go index 3d748cec..b22abd85 100644 --- a/gcp/commands/memorystore.go +++ b/gcp/commands/memorystore.go @@ -95,7 +95,7 @@ func (m *MemorystoreModule) processProject(ctx context.Context, projectID string svc := memorystoreservice.New() instances, err := svc.ListRedisInstances(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_MEMORYSTORE_MODULE_NAME, fmt.Sprintf("Could not list Redis instances in project %s", projectID)) return diff --git a/gcp/commands/monitoringalerts.go b/gcp/commands/monitoringalerts.go index abd8f4c5..33b856d5 100644 --- a/gcp/commands/monitoringalerts.go +++ b/gcp/commands/monitoringalerts.go @@ -273,7 +273,7 @@ func (m *MonitoringAlertsModule) enumerateAlertPolicies(ctx context.Context, pro break } if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_MONITORINGALERTS_MODULE_NAME, fmt.Sprintf("Could not enumerate alert policies in project %s", projectID)) break @@ -347,7 +347,7 @@ func (m *MonitoringAlertsModule) enumerateNotificationChannels(ctx context.Conte break } if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_MONITORINGALERTS_MODULE_NAME, fmt.Sprintf("Could not enumerate notification channels in project %s", projectID)) break @@ -399,7 +399,7 @@ func (m *MonitoringAlertsModule) enumerateUptimeChecks(ctx context.Context, proj break } if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_MONITORINGALERTS_MODULE_NAME, fmt.Sprintf("Could not enumerate uptime checks in project %s", projectID)) break @@ -896,7 +896,7 @@ func (m *MonitoringAlertsModule) writeFlatOutput(ctx context.Context, logger int ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), GCP_MONITORINGALERTS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/networktopology.go b/gcp/commands/networktopology.go index 7b0bd7f7..355e879d 100644 --- a/gcp/commands/networktopology.go +++ b/gcp/commands/networktopology.go @@ -347,7 +347,7 @@ func (m *NetworkTopologyModule) enumerateNetworks(ctx context.Context, projectID }) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_NETWORKTOPOLOGY_MODULE_NAME, fmt.Sprintf("Could not list networks in project %s", projectID)) } @@ -400,7 +400,7 @@ func (m *NetworkTopologyModule) enumerateSubnets(ctx context.Context, projectID }) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_NETWORKTOPOLOGY_MODULE_NAME, fmt.Sprintf("Could not list subnets in project %s", projectID)) } @@ -474,7 +474,7 @@ func (m *NetworkTopologyModule) enumerateRoutes(ctx context.Context, projectID s }) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_NETWORKTOPOLOGY_MODULE_NAME, fmt.Sprintf("Could not list routes in project %s", projectID)) } @@ -524,7 +524,7 @@ func (m *NetworkTopologyModule) enumerateCloudNAT(ctx context.Context, projectID }) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_NETWORKTOPOLOGY_MODULE_NAME, fmt.Sprintf("Could not list Cloud NAT in project %s", projectID)) } @@ -561,7 +561,7 @@ func (m *NetworkTopologyModule) checkSharedVPCHost(ctx context.Context, projectI return nil }) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, GCP_NETWORKTOPOLOGY_MODULE_NAME, fmt.Sprintf("Could not list XPN resources in project %s", projectID)) } @@ -1751,6 +1751,6 @@ func (m *NetworkTopologyModule) writeFlatOutput(ctx context.Context, logger inte ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), GCP_NETWORKTOPOLOGY_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/notebooks.go b/gcp/commands/notebooks.go index 26076d0b..192b8e97 100644 --- a/gcp/commands/notebooks.go +++ b/gcp/commands/notebooks.go @@ -124,7 +124,7 @@ func (m *NotebooksModule) processProject(ctx context.Context, projectID string, // Get instances instances, err := svc.ListInstances(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_NOTEBOOKS_MODULE_NAME, fmt.Sprintf("Could not list notebook instances in project %s", projectID)) } else { diff --git a/gcp/commands/organizations.go b/gcp/commands/organizations.go index c8682be7..e59fa189 100755 --- a/gcp/commands/organizations.go +++ b/gcp/commands/organizations.go @@ -924,7 +924,7 @@ func (m *OrganizationsModule) writeHierarchicalOutput(ctx context.Context, logge err := internal.HandleHierarchicalOutputSmart("gcp", m.Format, m.Verbosity, m.WrapTable, pathBuilder, outputData) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_ORGANIZATIONS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -956,6 +956,6 @@ func (m *OrganizationsModule) writeFlatOutput(ctx context.Context, logger intern ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_ORGANIZATIONS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/orgpolicies.go b/gcp/commands/orgpolicies.go index 5c9275b2..0c3d18a4 100644 --- a/gcp/commands/orgpolicies.go +++ b/gcp/commands/orgpolicies.go @@ -109,7 +109,7 @@ func (m *OrgPoliciesModule) processProject(ctx context.Context, projectID string svc := orgpolicyservice.New() policies, err := svc.ListProjectPolicies(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_ORGPOLICIES_MODULE_NAME, fmt.Sprintf("Could not enumerate org policies in project %s", projectID)) return diff --git a/gcp/commands/permissions.go b/gcp/commands/permissions.go index e40a14b5..4be29a41 100755 --- a/gcp/commands/permissions.go +++ b/gcp/commands/permissions.go @@ -326,7 +326,7 @@ func (m *PermissionsModule) processProject(ctx context.Context, projectID string iamService := IAMService.New() entityPerms, groupInfos, err := iamService.GetAllEntityPermissionsWithGroupExpansion(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_PERMISSIONS_MODULE_NAME, fmt.Sprintf("Could not enumerate permissions in project %s", projectID)) return @@ -1119,7 +1119,7 @@ func (m *PermissionsModule) writeHierarchicalOutput(ctx context.Context, logger ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_PERMISSIONS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -1207,7 +1207,7 @@ func (m *PermissionsModule) writeHierarchicalOutputTee(ctx context.Context, logg err := internal.HandleHierarchicalOutputTee(config) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing tee streaming output: %v", err), globals.GCP_PERMISSIONS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -1280,7 +1280,7 @@ func (m *PermissionsModule) writeFlatOutput(ctx context.Context, logger internal ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_PERMISSIONS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/privateserviceconnect.go b/gcp/commands/privateserviceconnect.go index 9a2dca4c..fc9b95aa 100644 --- a/gcp/commands/privateserviceconnect.go +++ b/gcp/commands/privateserviceconnect.go @@ -167,7 +167,7 @@ func (m *PrivateServiceConnectModule) processProject(ctx context.Context, projec // Get PSC endpoints pscEndpoints, err := svc.GetPrivateServiceConnectEndpoints(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, "private-service-connect", fmt.Sprintf("Could not get PSC endpoints in project %s", projectID)) } @@ -175,7 +175,7 @@ func (m *PrivateServiceConnectModule) processProject(ctx context.Context, projec // Get private connections privateConns, err := svc.GetPrivateConnections(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, "private-service-connect", fmt.Sprintf("Could not get private connections in project %s", projectID)) } @@ -183,7 +183,7 @@ func (m *PrivateServiceConnectModule) processProject(ctx context.Context, projec // Get service attachments attachments, err := svc.GetServiceAttachments(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, "private-service-connect", fmt.Sprintf("Could not get service attachments in project %s", projectID)) } @@ -553,6 +553,6 @@ func (m *PrivateServiceConnectModule) writeFlatOutput(ctx context.Context, logge "project", m.ProjectIDs, scopeNames, m.Account, output) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), "private-service-connect") - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/publicaccess.go b/gcp/commands/publicaccess.go index 37d92a26..15d54fc5 100644 --- a/gcp/commands/publicaccess.go +++ b/gcp/commands/publicaccess.go @@ -1173,7 +1173,7 @@ func (m *PublicAccessModule) writeHierarchicalOutput(ctx context.Context, logger err := internal.HandleHierarchicalOutputSmart("gcp", m.Format, m.Verbosity, m.WrapTable, pathBuilder, outputData) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_PUBLICACCESS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -1259,7 +1259,7 @@ func (m *PublicAccessModule) writeFlatOutput(ctx context.Context, logger interna ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_PUBLICACCESS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/pubsub.go b/gcp/commands/pubsub.go index 3bdef915..35d44372 100644 --- a/gcp/commands/pubsub.go +++ b/gcp/commands/pubsub.go @@ -170,7 +170,7 @@ func (m *PubSubModule) processProject(ctx context.Context, projectID string, log // Get topics topicsResult, err := ps.Topics(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_PUBSUB_MODULE_NAME, fmt.Sprintf("Could not enumerate Pub/Sub topics in project %s", projectID)) } else { @@ -180,7 +180,7 @@ func (m *PubSubModule) processProject(ctx context.Context, projectID string, log // Get subscriptions subsResult, err := ps.Subscriptions(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_PUBSUB_MODULE_NAME, fmt.Sprintf("Could not enumerate Pub/Sub subscriptions in project %s", projectID)) } else { @@ -866,7 +866,7 @@ func (m *PubSubModule) writeHierarchicalOutput(ctx context.Context, logger inter ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_PUBSUB_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -915,7 +915,7 @@ func (m *PubSubModule) writeFlatOutput(ctx context.Context, logger internal.Logg ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_PUBSUB_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/resourceiam.go b/gcp/commands/resourceiam.go index fd4c27fd..9deef670 100644 --- a/gcp/commands/resourceiam.go +++ b/gcp/commands/resourceiam.go @@ -145,7 +145,7 @@ func (m *ResourceIAMModule) processProject(ctx context.Context, projectID string svc := resourceiamservice.New() bindings, err := svc.GetAllResourceIAM(ctx, projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_RESOURCEIAM_MODULE_NAME, fmt.Sprintf("Could not enumerate resource IAM in project %s", projectID)) return @@ -462,7 +462,7 @@ func (m *ResourceIAMModule) writeHierarchicalOutput(ctx context.Context, logger err := internal.HandleHierarchicalOutputSmart("gcp", m.Format, m.Verbosity, m.WrapTable, pathBuilder, outputData) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_RESOURCEIAM_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -597,6 +597,6 @@ func (m *ResourceIAMModule) writeFlatOutput(ctx context.Context, logger internal ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_RESOURCEIAM_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/scheduler.go b/gcp/commands/scheduler.go index 0d4c47f7..8d66af8b 100644 --- a/gcp/commands/scheduler.go +++ b/gcp/commands/scheduler.go @@ -142,7 +142,7 @@ func (m *SchedulerModule) processProject(ctx context.Context, projectID string, jobs, err := ss.Jobs(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_SCHEDULER_MODULE_NAME, fmt.Sprintf("Could not enumerate Scheduler jobs in project %s", projectID)) return @@ -346,7 +346,7 @@ func (m *SchedulerModule) writeHierarchicalOutput(ctx context.Context, logger in ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_SCHEDULER_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -396,7 +396,7 @@ func (m *SchedulerModule) writeFlatOutput(ctx context.Context, logger internal.L ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_SCHEDULER_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/secrets.go b/gcp/commands/secrets.go index 94aa29c9..d6759794 100644 --- a/gcp/commands/secrets.go +++ b/gcp/commands/secrets.go @@ -145,7 +145,7 @@ func (m *SecretsModule) processProject(ctx context.Context, projectID string, lo ss := SecretsService.New(m.client) secrets, err := ss.Secrets(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_SECRETS_MODULE_NAME, fmt.Sprintf("Could not enumerate secrets in project %s", projectID)) return @@ -326,7 +326,7 @@ func (m *SecretsModule) writeHierarchicalOutput(ctx context.Context, logger inte ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_SECRETS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -378,7 +378,7 @@ func (m *SecretsModule) writeFlatOutput(ctx context.Context, logger internal.Log ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_SECRETS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/securitycenter.go b/gcp/commands/securitycenter.go index fbd46b61..f6bfad10 100644 --- a/gcp/commands/securitycenter.go +++ b/gcp/commands/securitycenter.go @@ -237,7 +237,7 @@ func (m *SecurityCenterModule) processProject(ctx context.Context, projectID str break } if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() parsedErr := gcpinternal.ParseGCPError(err, "securitycenter.googleapis.com") gcpinternal.HandleGCPError(parsedErr, logger, GCP_SECURITYCENTER_MODULE_NAME, fmt.Sprintf("Project %s", projectID)) @@ -544,7 +544,7 @@ func (m *SecurityCenterModule) writeHierarchicalOutput(ctx context.Context, logg err := internal.HandleHierarchicalOutputSmart("gcp", m.Format, m.Verbosity, m.WrapTable, pathBuilder, outputData) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), GCP_SECURITYCENTER_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -680,6 +680,6 @@ func (m *SecurityCenterModule) writeFlatOutput(ctx context.Context, logger inter ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), GCP_SECURITYCENTER_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/serviceaccounts.go b/gcp/commands/serviceaccounts.go index 660c63d2..218fd910 100644 --- a/gcp/commands/serviceaccounts.go +++ b/gcp/commands/serviceaccounts.go @@ -164,7 +164,7 @@ func (m *ServiceAccountsModule) processProject(ctx context.Context, projectID st // Fallback to basic enumeration if impersonation analysis fails serviceAccounts, err = iamService.ServiceAccounts(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_SERVICEACCOUNTS_MODULE_NAME, fmt.Sprintf("Could not enumerate service accounts in project %s", projectID)) return @@ -677,7 +677,7 @@ func (m *ServiceAccountsModule) writeHierarchicalOutput(ctx context.Context, log ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_SERVICEACCOUNTS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -723,7 +723,7 @@ func (m *ServiceAccountsModule) writeFlatOutput(ctx context.Context, logger inte ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_SERVICEACCOUNTS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/serviceagents.go b/gcp/commands/serviceagents.go index b7b4788e..378e4294 100644 --- a/gcp/commands/serviceagents.go +++ b/gcp/commands/serviceagents.go @@ -140,7 +140,7 @@ func (m *ServiceAgentsModule) processProject(ctx context.Context, projectID stri svc := serviceagentsservice.New() agents, err := svc.GetServiceAgents(projectID, m.OrgCache) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_SERVICEAGENTS_MODULE_NAME, fmt.Sprintf("Could not get service agents in project %s", projectID)) return @@ -292,7 +292,7 @@ func (m *ServiceAgentsModule) writeHierarchicalOutput(ctx context.Context, logge ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_SERVICEAGENTS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -345,7 +345,7 @@ func (m *ServiceAgentsModule) writeFlatOutput(ctx context.Context, logger intern ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_SERVICEAGENTS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/sourcerepos.go b/gcp/commands/sourcerepos.go index 4e7f74d5..afa6e936 100644 --- a/gcp/commands/sourcerepos.go +++ b/gcp/commands/sourcerepos.go @@ -118,7 +118,7 @@ func (m *SourceReposModule) processProject(ctx context.Context, projectID string svc := sourcereposservice.New() repos, err := svc.ListRepos(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_SOURCEREPOS_MODULE_NAME, fmt.Sprintf("Could not list repos in project %s", projectID)) return @@ -263,7 +263,7 @@ func (m *SourceReposModule) writeHierarchicalOutput(ctx context.Context, logger ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_SOURCEREPOS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -325,7 +325,7 @@ func (m *SourceReposModule) writeFlatOutput(ctx context.Context, logger internal ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_SOURCEREPOS_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/spanner.go b/gcp/commands/spanner.go index 79e9f1c0..3a8aaa42 100644 --- a/gcp/commands/spanner.go +++ b/gcp/commands/spanner.go @@ -98,7 +98,7 @@ func (m *SpannerModule) processProject(ctx context.Context, projectID string, lo svc := spannerservice.New() result, err := svc.ListInstancesAndDatabases(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_SPANNER_MODULE_NAME, fmt.Sprintf("Could not list Spanner instances in project %s", projectID)) return @@ -459,6 +459,6 @@ func (m *SpannerModule) writeFlatOutput(ctx context.Context, logger internal.Log "project", m.ProjectIDs, scopeNames, m.Account, output) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_SPANNER_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/spannerenum.go b/gcp/commands/spannerenum.go index edab5eef..b8103a2d 100644 --- a/gcp/commands/spannerenum.go +++ b/gcp/commands/spannerenum.go @@ -103,7 +103,7 @@ func (m *SpannerEnumModule) processProject(ctx context.Context, projectID string resources, err := svc.EnumerateSensitiveResources(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_SPANNERENUM_MODULE_NAME, fmt.Sprintf("Could not scan Spanner in project %s", projectID)) return diff --git a/gcp/commands/vpcnetworks.go b/gcp/commands/vpcnetworks.go index 1f2f7a23..f045a83e 100644 --- a/gcp/commands/vpcnetworks.go +++ b/gcp/commands/vpcnetworks.go @@ -135,7 +135,7 @@ func (m *VPCNetworksModule) processProject(ctx context.Context, projectID string // Get networks networks, err := svc.ListVPCNetworks(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_VPCNETWORKS_MODULE_NAME, fmt.Sprintf("Could not list VPC networks in project %s", projectID)) } else { @@ -150,7 +150,7 @@ func (m *VPCNetworksModule) processProject(ctx context.Context, projectID string // Get subnets subnets, err := svc.ListSubnets(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_VPCNETWORKS_MODULE_NAME, fmt.Sprintf("Could not list subnets in project %s", projectID)) } else { @@ -165,7 +165,7 @@ func (m *VPCNetworksModule) processProject(ctx context.Context, projectID string // Get peerings peerings, err := svc.ListVPCPeerings(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_VPCNETWORKS_MODULE_NAME, fmt.Sprintf("Could not list VPC peerings in project %s", projectID)) } else { @@ -180,7 +180,7 @@ func (m *VPCNetworksModule) processProject(ctx context.Context, projectID string // Get routes routes, err := svc.ListRoutes(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_VPCNETWORKS_MODULE_NAME, fmt.Sprintf("Could not list routes in project %s", projectID)) } else { diff --git a/gcp/commands/vpcsc.go b/gcp/commands/vpcsc.go index 92ff8ef0..bba708af 100644 --- a/gcp/commands/vpcsc.go +++ b/gcp/commands/vpcsc.go @@ -113,7 +113,7 @@ func (m *VPCSCModule) Execute(ctx context.Context, logger internal.Logger) { // List access policies policies, err := svc.ListAccessPolicies(m.OrgID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_VPCSC_MODULE_NAME, fmt.Sprintf("Could not list access policies for organization %s", m.OrgID)) return @@ -433,7 +433,7 @@ func (m *VPCSCModule) writeHierarchicalOutput(ctx context.Context, logger intern err := internal.HandleHierarchicalOutputSmart("gcp", m.Format, m.Verbosity, m.WrapTable, pathBuilder, outputData) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_VPCSC_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -446,7 +446,7 @@ func (m *VPCSCModule) writeFlatOutput(ctx context.Context, logger internal.Logge err := internal.HandleOutputSmart("gcp", m.Format, m.OutputDirectory, m.Verbosity, m.WrapTable, "org", []string{m.OrgID}, []string{m.OrgID}, m.Account, output) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_VPCSC_MODULE_NAME, "Could not write output") } diff --git a/gcp/commands/whoami.go b/gcp/commands/whoami.go index 8e101cde..933753ff 100644 --- a/gcp/commands/whoami.go +++ b/gcp/commands/whoami.go @@ -296,7 +296,7 @@ func (m *WhoAmIModule) getOrganizationContext(ctx context.Context, logger intern // Create resource manager clients crmService, err := cloudresourcemanager.NewService(ctx) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_WHOAMI_MODULE_NAME, "Could not create Cloud Resource Manager client") return @@ -305,7 +305,7 @@ func (m *WhoAmIModule) getOrganizationContext(ctx context.Context, logger intern // Create v3 client for fetching folder details crmv3Service, err := crmv3.NewService(ctx) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_WHOAMI_MODULE_NAME, "Could not create Cloud Resource Manager v3 client") // Continue without v3, we just won't get display names for folders @@ -326,7 +326,7 @@ func (m *WhoAmIModule) getOrganizationContext(ctx context.Context, logger intern // Get ancestry resp, err := crmService.Projects.GetAncestry(projectID, &cloudresourcemanager.GetAncestryRequest{}).Do() if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_WHOAMI_MODULE_NAME, fmt.Sprintf("Could not get ancestry for project %s", projectID)) continue @@ -437,7 +437,7 @@ func (m *WhoAmIModule) getGroupMemberships(ctx context.Context, logger internal. ciService, err := cloudidentity.NewService(ctx) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() parsedErr := gcpinternal.ParseGCPError(err, "cloudidentity.googleapis.com") gcpinternal.HandleGCPError(parsedErr, logger, globals.GCP_WHOAMI_MODULE_NAME, "Could not create Cloud Identity client") @@ -451,7 +451,7 @@ func (m *WhoAmIModule) getGroupMemberships(ctx context.Context, logger internal. query := fmt.Sprintf("member_key_id == '%s'", m.Identity.Email) resp, err := ciService.Groups.Memberships.SearchDirectGroups("groups/-").Query(query).Do() if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() parsedErr := gcpinternal.ParseGCPError(err, "cloudidentity.googleapis.com") gcpinternal.HandleGCPError(parsedErr, logger, globals.GCP_WHOAMI_MODULE_NAME, "Could not fetch group memberships") @@ -565,7 +565,7 @@ func (m *WhoAmIModule) getRoleBindings(ctx context.Context, logger internal.Logg // Use PrincipalsWithRolesEnhanced which includes inheritance principals, err := iamService.PrincipalsWithRolesEnhanced(projectID) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_WHOAMI_MODULE_NAME, fmt.Sprintf("Could not get IAM bindings for project %s", projectID)) continue @@ -2030,7 +2030,7 @@ func (m *WhoAmIModule) writeHierarchicalOutput(ctx context.Context, logger inter err := internal.HandleHierarchicalOutputSmart("gcp", m.Format, m.Verbosity, m.WrapTable, pathBuilder, outputData) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_WHOAMI_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -2058,7 +2058,7 @@ func (m *WhoAmIModule) writeFlatOutput(ctx context.Context, logger internal.Logg ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing output: %v", err), globals.GCP_WHOAMI_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } diff --git a/gcp/commands/workloadidentity.go b/gcp/commands/workloadidentity.go index fd63d2b3..909048f8 100644 --- a/gcp/commands/workloadidentity.go +++ b/gcp/commands/workloadidentity.go @@ -446,7 +446,7 @@ func (m *WorkloadIdentityModule) writeHierarchicalOutput(ctx context.Context, lo ) if err != nil { logger.ErrorM(fmt.Sprintf("Error writing hierarchical output: %v", err), globals.GCP_WORKLOAD_IDENTITY_MODULE_NAME) - m.CommandCounter.Error++ + m.CommandCounter.IncrError() } } @@ -487,7 +487,7 @@ func (m *WorkloadIdentityModule) writeFlatOutput(ctx context.Context, logger int output, ) if err != nil { - m.CommandCounter.Error++ + m.CommandCounter.IncrError() gcpinternal.HandleGCPError(err, logger, globals.GCP_WORKLOAD_IDENTITY_MODULE_NAME, "Could not write output") } diff --git a/internal/aws.go b/internal/aws.go index b745a6c6..c240504e 100644 --- a/internal/aws.go +++ b/internal/aws.go @@ -11,6 +11,7 @@ import ( "path/filepath" "regexp" "strings" + "sync/atomic" "time" "github.com/aws/aws-sdk-go-v2/aws" @@ -460,22 +461,39 @@ func BuildAWSPath(Caller sts.GetCallerIdentityOutput) string { // this is all for the spinner and command counter const clearln = "\r\x1b[2K" +// CommandCounter tracks per-module task progress. All fields are accessed +// atomically through the Incr/Decr/Load methods so worker goroutines and the +// spinner goroutine can update and read counts safely. type CommandCounter struct { - Total int - Pending int - Complete int - Error int - Executing int + Total int64 + Pending int64 + Complete int64 + Error int64 + Executing int64 } +func (c *CommandCounter) IncrTotal() { atomic.AddInt64(&c.Total, 1) } +func (c *CommandCounter) IncrPending() { atomic.AddInt64(&c.Pending, 1) } +func (c *CommandCounter) IncrComplete() { atomic.AddInt64(&c.Complete, 1) } +func (c *CommandCounter) IncrError() { atomic.AddInt64(&c.Error, 1) } +func (c *CommandCounter) IncrExecuting() { atomic.AddInt64(&c.Executing, 1) } + +func (c *CommandCounter) DecrPending() { atomic.AddInt64(&c.Pending, -1) } +func (c *CommandCounter) DecrExecuting() { atomic.AddInt64(&c.Executing, -1) } + +func (c *CommandCounter) LoadTotal() int64 { return atomic.LoadInt64(&c.Total) } +func (c *CommandCounter) LoadComplete() int64 { return atomic.LoadInt64(&c.Complete) } +func (c *CommandCounter) LoadError() int64 { return atomic.LoadInt64(&c.Error) } + func SpinUntil(callingModuleName string, counter *CommandCounter, done chan bool, spinType string) { defer close(done) for { select { case <-time.After(1 * time.Second): - fmt.Printf(clearln+"[%s] Status: %d/%d %s complete (%d errors -- For details check %s)", cyan(callingModuleName), counter.Complete, counter.Total, spinType, counter.Error, fmt.Sprintf("%s/cloudfox-error.log", ptr.ToString(GetLogDirPath()))) + fmt.Printf(clearln+"[%s] Status: %d/%d %s complete (%d errors -- For details check %s)", cyan(callingModuleName), counter.LoadComplete(), counter.LoadTotal(), spinType, counter.LoadError(), fmt.Sprintf("%s/cloudfox-error.log", ptr.ToString(GetLogDirPath()))) case <-done: - fmt.Printf(clearln+"[%s] Status: %d/%d %s complete (%d errors -- For details check %s)\n", cyan(callingModuleName), counter.Complete, counter.Complete, spinType, counter.Error, fmt.Sprintf("%s/cloudfox-error.log", ptr.ToString(GetLogDirPath()))) + complete := counter.LoadComplete() + fmt.Printf(clearln+"[%s] Status: %d/%d %s complete (%d errors -- For details check %s)\n", cyan(callingModuleName), complete, complete, spinType, counter.LoadError(), fmt.Sprintf("%s/cloudfox-error.log", ptr.ToString(GetLogDirPath()))) done <- true return } diff --git a/internal/gcp/base.go b/internal/gcp/base.go index 2c6a8dc2..4a20f1fa 100644 --- a/internal/gcp/base.go +++ b/internal/gcp/base.go @@ -428,14 +428,14 @@ func (b *BaseGCPModule) RunProjectEnumeration( // Process each project with goroutines for _, projectID := range projectIDs { - b.CommandCounter.Total++ - b.CommandCounter.Pending++ + b.CommandCounter.IncrTotal() + b.CommandCounter.IncrPending() wg.Add(1) go func(project string) { defer func() { - b.CommandCounter.Executing-- - b.CommandCounter.Complete++ + b.CommandCounter.DecrExecuting() + b.CommandCounter.IncrComplete() wg.Done() }() @@ -443,8 +443,8 @@ func (b *BaseGCPModule) RunProjectEnumeration( semaphore <- struct{}{} defer func() { <-semaphore }() - b.CommandCounter.Pending-- - b.CommandCounter.Executing++ + b.CommandCounter.DecrPending() + b.CommandCounter.IncrExecuting() // Call the module-specific processor processor(ctx, project, logger) From 81be56e006a9bd31eaea8bcbeddead7a5e751409 Mon Sep 17 00:00:00 2001 From: jbarciabf Date: Tue, 26 May 2026 10:42:29 -0400 Subject: [PATCH 3/3] Bump version to 2.0.5 --- globals/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/globals/utils.go b/globals/utils.go index 4b512f22..8b9d2c2f 100644 --- a/globals/utils.go +++ b/globals/utils.go @@ -4,4 +4,4 @@ const CLOUDFOX_USER_AGENT = "cloudfox" const CLOUDFOX_LOG_FILE_DIR_NAME = ".cloudfox" const CLOUDFOX_BASE_DIRECTORY = "cloudfox-output" const LOOT_DIRECTORY_NAME = "loot" -const CLOUDFOX_VERSION = "2.0.4" +const CLOUDFOX_VERSION = "2.0.5"