Skip to content

Commit

Permalink
Update table per review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
misraved committed Nov 29, 2024
1 parent f07156d commit d93d85f
Showing 1 changed file with 19 additions and 45 deletions.
64 changes: 19 additions & 45 deletions aws/table_aws_config_delivery_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ func tableAwsConfigDeliveryChannel(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "aws_config_delivery_channel",
Description: "AWS Config Delivery Channel",
Get: &plugin.GetConfig{
KeyColumns: plugin.AllColumns([]string{"name", "region"}),
List: &plugin.ListConfig{
Hydrate: listConfigDeliveryChannels,
KeyColumns: []*plugin.KeyColumn{
{
Name: "name",
Require: plugin.Optional,
},
},
IgnoreConfig: &plugin.IgnoreConfig{
ShouldIgnoreErrorFunc: shouldIgnoreErrors([]string{"NoSuchDeliveryChannelException"}),
},
Hydrate: getConfigDeliveryChannel,
Tags: map[string]string{"service": "config", "action": "DescribeDeliveryChannels"},
},
List: &plugin.ListConfig{
Hydrate: listConfigDeliveryChannels,
Tags: map[string]string{"service": "config", "action": "DescribeDeliveryChannels"},
},
GetMatrixItemFunc: SupportedRegionMatrix(configservicev1.EndpointsID),
Expand All @@ -38,13 +39,6 @@ func tableAwsConfigDeliveryChannel(_ context.Context) *plugin.Table {
Description: "The name of the delivery channel.",
Type: proto.ColumnType_STRING,
},
{
Name: "arn",
Description: "The Amazon Resource Name (ARN) of the delivery channel.",
Type: proto.ColumnType_STRING,
Hydrate: getAwsDeliveryChannelARN,
Transform: transform.FromValue(),
},
{
Name: "s3_bucket_name",
Description: "The name of the Amazon S3 bucket to which AWS Config delivers configuration snapshots and configuration history files.",
Expand Down Expand Up @@ -82,12 +76,13 @@ func tableAwsConfigDeliveryChannel(_ context.Context) *plugin.Table {
Hydrate: getConfigDeliveryChannelStatus,
Transform: transform.FromValue(),
},
// Standard columns

// Steampipe standard columns
{
Name: "akas",
Description: resourceInterfaceDescription("akas"),
Type: proto.ColumnType_JSON,
Hydrate: getAwsDeliveryChannelARN,
Hydrate: getAwsDeliveryChannelAkas,
Transform: transform.FromValue().Transform(transform.EnsureStringArray),
},
{
Expand All @@ -112,6 +107,12 @@ func listConfigDeliveryChannels(ctx context.Context, d *plugin.QueryData, _ *plu

input := &configservice.DescribeDeliveryChannelsInput{}

// Additonal Filter
equalQuals := d.EqualsQuals
if equalQuals["name"] != nil {
input.DeliveryChannelNames = []string{equalQuals["name"].GetStringValue()}
}

op, err := svc.DescribeDeliveryChannels(ctx, input)
if err != nil {
plugin.Logger(ctx).Error("aws_config_delivery_channel.listConfigDeliveryChannels", "api_error", err)
Expand All @@ -134,33 +135,6 @@ func listConfigDeliveryChannels(ctx context.Context, d *plugin.QueryData, _ *plu

//// HYDRATE FUNCTIONS

func getConfigDeliveryChannel(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
name := d.EqualsQuals["name"].GetStringValue()

// Create session
svc, err := ConfigClient(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("aws_config_delivery_channel.getConfigDeliveryChannel", "get_client_error", err)
return nil, err
}

params := &configservice.DescribeDeliveryChannelsInput{
DeliveryChannelNames: []string{name},
}

op, err := svc.DescribeDeliveryChannels(ctx, params)
if err != nil {
plugin.Logger(ctx).Error("aws_config_delivery_channel.getConfigDeliveryChannel", "api_error", err)
return nil, err
}

if op != nil && len(op.DeliveryChannels) > 0 {
return op.DeliveryChannels[0], nil
}

return nil, nil
}

func getConfigDeliveryChannelStatus(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
deliveryChannel := h.Item.(types.DeliveryChannel)

Expand Down Expand Up @@ -188,14 +162,14 @@ func getConfigDeliveryChannelStatus(ctx context.Context, d *plugin.QueryData, h
return status.DeliveryChannelsStatus[0], nil
}

func getAwsDeliveryChannelARN(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
func getAwsDeliveryChannelAkas(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
region := d.EqualsQualString(matrixKeyRegion)

deliveryChannel := h.Item.(types.DeliveryChannel)

c, err := getCommonColumns(ctx, d, h)
if err != nil {
plugin.Logger(ctx).Error("aws_config_delivery_channel.getAwsDeliveryChannelARN", "api_error", err)
plugin.Logger(ctx).Error("aws_config_delivery_channel.getAwsDeliveryChannelAkas", "api_error", err)
return nil, err
}
commonColumnData := c.(*awsCommonColumnData)
Expand Down

0 comments on commit d93d85f

Please sign in to comment.