Skip to content

Commit f30fbd6

Browse files
Adding events detection job support.
1 parent 33fa1cf commit f30fbd6

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package resources
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/aws/session"
5+
"github.com/aws/aws-sdk-go/service/comprehend"
6+
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
7+
)
8+
9+
func init() {
10+
register("ComprehendEventsDetectionJob", ListComprehendEventsDetectionJobs)
11+
}
12+
13+
func ListComprehendEventsDetectionJobs(sess *session.Session) ([]Resource, error) {
14+
svc := comprehend.New(sess)
15+
16+
params := &comprehend.ListEventsDetectionJobsInput{}
17+
resources := make([]Resource, 0)
18+
19+
for {
20+
resp, err := svc.ListEventsDetectionJobs(params)
21+
if err != nil {
22+
return nil, err
23+
}
24+
for _, eventsDetectionJob := range resp.EventsDetectionJobPropertiesList {
25+
switch *eventsDetectionJob.JobStatus {
26+
case "STOPPED", "FAILED", "COMPLETED":
27+
// if the job has already been stopped, failed, or completed; do not try to stop it again
28+
continue
29+
}
30+
resources = append(resources, &ComprehendEventsDetectionJob{
31+
svc: svc,
32+
eventsDetectionJob: eventsDetectionJob,
33+
})
34+
}
35+
36+
if resp.NextToken == nil {
37+
break
38+
}
39+
40+
params.NextToken = resp.NextToken
41+
}
42+
43+
return resources, nil
44+
}
45+
46+
type ComprehendEventsDetectionJob struct {
47+
svc *comprehend.Comprehend
48+
eventsDetectionJob *comprehend.EventsDetectionJobProperties
49+
}
50+
51+
func (ce *ComprehendEventsDetectionJob) Remove() error {
52+
_, err := ce.svc.StopEventsDetectionJob(&comprehend.StopEventsDetectionJobInput{
53+
JobId: ce.eventsDetectionJob.JobId,
54+
})
55+
return err
56+
}
57+
58+
func (ce *ComprehendEventsDetectionJob) Properties() types.Properties {
59+
properties := types.NewProperties()
60+
properties.Set("JobName", ce.eventsDetectionJob.JobName)
61+
properties.Set("JobId", ce.eventsDetectionJob.JobId)
62+
63+
return properties
64+
}
65+
66+
func (ce *ComprehendEventsDetectionJob) String() string {
67+
if ce.eventsDetectionJob.JobName == nil {
68+
return "Unnamed job"
69+
} else {
70+
return *ce.eventsDetectionJob.JobName
71+
}
72+
}

0 commit comments

Comments
 (0)