Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PollyLexicon module #1045

Closed
wants to merge 9 commits into from
70 changes: 70 additions & 0 deletions resources/polly-lexicons.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package resources

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

type PollyLexicon struct {
svc *polly.Polly
name *string
attributes *polly.LexiconAttributes
}

func init() {
register("PollyLexicon", ListPollyLexicons)
}

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

for {
listLexiconsInput := &polly.ListLexiconsInput{
NextToken: nextToken,
}

listOutput, err := svc.ListLexicons(listLexiconsInput)
if err != nil {
return nil, err
}
for _, lexicon := range listOutput.Lexicons {
resources = append(resources, &PollyLexicon{
svc: svc,
name: lexicon.Name,
attributes: lexicon.Attributes,
})
}

// 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 (lexicon *PollyLexicon) Remove() error {
deleteInput := &polly.DeleteLexiconInput{
Name: lexicon.name,
}
_, err := lexicon.svc.DeleteLexicon(deleteInput)
return err
}

func (lexicon *PollyLexicon) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Name", lexicon.name)
properties.Set("Alphabet", lexicon.attributes.Alphabet)
properties.Set("LanguageCode", lexicon.attributes.LanguageCode)
properties.Set("LastModified", lexicon.attributes.LastModified.Format(time.RFC3339))
properties.Set("LexemesCount", lexicon.attributes.LexemesCount)
properties.Set("LexiconArn", lexicon.attributes.LexiconArn)
properties.Set("Size", lexicon.attributes.Size)
return properties
}