-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add table aws_scheduler_schedule Closes #2304 #2359
Open
ParthaI
wants to merge
3
commits into
main
Choose a base branch
from
issue-2304
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+483
−5
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,241 @@ | ||
package aws | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/scheduler" | ||
"github.com/aws/aws-sdk-go-v2/service/scheduler/types" | ||
|
||
schedulerv1 "github.com/aws/aws-sdk-go/service/scheduler" | ||
|
||
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" | ||
"github.com/turbot/steampipe-plugin-sdk/v5/plugin" | ||
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" | ||
) | ||
|
||
func tableAwsSchedulerSchedule(_ context.Context) *plugin.Table { | ||
return &plugin.Table{ | ||
Name: "aws_scheduler_schedule", | ||
Description: "AWS EventBridge Scheduler Schedule", | ||
Get: &plugin.GetConfig{ | ||
KeyColumns: plugin.AllColumns([]string{"name", "group_name"}), | ||
Hydrate: getAwsSchedulerSchedule, | ||
IgnoreConfig: &plugin.IgnoreConfig{ | ||
ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"ResourceNotFoundException"}), | ||
}, | ||
Tags: map[string]string{"service": "scheduler", "action": "GetSchedule"}, | ||
}, | ||
List: &plugin.ListConfig{ | ||
Hydrate: listAwsSchedulerSchedules, | ||
IgnoreConfig: &plugin.IgnoreConfig{ | ||
ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"ResourceNotFoundException"}), | ||
}, | ||
KeyColumns: []*plugin.KeyColumn{ | ||
{Name: "group_name", Require: plugin.Optional}, | ||
{Name: "state", Require: plugin.Optional}, | ||
}, | ||
Tags: map[string]string{"service": "scheduler", "action": "ListSchedules"}, | ||
}, | ||
GetMatrixItemFunc: SupportedRegionMatrix(schedulerv1.EndpointsID), | ||
Columns: awsRegionalColumns([]*plugin.Column{ | ||
{ | ||
Name: "name", | ||
Description: "The name of the schedule.", | ||
Type: proto.ColumnType_STRING, | ||
}, | ||
{ | ||
Name: "arn", | ||
Description: "The Amazon Resource Name (ARN) of the schedule.", | ||
Type: proto.ColumnType_STRING, | ||
}, | ||
{ | ||
Name: "state", | ||
Description: "Specifies whether the schedule is enabled or disabled.", | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("State"), | ||
}, | ||
{ | ||
Name: "description", | ||
Description: "The description of the schedule.", | ||
Type: proto.ColumnType_STRING, | ||
Hydrate: getAwsSchedulerSchedule, | ||
}, | ||
{ | ||
Name: "schedule_expression", | ||
Description: "The expression that defines when the schedule runs.", | ||
Type: proto.ColumnType_STRING, | ||
Hydrate: getAwsSchedulerSchedule, | ||
}, | ||
{ | ||
Name: "schedule_expression_timezone", | ||
Description: "The timezone in which the scheduling expression is evaluated.", | ||
Type: proto.ColumnType_STRING, | ||
Hydrate: getAwsSchedulerSchedule, | ||
}, | ||
{ | ||
Name: "creation_date", | ||
Description: "The time at which the schedule was created.", | ||
Type: proto.ColumnType_TIMESTAMP, | ||
}, | ||
{ | ||
Name: "last_modification_date", | ||
Description: "The time at which the schedule was last modified.", | ||
Type: proto.ColumnType_TIMESTAMP, | ||
}, | ||
{ | ||
Name: "start_date", | ||
Description: "The date, in UTC, after which the schedule can begin invoking its target.", | ||
Type: proto.ColumnType_TIMESTAMP, | ||
Hydrate: getAwsSchedulerSchedule, | ||
}, | ||
{ | ||
Name: "end_date", | ||
Description: "The date, in UTC, before which the schedule can invoke its target.", | ||
Type: proto.ColumnType_TIMESTAMP, | ||
Hydrate: getAwsSchedulerSchedule, | ||
}, | ||
{ | ||
Name: "group_name", | ||
Description: "The name of the schedule group associated with this schedule.", | ||
Type: proto.ColumnType_STRING, | ||
}, | ||
{ | ||
Name: "kms_key_arn", | ||
Description: "The ARN for a customer managed KMS Key used for encryption.", | ||
Type: proto.ColumnType_STRING, | ||
Hydrate: getAwsSchedulerSchedule, | ||
}, | ||
{ | ||
Name: "action_after_completion", | ||
Description: "Indicates the action that EventBridge Scheduler applies after completion.", | ||
Type: proto.ColumnType_STRING, | ||
Hydrate: getAwsSchedulerSchedule, | ||
Transform: transform.FromField("ActionAfterCompletion"), | ||
}, | ||
{ | ||
Name: "flexible_time_window", | ||
Description: "Allows you to configure a time window during which the schedule invokes the target.", | ||
Type: proto.ColumnType_JSON, | ||
Hydrate: getAwsSchedulerSchedule, | ||
}, | ||
{ | ||
Name: "target", | ||
Description: "The schedule target.", | ||
Type: proto.ColumnType_JSON, | ||
Hydrate: getAwsSchedulerSchedule, | ||
}, | ||
|
||
// Standard columns | ||
{ | ||
Name: "title", | ||
Description: resourceInterfaceDescription("title"), | ||
Type: proto.ColumnType_STRING, | ||
Transform: transform.FromField("Name"), | ||
}, | ||
{ | ||
Name: "akas", | ||
Description: resourceInterfaceDescription("akas"), | ||
Type: proto.ColumnType_JSON, | ||
Transform: transform.FromField("Arn").Transform(transform.EnsureStringArray), | ||
}, | ||
}), | ||
} | ||
} | ||
|
||
//// LIST FUNCTION | ||
|
||
func listAwsSchedulerSchedules(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
// Create session | ||
svc, err := SchedulerClient(ctx, d) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("aws_scheduler_schedule.listAwsSchedulerSchedules", "client_error", err) | ||
return nil, err | ||
} | ||
|
||
// Limiting the results | ||
maxLimit := int32(100) | ||
if d.QueryContext.Limit != nil { | ||
limit := int32(*d.QueryContext.Limit) | ||
if limit < maxLimit { | ||
maxLimit = limit | ||
} | ||
} | ||
|
||
// Build params | ||
params := &scheduler.ListSchedulesInput{} | ||
if d.EqualsQuals["group_name"] != nil { | ||
params.GroupName = aws.String(d.EqualsQuals["group_name"].GetStringValue()) | ||
} | ||
if d.EqualsQuals["state"] != nil { | ||
params.State = types.ScheduleState(d.EqualsQuals["state"].GetStringValue()) | ||
} | ||
|
||
paginator := scheduler.NewListSchedulesPaginator(svc, params, func(o *scheduler.ListSchedulesPaginatorOptions) { | ||
o.Limit = maxLimit | ||
o.StopOnDuplicateToken = true | ||
}) | ||
|
||
// Iterate and stream results | ||
for paginator.HasMorePages() { | ||
// apply rate limiting | ||
d.WaitForListRateLimit(ctx) | ||
|
||
page, err := paginator.NextPage(ctx) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("aws_scheduler_schedule.listAwsSchedulerSchedules", "api_error", err) | ||
return nil, err | ||
} | ||
|
||
for _, schedule := range page.Schedules { | ||
d.StreamListItem(ctx, schedule) | ||
|
||
// Context can be cancelled due to manual cancellation or the limit has been hit | ||
if d.RowsRemaining(ctx) == 0 { | ||
return nil, nil | ||
} | ||
} | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
//// GET FUNCTION | ||
|
||
func getAwsSchedulerSchedule(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
name := d.EqualsQuals["name"].GetStringValue() | ||
groupName := d.EqualsQuals["group_name"].GetStringValue() | ||
|
||
if h.Item != nil { | ||
scheduler := h.Item.(types.ScheduleSummary) | ||
name = *scheduler.Name | ||
groupName = *scheduler.GroupName | ||
} | ||
|
||
// Empty Check | ||
if name == "" || groupName == "" { | ||
return nil, nil | ||
} | ||
|
||
// Create session | ||
svc, err := SchedulerClient(ctx, d) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("aws_scheduler_schedule.getAwsSchedulerSchedule", "client_error", err) | ||
return nil, err | ||
} | ||
|
||
// Build params | ||
params := &scheduler.GetScheduleInput{ | ||
Name: aws.String(name), | ||
GroupName: aws.String(groupName), | ||
} | ||
|
||
// Call API | ||
result, err := svc.GetSchedule(ctx, params) | ||
if err != nil { | ||
plugin.Logger(ctx).Error("aws_scheduler_schedule.getAwsSchedulerSchedule", "api_error", err) | ||
return nil, err | ||
} | ||
|
||
return result, nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use the above table name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the Terraform naming convention, it is
aws_scheduler_*
(reference: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/scheduler_schedule).Do you think we should rename it?