Skip to content

Commit 33fa1cf

Browse files
Adding pii entitites and sentiment detection job support.
1 parent 5bcf0b6 commit 33fa1cf

File tree

2 files changed

+144
-0
lines changed

2 files changed

+144
-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("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+
}
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)