forked from ekristen/aws-nuke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranscribe-call-analytics-category.go
99 lines (82 loc) · 2.69 KB
/
transcribe-call-analytics-category.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
package resources
import (
"context"
"errors"
"strings"
"time"
"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 TranscribeCallAnalyticsCategoryResource = "TranscribeCallAnalyticsCategory"
func init() {
registry.Register(®istry.Registration{
Name: TranscribeCallAnalyticsCategoryResource,
Scope: nuke.Account,
Lister: &TranscribeCallAnalyticsCategoryLister{},
})
}
type TranscribeCallAnalyticsCategoryLister struct{}
func (l *TranscribeCallAnalyticsCategoryLister) 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 {
listCallAnalyticsCategoriesInput := &transcribeservice.ListCallAnalyticsCategoriesInput{
NextToken: nextToken,
}
listOutput, err := svc.ListCallAnalyticsCategories(listCallAnalyticsCategoriesInput)
if err != nil {
var badRequestException *transcribeservice.BadRequestException
if errors.As(err, &badRequestException) &&
strings.Contains(badRequestException.Message(), "isn't supported in this region") {
return resources, nil
}
return nil, err
}
for _, category := range listOutput.Categories {
resources = append(resources, &TranscribeCallAnalyticsCategory{
svc: svc,
name: category.CategoryName,
inputType: category.InputType,
createTime: category.CreateTime,
lastUpdateTime: category.LastUpdateTime,
})
}
// 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 TranscribeCallAnalyticsCategory struct {
svc *transcribeservice.TranscribeService
name *string
inputType *string
createTime *time.Time
lastUpdateTime *time.Time
}
func (r *TranscribeCallAnalyticsCategory) Remove(_ context.Context) error {
deleteInput := &transcribeservice.DeleteCallAnalyticsCategoryInput{
CategoryName: r.name,
}
_, err := r.svc.DeleteCallAnalyticsCategory(deleteInput)
return err
}
func (r *TranscribeCallAnalyticsCategory) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Name", r.name)
properties.Set("InputType", r.inputType)
properties.Set("CreateTime", r.createTime)
properties.Set("LastUpdateTime", r.lastUpdateTime)
return properties
}
func (r *TranscribeCallAnalyticsCategory) String() string {
return *r.name
}