Skip to content

Commit

Permalink
feat(resource): add TranscribeVocabularyFilter resource
Browse files Browse the repository at this point in the history
  • Loading branch information
danarbaugh authored and ekristen committed Oct 2, 2024
1 parent 47c15cb commit d2246d2
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions resources/transcribe-vocabulary-filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package resources

import (
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/transcribeservice"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type TranscribeVocabularyFilter struct {
svc *transcribeservice.TranscribeService
name *string
languageCode *string
lastModifiedTime *time.Time
}

func init() {
register("TranscribeVocabularyFilter", ListTranscribeVocabularyFilters)
}

func ListTranscribeVocabularyFilters(sess *session.Session) ([]Resource, error) {
svc := transcribeservice.New(sess)
resources := []Resource{}
var nextToken *string

for {
listVocabularyFiltersInput := &transcribeservice.ListVocabularyFiltersInput{
MaxResults: aws.Int64(100),
NextToken: nextToken,
}

listOutput, err := svc.ListVocabularyFilters(listVocabularyFiltersInput)
if err != nil {
return nil, err
}
for _, filter := range listOutput.VocabularyFilters {
resources = append(resources, &TranscribeVocabularyFilter{
svc: svc,
name: filter.VocabularyFilterName,
languageCode: filter.LanguageCode,
lastModifiedTime: filter.LastModifiedTime,
})
}

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

func (filter *TranscribeVocabularyFilter) Remove() error {
deleteInput := &transcribeservice.DeleteVocabularyFilterInput{
VocabularyFilterName: filter.name,
}
_, err := filter.svc.DeleteVocabularyFilter(deleteInput)
return err
}

func (filter *TranscribeVocabularyFilter) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Name", filter.name)
properties.Set("LanguageCode", filter.languageCode)
if filter.lastModifiedTime != nil {
properties.Set("LastModifiedTime", filter.lastModifiedTime.Format(time.RFC3339))
}
return properties
}

0 comments on commit d2246d2

Please sign in to comment.