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

elastic / cloudbeat / 17606600399

10 Sep 2025 07:32AM UTC coverage: 76.0% (-0.06%) from 76.062%
17606600399

Pull #3561

github

amirbenun
Revert "cloud_connectors_federated_identity"

This reverts commit df92f7759.
Pull Request #3561: Azure cloud connector credentials

15 of 38 new or added lines in 2 files covered. (39.47%)

200 existing lines in 32 files now uncovered.

9560 of 12579 relevant lines covered (76.0%)

16.59 hits per line

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

92.75
/internal/inventory/awsfetcher/fetcher_ec2_instance.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/ec2"
27
        "github.com/elastic/cloudbeat/internal/resources/utils/pointers"
28
)
29

30
type ec2InstanceFetcher struct {
31
        logger      *clog.Logger
32
        provider    ec2InstancesProvider
33
        AccountId   string
34
        AccountName string
35
}
36

37
type ec2InstancesProvider interface {
38
        DescribeInstances(ctx context.Context) ([]*ec2.Ec2Instance, error)
39
}
40

41
func newEc2InstancesFetcher(logger *clog.Logger, identity *cloud.Identity, provider ec2InstancesProvider) inventory.AssetFetcher {
42
        return &ec2InstanceFetcher{
43
                logger:      logger,
44
                provider:    provider,
1✔
45
                AccountId:   identity.Account,
1✔
46
                AccountName: identity.AccountAlias,
1✔
47
        }
1✔
48
}
1✔
49

1✔
50
func (e *ec2InstanceFetcher) Fetch(ctx context.Context, assetChannel chan<- inventory.AssetEvent) {
1✔
51
        e.logger.Info("Fetching EC2 Instances")
1✔
52
        defer e.logger.Info("Fetching EC2 Instances - Finished")
1✔
53

54
        instances, err := e.provider.DescribeInstances(ctx)
1✔
55
        if err != nil {
1✔
56
                e.logger.Errorf("Could not list ec2 instances: %v", err)
1✔
57
                return
1✔
58
        }
1✔
59

1✔
UNCOV
60
        for _, i := range instances {
×
UNCOV
61
                if i == nil {
×
UNCOV
62
                        continue
×
UNCOV
63
                }
×
64

65
                iamFetcher := inventory.EmptyEnricher()
4✔
66
                if i.IamInstanceProfile != nil {
4✔
67
                        iamFetcher = inventory.WithUser(inventory.User{
1✔
68
                                ID: pointers.Deref(i.IamInstanceProfile.Arn),
69
                        })
70
                }
2✔
71

3✔
72
                assetChannel <- inventory.NewAssetEvent(
1✔
73
                        inventory.AssetClassificationAwsEc2Instance,
1✔
74
                        i.GetResourceArn(),
1✔
75
                        pointers.Deref(i.PrivateDnsName),
1✔
76

77
                        inventory.WithRelatedAssetIds([]string{pointers.Deref(i.InstanceId)}),
2✔
78
                        inventory.WithRawAsset(i),
2✔
79
                        inventory.WithLabels(e.getTags(i)),
2✔
80
                        inventory.WithCloud(inventory.Cloud{
2✔
81
                                Provider:         inventory.AwsCloudProvider,
2✔
82
                                Region:           i.Region,
2✔
83
                                AvailabilityZone: e.getAvailabilityZone(i),
2✔
84
                                AccountID:        e.AccountId,
2✔
85
                                AccountName:      e.AccountName,
2✔
86
                                InstanceID:       pointers.Deref(i.InstanceId),
2✔
87
                                InstanceName:     i.GetResourceName(),
2✔
88
                                MachineType:      string(i.InstanceType),
2✔
89
                                ServiceName:      "AWS EC2",
2✔
90
                        }),
2✔
91
                        inventory.WithHost(inventory.Host{
2✔
92
                                ID:           pointers.Deref(i.InstanceId),
2✔
93
                                Name:         pointers.Deref(i.PrivateDnsName),
2✔
94
                                Architecture: string(i.Architecture),
2✔
95
                                Type:         string(i.InstanceType),
2✔
96
                                IP:           pointers.Deref(i.PublicIpAddress),
2✔
97
                                MacAddress:   i.GetResourceMacAddresses(),
2✔
98
                        }),
2✔
99
                        iamFetcher,
2✔
100
                )
2✔
101
        }
2✔
102
}
2✔
103

2✔
104
func (e *ec2InstanceFetcher) getTags(instance *ec2.Ec2Instance) map[string]string {
2✔
105
        tags := make(map[string]string, len(instance.Tags))
2✔
106
        for _, t := range instance.Tags {
107
                if t.Key == nil {
108
                        continue
109
                }
2✔
110

2✔
111
                tags[*t.Key] = pointers.Deref(t.Value)
4✔
112
        }
2✔
UNCOV
113
        return tags
×
114
}
115

116
func (e *ec2InstanceFetcher) getAvailabilityZone(instance *ec2.Ec2Instance) string {
2✔
117
        if instance.Placement == nil {
118
                return ""
2✔
119
        }
120

121
        return pointers.Deref(instance.Placement.AvailabilityZone)
2✔
122
}
3✔
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