forked from ekristen/aws-nuke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranscribe-transcription-job.go
103 lines (86 loc) · 2.76 KB
/
transcribe-transcription-job.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package resources
import (
"context"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/transcribeservice"
"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"
"github.com/ekristen/aws-nuke/v3/pkg/nuke"
)
const TranscribeTranscriptionJobResource = "TranscribeTranscriptionJob"
func init() {
registry.Register(®istry.Registration{
Name: TranscribeTranscriptionJobResource,
Scope: nuke.Account,
Lister: &TranscribeTranscriptionJobLister{},
})
}
type TranscribeTranscriptionJobLister struct{}
func (l *TranscribeTranscriptionJobLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)
svc := transcribeservice.New(opts.Session)
resources := make([]resource.Resource, 0)
var nextToken *string
for {
listTranscriptionJobsInput := &transcribeservice.ListTranscriptionJobsInput{
MaxResults: aws.Int64(100),
NextToken: nextToken,
}
listOutput, err := svc.ListTranscriptionJobs(listTranscriptionJobsInput)
if err != nil {
return nil, err
}
for _, job := range listOutput.TranscriptionJobSummaries {
resources = append(resources, &TranscribeTranscriptionJob{
svc: svc,
name: job.TranscriptionJobName,
status: job.TranscriptionJobStatus,
completionTime: job.CompletionTime,
creationTime: job.CreationTime,
failureReason: job.FailureReason,
languageCode: job.LanguageCode,
startTime: job.StartTime,
})
}
// Check if there are more results
if listOutput.NextToken == nil {
break // No more results, exit the loop
}
// Set the nextToken for the next iteration
nextToken = listOutput.NextToken
}
return resources, nil
}
type TranscribeTranscriptionJob struct {
svc *transcribeservice.TranscribeService
name *string
status *string
completionTime *time.Time
creationTime *time.Time
failureReason *string
languageCode *string
startTime *time.Time
}
func (r *TranscribeTranscriptionJob) Remove(_ context.Context) error {
deleteInput := &transcribeservice.DeleteTranscriptionJobInput{
TranscriptionJobName: r.name,
}
_, err := r.svc.DeleteTranscriptionJob(deleteInput)
return err
}
func (r *TranscribeTranscriptionJob) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Name", r.name)
properties.Set("Status", r.status)
properties.Set("CompletionTime", r.completionTime)
properties.Set("CreationTime", r.creationTime)
properties.Set("FailureReason", r.failureReason)
properties.Set("LanguageCode", r.languageCode)
properties.Set("StartTime", r.startTime)
return properties
}
func (r *TranscribeTranscriptionJob) String() string {
return *r.name
}