-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #266 from ekristen/feat-scheduler-schedule
feat(resource): add event bridge scheduler schedule resource
- Loading branch information
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(®istry.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 | ||
} |