Skip to content

Commit 36a47fe

Browse files
Update comprehend detection filters (#1090)
* Updating detection filters. Adding `Completed` to the job status types that are ignored upon cleanup. * Adding filters for key-phrases and dominant-language Adding filters for key-phrases and dominant-language * Adding pii entitites and sentiment detection job support. * Adding events detection job support.
1 parent 0dd135f commit 36a47fe

7 files changed

+232
-6
lines changed

resources/comprehend_dominant_language_detection_job.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ func ListComprehendDominantLanguageDetectionJobs(sess *session.Session) ([]Resou
2222
return nil, err
2323
}
2424
for _, dominantLanguageDetectionJob := range resp.DominantLanguageDetectionJobPropertiesList {
25+
switch *dominantLanguageDetectionJob.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+
}
2530
resources = append(resources, &ComprehendDominantLanguageDetectionJob{
2631
svc: svc,
2732
dominantLanguageDetectionJob: dominantLanguageDetectionJob,

resources/comprehend_entities_detection_job.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ func ListComprehendEntitiesDetectionJobs(sess *session.Session) ([]Resource, err
2222
return nil, err
2323
}
2424
for _, entitiesDetectionJob := range resp.EntitiesDetectionJobPropertiesList {
25-
if *entitiesDetectionJob.JobStatus == "STOPPED" ||
26-
*entitiesDetectionJob.JobStatus == "FAILED" {
27-
// if the job has already been stopped, do not try to delete it again
25+
switch *entitiesDetectionJob.JobStatus {
26+
case "STOPPED", "FAILED", "COMPLETED":
27+
// if the job has already been stopped, failed, or completed; do not try to stop it again
2828
continue
2929
}
3030
resources = append(resources, &ComprehendEntitiesDetectionJob{
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+
}

resources/comprehend_key_phrases_detection_job.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ func ListComprehendKeyPhrasesDetectionJobs(sess *session.Session) ([]Resource, e
2222
return nil, err
2323
}
2424
for _, keyPhrasesDetectionJob := range resp.KeyPhrasesDetectionJobPropertiesList {
25+
switch *keyPhrasesDetectionJob.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+
}
2530
resources = append(resources, &ComprehendKeyPhrasesDetectionJob{
2631
svc: svc,
2732
keyPhrasesDetectionJob: keyPhrasesDetectionJob,
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("ComprehendPiiEntititesDetectionJob", ListComprehendPiiEntitiesDetectionJobs)
11+
}
12+
13+
func ListComprehendPiiEntitiesDetectionJobs(sess *session.Session) ([]Resource, error) {
14+
svc := comprehend.New(sess)
15+
16+
params := &comprehend.ListPiiEntitiesDetectionJobsInput{}
17+
resources := make([]Resource, 0)
18+
19+
for {
20+
resp, err := svc.ListPiiEntitiesDetectionJobs(params)
21+
if err != nil {
22+
return nil, err
23+
}
24+
for _, piiEntititesDetectionJob := range resp.PiiEntitiesDetectionJobPropertiesList {
25+
switch *piiEntititesDetectionJob.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, &ComprehendPiiEntitiesDetectionJob{
31+
svc: svc,
32+
piiEntititesDetectionJob: piiEntititesDetectionJob,
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 ComprehendPiiEntitiesDetectionJob struct {
47+
svc *comprehend.Comprehend
48+
piiEntititesDetectionJob *comprehend.PiiEntitiesDetectionJobProperties
49+
}
50+
51+
func (ce *ComprehendPiiEntitiesDetectionJob) Remove() error {
52+
_, err := ce.svc.StopPiiEntitiesDetectionJob(&comprehend.StopPiiEntitiesDetectionJobInput{
53+
JobId: ce.piiEntititesDetectionJob.JobId,
54+
})
55+
return err
56+
}
57+
58+
func (ce *ComprehendPiiEntitiesDetectionJob) Properties() types.Properties {
59+
properties := types.NewProperties()
60+
properties.Set("JobName", ce.piiEntititesDetectionJob.JobName)
61+
properties.Set("JobId", ce.piiEntititesDetectionJob.JobId)
62+
63+
return properties
64+
}
65+
66+
func (ce *ComprehendPiiEntitiesDetectionJob) String() string {
67+
if ce.piiEntititesDetectionJob.JobName == nil {
68+
return "Unnamed job"
69+
} else {
70+
return *ce.piiEntititesDetectionJob.JobName
71+
}
72+
}

resources/comprehend_sentiment_detection_job.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ func ListComprehendSentimentDetectionJobs(sess *session.Session) ([]Resource, er
2222
return nil, err
2323
}
2424
for _, sentimentDetectionJob := range resp.SentimentDetectionJobPropertiesList {
25-
if *sentimentDetectionJob.JobStatus == "STOPPED" ||
26-
*sentimentDetectionJob.JobStatus == "FAILED" {
27-
// if the job has already been stopped, do not try to delete it again
25+
switch *sentimentDetectionJob.JobStatus {
26+
case "STOPPED", "FAILED", "COMPLETED":
27+
// if the job has already been stopped, failed, or completed; do not try to stop it again
2828
continue
2929
}
3030
resources = append(resources, &ComprehendSentimentDetectionJob{
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("ComprehendTargetedSentimentDetectionJob", ListComprehendTargetedSentimentDetectionJobs)
11+
}
12+
13+
func ListComprehendTargetedSentimentDetectionJobs(sess *session.Session) ([]Resource, error) {
14+
svc := comprehend.New(sess)
15+
16+
params := &comprehend.ListTargetedSentimentDetectionJobsInput{}
17+
resources := make([]Resource, 0)
18+
19+
for {
20+
resp, err := svc.ListTargetedSentimentDetectionJobs(params)
21+
if err != nil {
22+
return nil, err
23+
}
24+
for _, targetedSentimentDetectionJob := range resp.TargetedSentimentDetectionJobPropertiesList {
25+
switch *targetedSentimentDetectionJob.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, &ComprehendTargetedSentimentDetectionJob{
31+
svc: svc,
32+
targetedSentimentDetectionJob: targetedSentimentDetectionJob,
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 ComprehendTargetedSentimentDetectionJob struct {
47+
svc *comprehend.Comprehend
48+
targetedSentimentDetectionJob *comprehend.TargetedSentimentDetectionJobProperties
49+
}
50+
51+
func (ce *ComprehendTargetedSentimentDetectionJob) Remove() error {
52+
_, err := ce.svc.StopTargetedSentimentDetectionJob(&comprehend.StopTargetedSentimentDetectionJobInput{
53+
JobId: ce.targetedSentimentDetectionJob.JobId,
54+
})
55+
return err
56+
}
57+
58+
func (ce *ComprehendTargetedSentimentDetectionJob) Properties() types.Properties {
59+
properties := types.NewProperties()
60+
properties.Set("JobName", ce.targetedSentimentDetectionJob.JobName)
61+
properties.Set("JobId", ce.targetedSentimentDetectionJob.JobId)
62+
63+
return properties
64+
}
65+
66+
func (ce *ComprehendTargetedSentimentDetectionJob) String() string {
67+
if ce.targetedSentimentDetectionJob.JobName == nil {
68+
return "Unnamed job"
69+
} else {
70+
return *ce.targetedSentimentDetectionJob.JobName
71+
}
72+
}

0 commit comments

Comments
 (0)