This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
0dd135f
commit 36a47fe
Showing
7 changed files
with
232 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |