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

Commit 72da7c9

Browse files
committed
Add GuardDuty detectors
1 parent b5ccc00 commit 72da7c9

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

resources/guardduty.go

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

0 commit comments

Comments
 (0)