|
| 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