2015-10-02 04:54:35 -05:00
|
|
|
package cloudwatch
|
|
|
|
|
|
|
|
import (
|
2023-05-24 03:19:34 -05:00
|
|
|
"context"
|
2022-02-16 13:28:26 -06:00
|
|
|
"encoding/json"
|
2017-09-13 05:35:05 -05:00
|
|
|
"errors"
|
2018-01-19 02:24:44 -06:00
|
|
|
"fmt"
|
2022-02-16 13:28:26 -06:00
|
|
|
"net/url"
|
2017-09-19 04:55:11 -05:00
|
|
|
"reflect"
|
2017-09-13 05:35:05 -05:00
|
|
|
"sort"
|
|
|
|
"strings"
|
2016-01-14 04:02:04 -06:00
|
|
|
"time"
|
2015-10-02 04:54:35 -05:00
|
|
|
|
2017-09-13 05:35:05 -05:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
2017-09-19 04:09:57 -05:00
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
2019-01-09 15:06:27 -06:00
|
|
|
"github.com/aws/aws-sdk-go/service/resourcegroupstaggingapi"
|
2021-03-23 10:32:12 -05:00
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
2022-10-18 02:23:47 -05:00
|
|
|
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/constants"
|
2015-10-02 04:54:35 -05:00
|
|
|
)
|
|
|
|
|
2017-09-09 14:24:39 -05:00
|
|
|
type suggestData struct {
|
2022-02-16 13:28:26 -06:00
|
|
|
Text string `json:"text"`
|
|
|
|
Value string `json:"value"`
|
|
|
|
Label string `json:"label,omitempty"`
|
2017-09-09 14:24:39 -05:00
|
|
|
}
|
|
|
|
|
2018-01-24 08:41:42 -06:00
|
|
|
func parseMultiSelectValue(input string) []string {
|
|
|
|
trimmedInput := strings.TrimSpace(input)
|
|
|
|
if strings.HasPrefix(trimmedInput, "{") {
|
|
|
|
values := strings.Split(strings.TrimRight(strings.TrimLeft(trimmedInput, "{"), "}"), ",")
|
2020-05-18 05:25:58 -05:00
|
|
|
trimmedValues := make([]string, len(values))
|
2018-01-24 08:41:42 -06:00
|
|
|
for i, v := range values {
|
2020-05-18 05:25:58 -05:00
|
|
|
trimmedValues[i] = strings.TrimSpace(v)
|
2018-01-24 08:41:42 -06:00
|
|
|
}
|
2020-05-18 05:25:58 -05:00
|
|
|
return trimmedValues
|
2018-01-24 08:41:42 -06:00
|
|
|
}
|
2020-05-18 05:25:58 -05:00
|
|
|
|
Outdent code after if block that ends with return (golint)
This commit fixes the following golint warnings:
pkg/bus/bus.go:64:9: if block ends with a return statement, so drop this else and outdent its block
pkg/bus/bus.go:84:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:137:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:177:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:183:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:199:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:208:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/components/dynmap/dynmap.go:236:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:242:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:257:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:263:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:278:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:284:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:299:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:331:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:350:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:356:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:366:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:390:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:396:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:405:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:427:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:433:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:442:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:459:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:465:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:474:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:491:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:497:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:506:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:523:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:529:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:538:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:555:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:561:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:570:12: if block ends with a return statement, so drop this else and outdent its block
pkg/login/ldap.go:55:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/login/ldap_test.go:372:10: if block ends with a return statement, so drop this else and outdent its block
pkg/middleware/middleware_test.go:213:12: if block ends with a return statement, so drop this else and outdent its block
pkg/plugins/dashboard_importer.go:153:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:39:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:121:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:210:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:235:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/eval_context.go:111:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:92:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:98:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:122:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:108:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:118:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:121:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifiers/telegram.go:94:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/annotation.go:34:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/annotation.go:99:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/dashboard_test.go:107:13: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/plugin_setting.go:78:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/preferences.go:91:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/user.go:50:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/migrator/migrator.go:106:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/migrator/postgres_dialect.go:48:10: if block ends with a return statement, so drop this else and outdent its block
pkg/tsdb/time_range.go:59:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/time_range.go:67:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/cloudwatch/metric_find_query.go:225:9: if block ends with a return statement, so drop this else and outdent its block
pkg/util/filepath.go:68:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
2018-04-27 15:42:49 -05:00
|
|
|
return []string{trimmedInput}
|
2018-01-24 08:41:42 -06:00
|
|
|
}
|
|
|
|
|
2020-05-18 05:25:58 -05:00
|
|
|
// Whenever this list is updated, the frontend list should also be updated.
|
2017-09-09 14:24:39 -05:00
|
|
|
// Please update the region list in public/app/plugins/datasource/cloudwatch/partials/config.html
|
2023-05-24 03:19:34 -05:00
|
|
|
func (e *cloudWatchExecutor) handleGetRegions(ctx context.Context, pluginCtx backend.PluginContext, parameters url.Values) ([]suggestData, error) {
|
|
|
|
instance, err := e.getInstance(ctx, pluginCtx)
|
2021-03-23 10:32:12 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-10-25 02:52:12 -05:00
|
|
|
profile := instance.Settings.Profile
|
2023-04-11 12:55:57 -05:00
|
|
|
if cache, ok := e.regionCache.Load(profile); ok {
|
2018-10-24 23:23:26 -05:00
|
|
|
if cache2, ok2 := cache.([]suggestData); ok2 {
|
|
|
|
return cache2, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-24 03:19:34 -05:00
|
|
|
client, err := e.getEC2Client(ctx, pluginCtx, defaultRegion)
|
2018-06-19 03:06:56 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-04-11 12:55:57 -05:00
|
|
|
regions := constants.Regions()
|
|
|
|
ec2Regions, err := client.DescribeRegions(&ec2.DescribeRegionsInput{})
|
2018-06-19 03:06:56 -05:00
|
|
|
if err != nil {
|
2018-10-15 22:06:57 -05:00
|
|
|
// ignore error for backward compatibility
|
2022-11-02 09:14:02 -05:00
|
|
|
logger.Error("Failed to get regions", "error", err)
|
2018-10-15 22:06:57 -05:00
|
|
|
} else {
|
2023-04-11 12:55:57 -05:00
|
|
|
mergeEC2RegionsAndConstantRegions(regions, ec2Regions.Regions)
|
2018-06-19 03:06:56 -05:00
|
|
|
}
|
|
|
|
|
2017-09-09 14:24:39 -05:00
|
|
|
result := make([]suggestData, 0)
|
2023-04-11 12:55:57 -05:00
|
|
|
for region := range regions {
|
2022-02-16 13:28:26 -06:00
|
|
|
result = append(result, suggestData{Text: region, Value: region, Label: region})
|
2016-01-14 04:02:04 -06:00
|
|
|
}
|
2023-04-11 12:55:57 -05:00
|
|
|
sort.Slice(result, func(i, j int) bool {
|
|
|
|
return result[i].Text < result[j].Text
|
|
|
|
})
|
|
|
|
e.regionCache.Store(profile, result)
|
2016-01-14 04:02:04 -06:00
|
|
|
|
2017-09-09 14:24:39 -05:00
|
|
|
return result, nil
|
2016-01-14 04:02:04 -06:00
|
|
|
}
|
|
|
|
|
2023-04-11 12:55:57 -05:00
|
|
|
func mergeEC2RegionsAndConstantRegions(regions map[string]struct{}, ec2Regions []*ec2.Region) {
|
|
|
|
for _, region := range ec2Regions {
|
|
|
|
if _, ok := regions[*region.RegionName]; !ok {
|
|
|
|
regions[*region.RegionName] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-24 03:19:34 -05:00
|
|
|
func (e *cloudWatchExecutor) handleGetEbsVolumeIds(ctx context.Context, pluginCtx backend.PluginContext, parameters url.Values) ([]suggestData, error) {
|
2022-02-16 13:28:26 -06:00
|
|
|
region := parameters.Get("region")
|
|
|
|
instanceId := parameters.Get("instanceId")
|
2017-09-19 04:09:57 -05:00
|
|
|
|
2018-01-24 08:41:42 -06:00
|
|
|
instanceIds := aws.StringSlice(parseMultiSelectValue(instanceId))
|
2023-05-24 03:19:34 -05:00
|
|
|
instances, err := e.ec2DescribeInstances(ctx, pluginCtx, region, nil, instanceIds)
|
2017-09-19 04:09:57 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
result := make([]suggestData, 0)
|
2018-01-24 08:41:42 -06:00
|
|
|
for _, reservation := range instances.Reservations {
|
|
|
|
for _, instance := range reservation.Instances {
|
|
|
|
for _, mapping := range instance.BlockDeviceMappings {
|
2022-02-16 13:28:26 -06:00
|
|
|
result = append(result, suggestData{Text: *mapping.Ebs.VolumeId, Value: *mapping.Ebs.VolumeId, Label: *mapping.Ebs.VolumeId})
|
2018-01-24 08:41:42 -06:00
|
|
|
}
|
|
|
|
}
|
2017-09-19 04:09:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2023-05-24 03:19:34 -05:00
|
|
|
func (e *cloudWatchExecutor) handleGetEc2InstanceAttribute(ctx context.Context, pluginCtx backend.PluginContext, parameters url.Values) ([]suggestData, error) {
|
2022-02-16 13:28:26 -06:00
|
|
|
region := parameters.Get("region")
|
|
|
|
attributeName := parameters.Get("attributeName")
|
|
|
|
filterJson := parameters.Get("filters")
|
|
|
|
|
|
|
|
filterMap := map[string]interface{}{}
|
|
|
|
err := json.Unmarshal([]byte(filterJson), &filterMap)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error unmarshaling filter: %v", err)
|
|
|
|
}
|
2017-09-19 04:55:11 -05:00
|
|
|
|
|
|
|
var filters []*ec2.Filter
|
2022-02-16 13:28:26 -06:00
|
|
|
for k, v := range filterMap {
|
2017-11-13 06:07:46 -06:00
|
|
|
if vv, ok := v.([]interface{}); ok {
|
2020-07-14 01:23:23 -05:00
|
|
|
var values []*string
|
2017-09-19 04:55:11 -05:00
|
|
|
for _, vvv := range vv {
|
2017-11-13 06:07:46 -06:00
|
|
|
if vvvv, ok := vvv.(string); ok {
|
2020-07-14 01:23:23 -05:00
|
|
|
values = append(values, &vvvv)
|
2017-11-13 06:07:46 -06:00
|
|
|
}
|
2017-09-19 04:55:11 -05:00
|
|
|
}
|
|
|
|
filters = append(filters, &ec2.Filter{
|
|
|
|
Name: aws.String(k),
|
2020-07-14 01:23:23 -05:00
|
|
|
Values: values,
|
2017-09-19 04:55:11 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-24 03:19:34 -05:00
|
|
|
instances, err := e.ec2DescribeInstances(ctx, pluginCtx, region, filters, nil)
|
2017-09-19 04:55:11 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
result := make([]suggestData, 0)
|
|
|
|
dupCheck := make(map[string]bool)
|
2017-09-26 10:00:38 -05:00
|
|
|
for _, reservation := range instances.Reservations {
|
|
|
|
for _, instance := range reservation.Instances {
|
|
|
|
tags := make(map[string]string)
|
|
|
|
for _, tag := range instance.Tags {
|
|
|
|
tags[*tag.Key] = *tag.Value
|
|
|
|
}
|
2017-09-19 04:55:11 -05:00
|
|
|
|
2017-09-26 10:00:38 -05:00
|
|
|
var data string
|
|
|
|
if strings.Index(attributeName, "Tags.") == 0 {
|
|
|
|
tagName := attributeName[5:]
|
|
|
|
data = tags[tagName]
|
|
|
|
} else {
|
|
|
|
attributePath := strings.Split(attributeName, ".")
|
|
|
|
v := reflect.ValueOf(instance)
|
|
|
|
for _, key := range attributePath {
|
|
|
|
if v.Kind() == reflect.Ptr {
|
|
|
|
v = v.Elem()
|
|
|
|
}
|
|
|
|
if v.Kind() != reflect.Struct {
|
|
|
|
return nil, errors.New("invalid attribute path")
|
|
|
|
}
|
|
|
|
v = v.FieldByName(key)
|
2018-09-11 05:53:39 -05:00
|
|
|
if !v.IsValid() {
|
|
|
|
return nil, errors.New("invalid attribute path")
|
|
|
|
}
|
2017-09-19 04:55:11 -05:00
|
|
|
}
|
2017-09-26 10:00:38 -05:00
|
|
|
if attr, ok := v.Interface().(*string); ok {
|
|
|
|
data = *attr
|
2019-11-21 02:20:44 -06:00
|
|
|
} else if attr, ok := v.Interface().(*time.Time); ok {
|
2020-06-29 07:08:32 -05:00
|
|
|
data = attr.String()
|
2017-09-26 10:00:38 -05:00
|
|
|
} else {
|
2017-09-19 04:55:11 -05:00
|
|
|
return nil, errors.New("invalid attribute path")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-26 10:00:38 -05:00
|
|
|
if _, exists := dupCheck[data]; exists {
|
|
|
|
continue
|
|
|
|
}
|
2020-05-18 05:25:58 -05:00
|
|
|
|
2017-09-26 10:00:38 -05:00
|
|
|
dupCheck[data] = true
|
2022-02-16 13:28:26 -06:00
|
|
|
result = append(result, suggestData{Text: data, Value: data, Label: data})
|
2017-09-19 04:55:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(result, func(i, j int) bool {
|
|
|
|
return result[i].Text < result[j].Text
|
|
|
|
})
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2023-05-24 03:19:34 -05:00
|
|
|
func (e *cloudWatchExecutor) handleGetResourceArns(ctx context.Context, pluginCtx backend.PluginContext, parameters url.Values) ([]suggestData, error) {
|
2022-02-16 13:28:26 -06:00
|
|
|
region := parameters.Get("region")
|
|
|
|
resourceType := parameters.Get("resourceType")
|
|
|
|
tagsJson := parameters.Get("tags")
|
|
|
|
|
|
|
|
tagsMap := map[string]interface{}{}
|
|
|
|
err := json.Unmarshal([]byte(tagsJson), &tagsMap)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error unmarshaling filter: %v", err)
|
|
|
|
}
|
2019-01-09 15:06:27 -06:00
|
|
|
|
|
|
|
var filters []*resourcegroupstaggingapi.TagFilter
|
2022-02-16 13:28:26 -06:00
|
|
|
for k, v := range tagsMap {
|
2019-01-09 15:06:27 -06:00
|
|
|
if vv, ok := v.([]interface{}); ok {
|
2020-07-14 01:23:23 -05:00
|
|
|
var values []*string
|
2019-01-09 15:06:27 -06:00
|
|
|
for _, vvv := range vv {
|
|
|
|
if vvvv, ok := vvv.(string); ok {
|
2020-07-14 01:23:23 -05:00
|
|
|
values = append(values, &vvvv)
|
2019-01-09 15:06:27 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
filters = append(filters, &resourcegroupstaggingapi.TagFilter{
|
|
|
|
Key: aws.String(k),
|
2020-07-14 01:23:23 -05:00
|
|
|
Values: values,
|
2019-01-09 15:06:27 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var resourceTypes []*string
|
|
|
|
resourceTypes = append(resourceTypes, &resourceType)
|
|
|
|
|
2023-05-24 03:19:34 -05:00
|
|
|
resources, err := e.resourceGroupsGetResources(ctx, pluginCtx, region, filters, resourceTypes)
|
2019-01-09 15:06:27 -06:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
result := make([]suggestData, 0)
|
|
|
|
for _, resource := range resources.ResourceTagMappingList {
|
|
|
|
data := *resource.ResourceARN
|
2022-02-16 13:28:26 -06:00
|
|
|
result = append(result, suggestData{Text: data, Value: data, Label: data})
|
2019-01-09 15:06:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2023-05-24 03:19:34 -05:00
|
|
|
func (e *cloudWatchExecutor) ec2DescribeInstances(ctx context.Context, pluginCtx backend.PluginContext, region string, filters []*ec2.Filter, instanceIds []*string) (*ec2.DescribeInstancesOutput, error) {
|
2017-09-19 04:09:57 -05:00
|
|
|
params := &ec2.DescribeInstancesInput{
|
|
|
|
Filters: filters,
|
|
|
|
InstanceIds: instanceIds,
|
|
|
|
}
|
|
|
|
|
2023-05-24 03:19:34 -05:00
|
|
|
client, err := e.getEC2Client(ctx, pluginCtx, region)
|
2020-07-23 11:52:22 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-09-19 04:09:57 -05:00
|
|
|
var resp ec2.DescribeInstancesOutput
|
2020-07-23 11:52:22 -05:00
|
|
|
if err := client.DescribeInstancesPages(params, func(page *ec2.DescribeInstancesOutput, lastPage bool) bool {
|
2020-07-14 01:23:23 -05:00
|
|
|
resp.Reservations = append(resp.Reservations, page.Reservations...)
|
|
|
|
return !lastPage
|
|
|
|
}); err != nil {
|
|
|
|
return nil, fmt.Errorf("failed to call ec2:DescribeInstances, %w", err)
|
2017-09-19 04:09:57 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return &resp, nil
|
|
|
|
}
|
|
|
|
|
2023-05-24 03:19:34 -05:00
|
|
|
func (e *cloudWatchExecutor) resourceGroupsGetResources(ctx context.Context, pluginCtx backend.PluginContext, region string, filters []*resourcegroupstaggingapi.TagFilter,
|
2022-02-10 10:15:11 -06:00
|
|
|
resourceTypes []*string) (*resourcegroupstaggingapi.GetResourcesOutput, error) {
|
2019-01-09 15:06:27 -06:00
|
|
|
params := &resourcegroupstaggingapi.GetResourcesInput{
|
|
|
|
ResourceTypeFilters: resourceTypes,
|
|
|
|
TagFilters: filters,
|
|
|
|
}
|
|
|
|
|
2023-05-24 03:19:34 -05:00
|
|
|
client, err := e.getRGTAClient(ctx, pluginCtx, region)
|
2020-07-23 11:52:22 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-01-09 15:06:27 -06:00
|
|
|
var resp resourcegroupstaggingapi.GetResourcesOutput
|
2020-07-23 11:52:22 -05:00
|
|
|
if err := client.GetResourcesPages(params,
|
2019-01-09 15:06:27 -06:00
|
|
|
func(page *resourcegroupstaggingapi.GetResourcesOutput, lastPage bool) bool {
|
2020-07-14 01:23:23 -05:00
|
|
|
resp.ResourceTagMappingList = append(resp.ResourceTagMappingList, page.ResourceTagMappingList...)
|
2019-01-09 15:06:27 -06:00
|
|
|
return !lastPage
|
2020-07-14 01:23:23 -05:00
|
|
|
}); err != nil {
|
2020-08-26 04:01:50 -05:00
|
|
|
return nil, fmt.Errorf("failed to call tag:GetResources, %w", err)
|
2019-01-09 15:06:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return &resp, nil
|
|
|
|
}
|