|
| 1 | +package resources |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/aws/aws-sdk-go/aws" |
| 5 | + "github.com/aws/aws-sdk-go/aws/session" |
| 6 | + "github.com/aws/aws-sdk-go/service/cloudwatch" |
| 7 | + "github.com/rebuy-de/aws-nuke/v2/pkg/types" |
| 8 | +) |
| 9 | + |
| 10 | +type CloudWatchInsightRule struct { |
| 11 | + svc *cloudwatch.CloudWatch |
| 12 | + name *string |
| 13 | +} |
| 14 | + |
| 15 | +func init() { |
| 16 | + register("CloudWatchInsightRule", ListCloudWatchInsightRules) |
| 17 | +} |
| 18 | + |
| 19 | +func ListCloudWatchInsightRules(sess *session.Session) ([]Resource, error) { |
| 20 | + svc := cloudwatch.New(sess) |
| 21 | + resources := []Resource{} |
| 22 | + |
| 23 | + params := &cloudwatch.DescribeInsightRulesInput{ |
| 24 | + MaxResults: aws.Int64(25), |
| 25 | + } |
| 26 | + |
| 27 | + for { |
| 28 | + output, err := svc.DescribeInsightRules(params) |
| 29 | + if err != nil { |
| 30 | + return nil, err |
| 31 | + } |
| 32 | + |
| 33 | + for _, rules := range output.InsightRules { |
| 34 | + resources = append(resources, &CloudWatchInsightRule{ |
| 35 | + svc: svc, |
| 36 | + name: rules.Name, |
| 37 | + }) |
| 38 | + } |
| 39 | + |
| 40 | + if output.NextToken == nil { |
| 41 | + break |
| 42 | + } |
| 43 | + |
| 44 | + params.NextToken = output.NextToken |
| 45 | + } |
| 46 | + |
| 47 | + return resources, nil |
| 48 | +} |
| 49 | + |
| 50 | +func (f *CloudWatchInsightRule) Remove() error { |
| 51 | + _, err := f.svc.DeleteInsightRules(&cloudwatch.DeleteInsightRulesInput{ |
| 52 | + RuleNames: []*string{f.name}, |
| 53 | + }) |
| 54 | + |
| 55 | + return err |
| 56 | +} |
| 57 | + |
| 58 | +func (f *CloudWatchInsightRule) Properties() types.Properties { |
| 59 | + properties := types.NewProperties() |
| 60 | + properties.Set("Name", f.name) |
| 61 | + return properties |
| 62 | +} |
| 63 | + |
| 64 | +func (f *CloudWatchInsightRule) String() string { |
| 65 | + return *f.name |
| 66 | +} |
0 commit comments