Skip to content

Commit

Permalink
Merge pull request #25 from oreillymedia/CL-880-enable-aws-services
Browse files Browse the repository at this point in the history
CL-880 Elastic Transcoder Preset support.
  • Loading branch information
swhite-oreilly authored May 14, 2024
2 parents a3a9494 + 97c0044 commit 2d84fb6
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions resources/elastictranscoder-preset.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 2d84fb6

Please sign in to comment.