|
| 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