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

Commit

Permalink
Update comprehend detection filters (#1090)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
swhite-oreilly authored Aug 29, 2023
1 parent 0dd135f commit 36a47fe
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 6 deletions.
5 changes: 5 additions & 0 deletions resources/comprehend_dominant_language_detection_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func ListComprehendDominantLanguageDetectionJobs(sess *session.Session) ([]Resou
return nil, err
}
for _, dominantLanguageDetectionJob := range resp.DominantLanguageDetectionJobPropertiesList {
switch *dominantLanguageDetectionJob.JobStatus {
case "STOPPED", "FAILED", "COMPLETED":
// if the job has already been stopped, failed, or completed; do not try to stop it again
continue
}
resources = append(resources, &ComprehendDominantLanguageDetectionJob{
svc: svc,
dominantLanguageDetectionJob: dominantLanguageDetectionJob,
Expand Down
6 changes: 3 additions & 3 deletions resources/comprehend_entities_detection_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ func ListComprehendEntitiesDetectionJobs(sess *session.Session) ([]Resource, err
return nil, err
}
for _, entitiesDetectionJob := range resp.EntitiesDetectionJobPropertiesList {
if *entitiesDetectionJob.JobStatus == "STOPPED" ||
*entitiesDetectionJob.JobStatus == "FAILED" {
// if the job has already been stopped, do not try to delete it again
switch *entitiesDetectionJob.JobStatus {
case "STOPPED", "FAILED", "COMPLETED":
// if the job has already been stopped, failed, or completed; do not try to stop it again
continue
}
resources = append(resources, &ComprehendEntitiesDetectionJob{
Expand Down
72 changes: 72 additions & 0 deletions resources/comprehend_events_detection_job.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/comprehend"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

func init() {
register("ComprehendEventsDetectionJob", ListComprehendEventsDetectionJobs)
}

func ListComprehendEventsDetectionJobs(sess *session.Session) ([]Resource, error) {
svc := comprehend.New(sess)

params := &comprehend.ListEventsDetectionJobsInput{}
resources := make([]Resource, 0)

for {
resp, err := svc.ListEventsDetectionJobs(params)
if err != nil {
return nil, err
}
for _, eventsDetectionJob := range resp.EventsDetectionJobPropertiesList {
switch *eventsDetectionJob.JobStatus {
case "STOPPED", "FAILED", "COMPLETED":
// if the job has already been stopped, failed, or completed; do not try to stop it again
continue
}
resources = append(resources, &ComprehendEventsDetectionJob{
svc: svc,
eventsDetectionJob: eventsDetectionJob,
})
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

type ComprehendEventsDetectionJob struct {
svc *comprehend.Comprehend
eventsDetectionJob *comprehend.EventsDetectionJobProperties
}

func (ce *ComprehendEventsDetectionJob) Remove() error {
_, err := ce.svc.StopEventsDetectionJob(&comprehend.StopEventsDetectionJobInput{
JobId: ce.eventsDetectionJob.JobId,
})
return err
}

func (ce *ComprehendEventsDetectionJob) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("JobName", ce.eventsDetectionJob.JobName)
properties.Set("JobId", ce.eventsDetectionJob.JobId)

return properties
}

func (ce *ComprehendEventsDetectionJob) String() string {
if ce.eventsDetectionJob.JobName == nil {
return "Unnamed job"
} else {
return *ce.eventsDetectionJob.JobName
}
}
5 changes: 5 additions & 0 deletions resources/comprehend_key_phrases_detection_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func ListComprehendKeyPhrasesDetectionJobs(sess *session.Session) ([]Resource, e
return nil, err
}
for _, keyPhrasesDetectionJob := range resp.KeyPhrasesDetectionJobPropertiesList {
switch *keyPhrasesDetectionJob.JobStatus {
case "STOPPED", "FAILED", "COMPLETED":
// if the job has already been stopped, failed, or completed; do not try to stop it again
continue
}
resources = append(resources, &ComprehendKeyPhrasesDetectionJob{
svc: svc,
keyPhrasesDetectionJob: keyPhrasesDetectionJob,
Expand Down
72 changes: 72 additions & 0 deletions resources/comprehend_pii_entities_detection_job.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/comprehend"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

func init() {
register("ComprehendPiiEntititesDetectionJob", ListComprehendPiiEntitiesDetectionJobs)
}

func ListComprehendPiiEntitiesDetectionJobs(sess *session.Session) ([]Resource, error) {
svc := comprehend.New(sess)

params := &comprehend.ListPiiEntitiesDetectionJobsInput{}
resources := make([]Resource, 0)

for {
resp, err := svc.ListPiiEntitiesDetectionJobs(params)
if err != nil {
return nil, err
}
for _, piiEntititesDetectionJob := range resp.PiiEntitiesDetectionJobPropertiesList {
switch *piiEntititesDetectionJob.JobStatus {
case "STOPPED", "FAILED", "COMPLETED":
// if the job has already been stopped, failed, or completed; do not try to stop it again
continue
}
resources = append(resources, &ComprehendPiiEntitiesDetectionJob{
svc: svc,
piiEntititesDetectionJob: piiEntititesDetectionJob,
})
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

type ComprehendPiiEntitiesDetectionJob struct {
svc *comprehend.Comprehend
piiEntititesDetectionJob *comprehend.PiiEntitiesDetectionJobProperties
}

func (ce *ComprehendPiiEntitiesDetectionJob) Remove() error {
_, err := ce.svc.StopPiiEntitiesDetectionJob(&comprehend.StopPiiEntitiesDetectionJobInput{
JobId: ce.piiEntititesDetectionJob.JobId,
})
return err
}

func (ce *ComprehendPiiEntitiesDetectionJob) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("JobName", ce.piiEntititesDetectionJob.JobName)
properties.Set("JobId", ce.piiEntititesDetectionJob.JobId)

return properties
}

func (ce *ComprehendPiiEntitiesDetectionJob) String() string {
if ce.piiEntititesDetectionJob.JobName == nil {
return "Unnamed job"
} else {
return *ce.piiEntititesDetectionJob.JobName
}
}
6 changes: 3 additions & 3 deletions resources/comprehend_sentiment_detection_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ func ListComprehendSentimentDetectionJobs(sess *session.Session) ([]Resource, er
return nil, err
}
for _, sentimentDetectionJob := range resp.SentimentDetectionJobPropertiesList {
if *sentimentDetectionJob.JobStatus == "STOPPED" ||
*sentimentDetectionJob.JobStatus == "FAILED" {
// if the job has already been stopped, do not try to delete it again
switch *sentimentDetectionJob.JobStatus {
case "STOPPED", "FAILED", "COMPLETED":
// if the job has already been stopped, failed, or completed; do not try to stop it again
continue
}
resources = append(resources, &ComprehendSentimentDetectionJob{
Expand Down
72 changes: 72 additions & 0 deletions resources/comprehend_targeted_sentiment_detection_job.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/comprehend"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

func init() {
register("ComprehendTargetedSentimentDetectionJob", ListComprehendTargetedSentimentDetectionJobs)
}

func ListComprehendTargetedSentimentDetectionJobs(sess *session.Session) ([]Resource, error) {
svc := comprehend.New(sess)

params := &comprehend.ListTargetedSentimentDetectionJobsInput{}
resources := make([]Resource, 0)

for {
resp, err := svc.ListTargetedSentimentDetectionJobs(params)
if err != nil {
return nil, err
}
for _, targetedSentimentDetectionJob := range resp.TargetedSentimentDetectionJobPropertiesList {
switch *targetedSentimentDetectionJob.JobStatus {
case "STOPPED", "FAILED", "COMPLETED":
// if the job has already been stopped, failed, or completed; do not try to stop it again
continue
}
resources = append(resources, &ComprehendTargetedSentimentDetectionJob{
svc: svc,
targetedSentimentDetectionJob: targetedSentimentDetectionJob,
})
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

type ComprehendTargetedSentimentDetectionJob struct {
svc *comprehend.Comprehend
targetedSentimentDetectionJob *comprehend.TargetedSentimentDetectionJobProperties
}

func (ce *ComprehendTargetedSentimentDetectionJob) Remove() error {
_, err := ce.svc.StopTargetedSentimentDetectionJob(&comprehend.StopTargetedSentimentDetectionJobInput{
JobId: ce.targetedSentimentDetectionJob.JobId,
})
return err
}

func (ce *ComprehendTargetedSentimentDetectionJob) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("JobName", ce.targetedSentimentDetectionJob.JobName)
properties.Set("JobId", ce.targetedSentimentDetectionJob.JobId)

return properties
}

func (ce *ComprehendTargetedSentimentDetectionJob) String() string {
if ce.targetedSentimentDetectionJob.JobName == nil {
return "Unnamed job"
} else {
return *ce.targetedSentimentDetectionJob.JobName
}
}

0 comments on commit 36a47fe

Please sign in to comment.