From 97c004496e31f26987c6bf35f397cf5d430efff7 Mon Sep 17 00:00:00 2001 From: Sherd White Date: Wed, 8 May 2024 20:28:54 -0500 Subject: [PATCH] CL-880 Elastic Transcoder Preset support. --- resources/elastictranscoder-preset.go | 74 +++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 resources/elastictranscoder-preset.go diff --git a/resources/elastictranscoder-preset.go b/resources/elastictranscoder-preset.go new file mode 100644 index 000000000..da9356c67 --- /dev/null +++ b/resources/elastictranscoder-preset.go @@ -0,0 +1,74 @@ +package resources + +import ( + "fmt" + "strings" + + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/elastictranscoder" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" +) + +type ElasticTranscoderPreset struct { + svc *elastictranscoder.ElasticTranscoder + presetID *string +} + +func init() { + register("ElasticTranscoderPreset", ListElasticTranscoderPresets) +} + +func ListElasticTranscoderPresets(sess *session.Session) ([]Resource, error) { + svc := elastictranscoder.New(sess) + resources := []Resource{} + + params := &elastictranscoder.ListPresetsInput{} + + for { + resp, err := svc.ListPresets(params) + if err != nil { + return nil, err + } + + for _, preset := range resp.Presets { + resources = append(resources, &ElasticTranscoderPreset{ + svc: svc, + presetID: preset.Id, + }) + } + + if resp.NextPageToken == nil { + break + } + + params.PageToken = resp.NextPageToken + } + + return resources, nil +} + +func (f *ElasticTranscoderPreset) Filter() error { + if strings.HasPrefix(*f.presetID, "1351620000001") { + return fmt.Errorf("cannot delete elastic transcoder system presets") + } + return nil +} + +func (f *ElasticTranscoderPreset) Remove() error { + + _, err := f.svc.DeletePreset(&elastictranscoder.DeletePresetInput{ + Id: f.presetID, + }) + + return err +} + +func (f *ElasticTranscoderPreset) Properties() types.Properties { + properties := types.NewProperties() + properties.Set("PresetID", f.presetID) + return properties +} + +func (f *ElasticTranscoderPreset) String() string { + return *f.presetID +}