This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from rebuy-de/cloud-1047-nuke-cloudwatch
CLOUD-1047: Delete CloudWatchEvents.
- Loading branch information
Showing
4 changed files
with
113 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package resources | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/service/cloudwatchevents" | ||
) | ||
|
||
func (n *CloudWatchEventsNuke) ListRules() ([]Resource, error) { | ||
resp, err := n.Service.ListRules(nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
resources := make([]Resource, 0) | ||
for _, rule := range resp.Rules { | ||
resources = append(resources, &CloudWatchEventsRule{ | ||
svc: n.Service, | ||
name: rule.Name, | ||
}) | ||
|
||
} | ||
return resources, nil | ||
} | ||
|
||
type CloudWatchEventsRule struct { | ||
svc *cloudwatchevents.CloudWatchEvents | ||
name *string | ||
} | ||
|
||
func (rule *CloudWatchEventsRule) Remove() error { | ||
_, err := rule.svc.DeleteRule(&cloudwatchevents.DeleteRuleInput{ | ||
Name: rule.name, | ||
}) | ||
return err | ||
} | ||
|
||
func (rule *CloudWatchEventsRule) String() string { | ||
return fmt.Sprintf("Rule: %s", *rule.name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package resources | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/service/cloudwatchevents" | ||
) | ||
|
||
func (n *CloudWatchEventsNuke) ListTargets() ([]Resource, error) { | ||
resp, err := n.Service.ListRules(nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
resources := make([]Resource, 0) | ||
for _, rule := range resp.Rules { | ||
targetResp, err := n.Service.ListTargetsByRule(&cloudwatchevents.ListTargetsByRuleInput{ | ||
Rule: rule.Name, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for _, target := range targetResp.Targets { | ||
resources = append(resources, &CloudWatchEventsTarget{ | ||
svc: n.Service, | ||
ruleName: rule.Name, | ||
targetId: target.Id, | ||
}) | ||
} | ||
} | ||
return resources, nil | ||
} | ||
|
||
type CloudWatchEventsTarget struct { | ||
svc *cloudwatchevents.CloudWatchEvents | ||
targetId *string | ||
ruleName *string | ||
} | ||
|
||
func (target *CloudWatchEventsTarget) Remove() error { | ||
ids := []*string{target.targetId} | ||
_, err := target.svc.RemoveTargets(&cloudwatchevents.RemoveTargetsInput{ | ||
Ids: ids, | ||
Rule: target.ruleName, | ||
}) | ||
return err | ||
} | ||
|
||
func (target *CloudWatchEventsTarget) String() string { | ||
return fmt.Sprintf("Rule: %s Target ID: %s", *target.ruleName, *target.targetId) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters