Skip to content

Commit

Permalink
Add AWS Lex resources (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
der-eismann committed Aug 28, 2020
1 parent 970888e commit 3fe7ac3
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 0 deletions.
72 changes: 72 additions & 0 deletions resources/lex-bot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package resources

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

type LexBot struct {
svc *lexmodelbuildingservice.LexModelBuildingService
name *string
status *string
}

func init() {
register("LexBot", ListLexBots)
}

func ListLexBots(sess *session.Session) ([]Resource, error) {
svc := lexmodelbuildingservice.New(sess)
resources := []Resource{}

params := &lexmodelbuildingservice.GetBotsInput{
MaxResults: aws.Int64(10),
}

for {
output, err := svc.GetBots(params)
if err != nil {
return nil, err
}

for _, bot := range output.Bots {
resources = append(resources, &LexBot{
svc: svc,
name: bot.Name,
status: bot.Status,
})
}

if output.NextToken == nil {
break
}

params.NextToken = output.NextToken
}

return resources, nil
}

func (f *LexBot) Remove() error {

_, err := f.svc.DeleteBot(&lexmodelbuildingservice.DeleteBotInput{
Name: f.name,
})

return err
}

func (f *LexBot) String() string {
return *f.name
}

func (f *LexBot) Properties() types.Properties {
properties := types.NewProperties()

properties.
Set("Name", f.name).
Set("Status", f.status)
return properties
}
69 changes: 69 additions & 0 deletions resources/lex-intent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package resources

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

type LexIntent struct {
svc *lexmodelbuildingservice.LexModelBuildingService
name *string
}

func init() {
register("LexIntent", ListLexIntents)
}

func ListLexIntents(sess *session.Session) ([]Resource, error) {
svc := lexmodelbuildingservice.New(sess)
resources := []Resource{}

params := &lexmodelbuildingservice.GetIntentsInput{
MaxResults: aws.Int64(20),
}

for {
output, err := svc.GetIntents(params)
if err != nil {
return nil, err
}

for _, bot := range output.Intents {
resources = append(resources, &LexIntent{
svc: svc,
name: bot.Name,
})
}

if output.NextToken == nil {
break
}

params.NextToken = output.NextToken
}

return resources, nil
}

func (f *LexIntent) Remove() error {

_, err := f.svc.DeleteIntent(&lexmodelbuildingservice.DeleteIntentInput{
Name: f.name,
})

return err
}

func (f *LexIntent) String() string {
return *f.name
}

func (f *LexIntent) Properties() types.Properties {
properties := types.NewProperties()

properties.
Set("Name", f.name)
return properties
}
69 changes: 69 additions & 0 deletions resources/lex-slot-types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package resources

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

type LexSlotType struct {
svc *lexmodelbuildingservice.LexModelBuildingService
name *string
}

func init() {
register("LexSlotType", ListLexSlotTypes)
}

func ListLexSlotTypes(sess *session.Session) ([]Resource, error) {
svc := lexmodelbuildingservice.New(sess)
resources := []Resource{}

params := &lexmodelbuildingservice.GetSlotTypesInput{
MaxResults: aws.Int64(20),
}

for {
output, err := svc.GetSlotTypes(params)
if err != nil {
return nil, err
}

for _, bot := range output.SlotTypes {
resources = append(resources, &LexSlotType{
svc: svc,
name: bot.Name,
})
}

if output.NextToken == nil {
break
}

params.NextToken = output.NextToken
}

return resources, nil
}

func (f *LexSlotType) Remove() error {

_, err := f.svc.DeleteSlotType(&lexmodelbuildingservice.DeleteSlotTypeInput{
Name: f.name,
})

return err
}

func (f *LexSlotType) String() string {
return *f.name
}

func (f *LexSlotType) Properties() types.Properties {
properties := types.NewProperties()

properties.
Set("Name", f.name)
return properties
}

0 comments on commit 3fe7ac3

Please sign in to comment.