-
Notifications
You must be signed in to change notification settings - Fork 0
/
autogen_load_balancers_fetch.go
67 lines (53 loc) · 1.96 KB
/
autogen_load_balancers_fetch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//AUTOGENERATED CODE DO NOT EDIT
// This file is automatically generated from /internal/codegen/templates/aws_fetching_file.tmpl
package elasticloadbalancing
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing"
"github.com/google/uuid"
"github.com/jinzhu/copier"
"github.com/sheacloud/cloud-inventory/pkg/aws"
"github.com/sheacloud/cloud-inventory/pkg/meta"
)
func FetchLoadBalancers(ctx context.Context, params *aws.AwsFetchInput) ([]*LoadBalancer, *aws.AwsFetchOutputMetadata) {
fetchingErrors := []error{}
var fetchedResources int
var failedResources int
inventoryResults := &meta.InventoryResults{
Cloud: "aws",
Service: "elasticloadbalancing",
Resource: "load_balancers",
AccountId: params.AccountId,
Region: params.Region,
ReportTime: params.ReportTime,
}
resources := []*LoadBalancer{}
awsClient := params.RegionalClients[params.Region]
client := awsClient.ElasticLoadBalancing()
paginator := elasticloadbalancing.NewDescribeLoadBalancersPaginator(client, &elasticloadbalancing.DescribeLoadBalancersInput{})
for paginator.HasMorePages() {
output, err := paginator.NextPage(ctx)
if err != nil {
fetchingErrors = append(fetchingErrors, fmt.Errorf("error calling DescribeLoadBalancers in %s/%s: %w", params.AccountId, params.Region, err))
break
}
for _, object := range output.LoadBalancerDescriptions {
model := new(LoadBalancer)
copier.CopyWithOption(&model, &object, aws.CopyOption)
model.AccountId = params.AccountId
model.Region = params.Region
model.ReportTime = params.ReportTime
model.InventoryUUID = uuid.New().String()
resources = append(resources, model)
fetchedResources++
}
}
inventoryResults.FetchedResources = fetchedResources
inventoryResults.FailedResources = failedResources
inventoryResults.HadErrors = len(fetchingErrors) > 0
return resources, &aws.AwsFetchOutputMetadata{
FetchingErrors: fetchingErrors,
InventoryResults: inventoryResults,
}
}