Skip to content

Commit

Permalink
Merge pull request #266 from ekristen/feat-scheduler-schedule
Browse files Browse the repository at this point in the history
feat(resource): add event bridge scheduler schedule resource
  • Loading branch information
ekristen authored Aug 29, 2024
2 parents dba7634 + ab429a1 commit 3cfc6e9
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions resources/scheduler-schedule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package resources

import (
"context"
"time"

"github.com/aws/aws-sdk-go/service/scheduler"

"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/v3/pkg/nuke"
)

const SchedulerScheduleResource = "SchedulerSchedule"

func init() {
registry.Register(&registry.Registration{
Name: SchedulerScheduleResource,
Scope: nuke.Account,
Lister: &SchedulerScheduleLister{},
})
}

type SchedulerScheduleLister struct{}

func (l *SchedulerScheduleLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)
svc := scheduler.New(opts.Session)
var resources []resource.Resource

res, err := svc.ListSchedules(&scheduler.ListSchedulesInput{})
if err != nil {
return nil, err
}

for _, p := range res.Schedules {
resources = append(resources, &SchedulerSchedule{
svc: svc,
Name: p.Name,
State: p.State,
GroupName: p.GroupName,
CreationDate: p.CreationDate,
ModifiedDate: p.LastModificationDate,
})
}

return resources, nil
}

type SchedulerSchedule struct {
svc *scheduler.Scheduler
Name *string
State *string
GroupName *string
CreationDate *time.Time
ModifiedDate *time.Time
}

func (r *SchedulerSchedule) Remove(_ context.Context) error {
_, err := r.svc.DeleteSchedule(&scheduler.DeleteScheduleInput{
Name: r.Name,
GroupName: r.GroupName,
})
return err
}

func (r *SchedulerSchedule) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}

func (r *SchedulerSchedule) String() string {
return *r.Name
}

0 comments on commit 3cfc6e9

Please sign in to comment.