Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit eab5b39

Browse files
authored
Add GuardDuty detectors (#625)
* Add GuardDuty detectors * Include review suggestions
1 parent 8bfe0af commit eab5b39

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

resources/guardduty.go

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package resources
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/aws/session"
5+
"github.com/aws/aws-sdk-go/service/guardduty"
6+
"github.com/rebuy-de/aws-nuke/pkg/types"
7+
)
8+
9+
type GuardDutyDetector struct {
10+
svc *guardduty.GuardDuty
11+
id *string
12+
}
13+
14+
func init() {
15+
register("GuardDutyDetector", ListGuardDutyDetectors)
16+
}
17+
18+
func ListGuardDutyDetectors(sess *session.Session) ([]Resource, error) {
19+
svc := guardduty.New(sess)
20+
21+
detectors := make([]Resource, 0)
22+
23+
params := &guardduty.ListDetectorsInput{}
24+
25+
err := svc.ListDetectorsPages(params, func(page *guardduty.ListDetectorsOutput, lastPage bool) bool {
26+
for _, out := range page.DetectorIds {
27+
detectors = append(detectors, &GuardDutyDetector{
28+
svc: svc,
29+
id: out,
30+
})
31+
}
32+
return true
33+
})
34+
if err != nil {
35+
return nil, err
36+
}
37+
return detectors, nil
38+
}
39+
40+
func (detector *GuardDutyDetector) Remove() error {
41+
_, err := detector.svc.DeleteDetector(&guardduty.DeleteDetectorInput{
42+
DetectorId: detector.id,
43+
})
44+
return err
45+
}
46+
47+
func (detector *GuardDutyDetector) Properties() types.Properties {
48+
properties := types.NewProperties()
49+
properties.Set("DetectorID", detector.id)
50+
return properties
51+
}
52+
53+
func (detector *GuardDutyDetector) String() string {
54+
return *detector.id
55+
}

0 commit comments

Comments
 (0)