• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

elastic / cloudbeat / 16936699327

13 Aug 2025 12:06PM UTC coverage: 76.273% (+0.1%) from 76.127%
16936699327

Pull #3515

github

moukoublen
aws org flow: filter only the valid accounts
Pull Request #3515: Status Handler; Expose aws permission issues to user using beats status.

122 of 141 new or added lines in 22 files covered. (86.52%)

67 existing lines in 14 files now uncovered.

9557 of 12530 relevant lines covered (76.27%)

16.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.58
/internal/inventory/awsfetcher/fetcher_lambda.go
1
// Licensed to Elasticsearch B.V. under one or more contributor
2
// license agreements. See the NOTICE file distributed with
3
// this work for additional information regarding copyright
4
// ownership. Elasticsearch B.V. licenses this file to you under
5
// the Apache License, Version 2.0 (the "License"); you may
6
// not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
//
9
//     http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17

18
package awsfetcher
19

20
import (
21
        "context"
22

23
        "github.com/elastic/cloudbeat/internal/dataprovider/providers/cloud"
24
        "github.com/elastic/cloudbeat/internal/infra/clog"
25
        "github.com/elastic/cloudbeat/internal/inventory"
26
        "github.com/elastic/cloudbeat/internal/resources/providers/awslib"
27
)
28

29
type lambdaFetcher struct {
30
        logger      *clog.Logger
31
        provider    lambdaProvider
32
        AccountId   string
33
        AccountName string
34
}
35

36
type (
37
        lambdaDescribeFunc func(context.Context) ([]awslib.AwsResource, error)
38
        lambdaProvider     interface {
39
                ListAliases(context.Context, string, string) ([]awslib.AwsResource, error)
40
                ListEventSourceMappings(context.Context) ([]awslib.AwsResource, error)
41
                ListFunctions(context.Context) ([]awslib.AwsResource, error)
42
                ListLayers(context.Context) ([]awslib.AwsResource, error)
43
        }
44
)
45

46
func newLambdaFetcher(logger *clog.Logger, identity *cloud.Identity, provider lambdaProvider) inventory.AssetFetcher {
1✔
47
        return &lambdaFetcher{
1✔
48
                logger:      logger,
1✔
49
                provider:    provider,
1✔
50
                AccountId:   identity.Account,
1✔
51
                AccountName: identity.AccountAlias,
1✔
52
        }
1✔
53
}
1✔
54

55
func (s *lambdaFetcher) Fetch(ctx context.Context, assetChannel chan<- inventory.AssetEvent) {
1✔
56
        resourcesToFetch := []struct {
1✔
57
                name           string
1✔
58
                function       lambdaDescribeFunc
1✔
59
                classification inventory.AssetClassification
1✔
60
        }{
1✔
61
                {"Lambda Event Source Mappings", s.provider.ListEventSourceMappings, inventory.AssetClassificationAwsLambdaEventSourceMapping},
1✔
62
                {"Lambda Functions", s.provider.ListFunctions, inventory.AssetClassificationAwsLambdaFunction},
1✔
63
                {"Lambda Layers", s.provider.ListLayers, inventory.AssetClassificationAwsLambdaLayer},
1✔
64
        }
1✔
65
        for _, r := range resourcesToFetch {
4✔
66
                s.fetch(ctx, r.name, r.function, r.classification, assetChannel)
3✔
67
        }
3✔
68
}
69

70
func (s *lambdaFetcher) fetch(ctx context.Context, resourceName string, function lambdaDescribeFunc, classification inventory.AssetClassification, assetChannel chan<- inventory.AssetEvent) {
3✔
71
        s.logger.Infof("Fetching %s", resourceName)
3✔
72
        defer s.logger.Infof("Fetching %s - Finished", resourceName)
3✔
73

3✔
74
        awsResources, err := function(ctx)
3✔
75
        if err != nil {
3✔
UNCOV
76
                s.logger.Errorf("Could not fetch %s: %v", resourceName, err)
×
UNCOV
77
                return
×
UNCOV
78
        }
×
79

80
        for _, item := range awsResources {
4✔
81
                id := item.GetResourceArn()
1✔
82
                if id == "" { // e.g. LambdaEventSourceMappings
1✔
UNCOV
83
                        id = item.GetResourceName()
×
UNCOV
84
                }
×
85
                assetChannel <- inventory.NewAssetEvent(
1✔
86
                        classification,
1✔
87
                        id,
1✔
88
                        item.GetResourceName(),
1✔
89
                        inventory.WithRawAsset(item),
1✔
90
                        inventory.WithCloud(inventory.Cloud{
1✔
91
                                Provider:    inventory.AwsCloudProvider,
1✔
92
                                Region:      item.GetRegion(),
1✔
93
                                AccountID:   s.AccountId,
1✔
94
                                AccountName: s.AccountName,
1✔
95
                                ServiceName: "AWS Lambda",
1✔
96
                        }),
1✔
97
                )
1✔
98
        }
99
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc