Skip to content

Commit b92675f

Browse files
ParthaImisraved
andauthored
Added tables aws_cloudwatch_log_destination, aws_cloudwatch_log_delivery_source, aws_cloudwatch_log_delivery, and aws_cloudwatch_log_delivery_destination Closes #2453 (#2469)
Co-authored-by: Ved misra <47312748+misraved@users.noreply.github.com>
1 parent aa569d9 commit b92675f

9 files changed

Lines changed: 1428 additions & 0 deletions

aws/plugin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ func Plugin(ctx context.Context) *plugin.Plugin {
138138
"aws_cloudtrail_trail": tableAwsCloudtrailTrail(ctx),
139139
"aws_cloudtrail_trail_event": tableAwsCloudtrailTrailEvent(ctx),
140140
"aws_cloudwatch_alarm": tableAwsCloudWatchAlarm(ctx),
141+
"aws_cloudwatch_log_delivery_destination": tableAwsCloudWatchLogDeliveryDestination(ctx),
142+
"aws_cloudwatch_log_delivery_source": tableAwsCloudWatchLogDeliverySource(ctx),
143+
"aws_cloudwatch_log_delivery": tableAwsCloudWatchLogDelivery(ctx),
144+
"aws_cloudwatch_log_destination": tableAwsCloudWatchLogDestination(ctx),
141145
"aws_cloudwatch_log_event": tableAwsCloudwatchLogEvent(ctx),
142146
"aws_cloudwatch_log_group": tableAwsCloudwatchLogGroup(ctx),
143147
"aws_cloudwatch_log_metric_filter": tableAwsCloudwatchLogMetricFilter(ctx),
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
package aws
2+
3+
import (
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
7+
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
8+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
9+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
10+
)
11+
12+
func tableAwsCloudWatchLogDelivery(_ context.Context) *plugin.Table {
13+
return &plugin.Table{
14+
Name: "aws_cloudwatch_log_delivery",
15+
Description: "AWS CloudWatch Log Delivery represents a delivery configuration for vended logs.",
16+
Get: &plugin.GetConfig{
17+
KeyColumns: plugin.SingleColumn("id"),
18+
Hydrate: getCloudWatchLogDelivery,
19+
Tags: map[string]string{"service": "logs", "action": "GetDelivery"},
20+
},
21+
List: &plugin.ListConfig{
22+
Hydrate: listCloudWatchLogDeliveries,
23+
Tags: map[string]string{"service": "logs", "action": "ListDeliveries"},
24+
},
25+
GetMatrixItemFunc: CloudWatchRegionsMatrix,
26+
Columns: []*plugin.Column{
27+
{
28+
Name: "id",
29+
Description: "The unique ID that identifies this delivery in your account.",
30+
Type: proto.ColumnType_STRING,
31+
},
32+
{
33+
Name: "arn",
34+
Description: "The Amazon Resource Name (ARN) that uniquely identifies this delivery.",
35+
Type: proto.ColumnType_STRING,
36+
},
37+
{
38+
Name: "delivery_source_name",
39+
Description: "The name of the delivery source that is associated with this delivery.",
40+
Type: proto.ColumnType_STRING,
41+
},
42+
{
43+
Name: "delivery_destination_arn",
44+
Description: "The ARN of the delivery destination that is associated with this delivery.",
45+
Type: proto.ColumnType_STRING,
46+
},
47+
{
48+
Name: "delivery_destination_type",
49+
Description: "Displays whether the delivery destination associated with this delivery is CloudWatch Logs, Amazon S3, or Firehose.",
50+
Type: proto.ColumnType_STRING,
51+
},
52+
53+
// Standard columns
54+
{
55+
Name: "title",
56+
Description: resourceInterfaceDescription("title"),
57+
Type: proto.ColumnType_STRING,
58+
Transform: transform.FromField("Id"),
59+
},
60+
{
61+
Name: "tags",
62+
Description: resourceInterfaceDescription("tags"),
63+
Type: proto.ColumnType_JSON,
64+
},
65+
{
66+
Name: "akas",
67+
Description: resourceInterfaceDescription("akas"),
68+
Type: proto.ColumnType_JSON,
69+
Transform: transform.FromField("Arn").Transform(transform.EnsureStringArray),
70+
},
71+
},
72+
}
73+
}
74+
75+
//// LIST FUNCTION
76+
77+
func listCloudWatchLogDeliveries(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
78+
// Create session
79+
svc, err := CloudWatchLogsClient(ctx, d)
80+
if err != nil {
81+
plugin.Logger(ctx).Error("aws_cloudwatch_log_delivery.listCloudWatchLogDeliveries", "connection_error", err)
82+
return nil, err
83+
}
84+
85+
// Limiting the results
86+
maxLimit := int32(50)
87+
if d.QueryContext.Limit != nil {
88+
limit := int32(*d.QueryContext.Limit)
89+
if limit < maxLimit {
90+
maxLimit = limit
91+
}
92+
}
93+
94+
input := &cloudwatchlogs.DescribeDeliveriesInput{
95+
Limit: &maxLimit,
96+
}
97+
98+
paginator := cloudwatchlogs.NewDescribeDeliveriesPaginator(svc, input, func(o *cloudwatchlogs.DescribeDeliveriesPaginatorOptions) {
99+
o.Limit = maxLimit
100+
o.StopOnDuplicateToken = true
101+
})
102+
103+
for paginator.HasMorePages() {
104+
// apply rate limiting
105+
d.WaitForListRateLimit(ctx)
106+
107+
output, err := paginator.NextPage(ctx)
108+
if err != nil {
109+
plugin.Logger(ctx).Error("aws_cloudwatch_log_delivery.listCloudWatchLogDeliveries", "api_error", err)
110+
return nil, err
111+
}
112+
113+
for _, delivery := range output.Deliveries {
114+
d.StreamListItem(ctx, delivery)
115+
116+
// Context may get cancelled due to manual cancellation or if the limit has been reached
117+
if d.RowsRemaining(ctx) == 0 {
118+
return nil, nil
119+
}
120+
}
121+
}
122+
123+
return nil, nil
124+
}
125+
126+
//// HYDRATE FUNCTIONS
127+
128+
func getCloudWatchLogDelivery(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
129+
deliveryId := d.EqualsQuals["id"].GetStringValue()
130+
131+
// Create session
132+
svc, err := CloudWatchLogsClient(ctx, d)
133+
if err != nil {
134+
plugin.Logger(ctx).Error("aws_cloudwatch_log_delivery.getCloudWatchLogDelivery", "connection_error", err)
135+
return nil, err
136+
}
137+
138+
params := &cloudwatchlogs.GetDeliveryInput{
139+
Id: &deliveryId,
140+
}
141+
142+
op, err := svc.GetDelivery(ctx, params)
143+
if err != nil {
144+
plugin.Logger(ctx).Error("aws_cloudwatch_log_delivery.getCloudWatchLogDelivery", "api_error", err)
145+
return nil, err
146+
}
147+
148+
if op.Delivery != nil {
149+
return *op.Delivery, nil
150+
}
151+
152+
return nil, nil
153+
}
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
package aws
2+
3+
import (
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
7+
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"
8+
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
9+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
10+
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
11+
)
12+
13+
func tableAwsCloudWatchLogDeliveryDestination(_ context.Context) *plugin.Table {
14+
return &plugin.Table{
15+
Name: "aws_cloudwatch_log_delivery_destination",
16+
Description: "AWS CloudWatch Log Delivery Destination represents a destination configuration for vended log delivery.",
17+
Get: &plugin.GetConfig{
18+
KeyColumns: plugin.SingleColumn("name"),
19+
Hydrate: getCloudWatchLogDeliveryDestination,
20+
Tags: map[string]string{"service": "logs", "action": "GetDeliveryDestination"},
21+
},
22+
List: &plugin.ListConfig{
23+
Hydrate: listCloudWatchLogDeliveryDestinations,
24+
Tags: map[string]string{"service": "logs", "action": "ListDeliveryDestinations"},
25+
},
26+
GetMatrixItemFunc: CloudWatchRegionsMatrix,
27+
Columns: []*plugin.Column{
28+
{
29+
Name: "name",
30+
Description: "The name of the delivery destination.",
31+
Type: proto.ColumnType_STRING,
32+
},
33+
{
34+
Name: "arn",
35+
Description: "The Amazon Resource Name (ARN) that uniquely identifies this delivery destination.",
36+
Type: proto.ColumnType_STRING,
37+
},
38+
{
39+
Name: "destination_resource_arn",
40+
Description: "The ARN of the Amazon Web Services destination that this delivery destination represents.",
41+
Type: proto.ColumnType_STRING,
42+
Transform: transform.FromField("DeliveryDestinationConfiguration.DestinationResourceArn"),
43+
},
44+
{
45+
Name: "delivery_destination_type",
46+
Description: "Displays whether this delivery destination is CloudWatch Logs, Amazon S3, or Firehose.",
47+
Type: proto.ColumnType_STRING,
48+
},
49+
{
50+
Name: "output_format",
51+
Description: "The format of the logs that are sent to this delivery destination.",
52+
Type: proto.ColumnType_STRING,
53+
},
54+
{
55+
Name: "policy",
56+
Description: "The policy of the delivery destination.",
57+
Type: proto.ColumnType_JSON,
58+
Hydrate: getCloudWatchLogDeliveryDestinationPolicy,
59+
Transform: transform.FromValue(),
60+
},
61+
62+
// Standard columns
63+
{
64+
Name: "title",
65+
Description: resourceInterfaceDescription("title"),
66+
Type: proto.ColumnType_STRING,
67+
Transform: transform.FromField("Name"),
68+
},
69+
{
70+
Name: "tags",
71+
Description: resourceInterfaceDescription("tags"),
72+
Type: proto.ColumnType_JSON,
73+
},
74+
{
75+
Name: "akas",
76+
Description: resourceInterfaceDescription("akas"),
77+
Type: proto.ColumnType_JSON,
78+
Transform: transform.FromField("Arn").Transform(transform.EnsureStringArray),
79+
},
80+
},
81+
}
82+
}
83+
84+
//// LIST FUNCTION
85+
86+
func listCloudWatchLogDeliveryDestinations(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
87+
// Create session
88+
svc, err := CloudWatchLogsClient(ctx, d)
89+
if err != nil {
90+
plugin.Logger(ctx).Error("aws_cloudwatch_log_delivery_destination.listCloudWatchLogDeliveryDestinations", "connection_error", err)
91+
return nil, err
92+
}
93+
94+
// Limiting the results
95+
maxLimit := int32(50)
96+
if d.QueryContext.Limit != nil {
97+
limit := int32(*d.QueryContext.Limit)
98+
if limit < maxLimit {
99+
maxLimit = limit
100+
}
101+
}
102+
103+
input := &cloudwatchlogs.DescribeDeliveryDestinationsInput{
104+
Limit: &maxLimit,
105+
}
106+
107+
paginator := cloudwatchlogs.NewDescribeDeliveryDestinationsPaginator(svc, input, func(o *cloudwatchlogs.DescribeDeliveryDestinationsPaginatorOptions) {
108+
o.Limit = maxLimit
109+
o.StopOnDuplicateToken = true
110+
})
111+
112+
for paginator.HasMorePages() {
113+
// apply rate limiting
114+
d.WaitForListRateLimit(ctx)
115+
116+
output, err := paginator.NextPage(ctx)
117+
if err != nil {
118+
plugin.Logger(ctx).Error("aws_cloudwatch_log_delivery_destination.listCloudWatchLogDeliveryDestinations", "api_error", err)
119+
return nil, err
120+
}
121+
122+
for _, destination := range output.DeliveryDestinations {
123+
d.StreamListItem(ctx, destination)
124+
125+
// Context may get cancelled due to manual cancellation or if the limit has been reached
126+
if d.RowsRemaining(ctx) == 0 {
127+
return nil, nil
128+
}
129+
}
130+
}
131+
132+
return nil, nil
133+
}
134+
135+
//// HYDRATE FUNCTIONS
136+
137+
func getCloudWatchLogDeliveryDestination(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
138+
destinationName := d.EqualsQuals["name"].GetStringValue()
139+
140+
// Create session
141+
svc, err := CloudWatchLogsClient(ctx, d)
142+
if err != nil {
143+
plugin.Logger(ctx).Error("aws_cloudwatch_log_delivery_destination.getCloudWatchLogDeliveryDestination", "connection_error", err)
144+
return nil, err
145+
}
146+
147+
params := &cloudwatchlogs.GetDeliveryDestinationInput{
148+
Name: &destinationName,
149+
}
150+
151+
op, err := svc.GetDeliveryDestination(ctx, params)
152+
if err != nil {
153+
plugin.Logger(ctx).Error("aws_cloudwatch_log_delivery_destination.getCloudWatchLogDeliveryDestination", "api_error", err)
154+
return nil, err
155+
}
156+
157+
if op.DeliveryDestination != nil {
158+
return *op.DeliveryDestination, nil
159+
}
160+
161+
return nil, nil
162+
}
163+
164+
func getCloudWatchLogDeliveryDestinationPolicy(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
165+
item := h.Item.(types.DeliveryDestination)
166+
167+
// Create session
168+
svc, err := CloudWatchLogsClient(ctx, d)
169+
if err != nil {
170+
plugin.Logger(ctx).Error("aws_cloudwatch_log_delivery_destination.getCloudWatchLogDeliveryDestination", "connection_error", err)
171+
return nil, err
172+
}
173+
174+
params := &cloudwatchlogs.GetDeliveryDestinationPolicyInput{
175+
DeliveryDestinationName: item.Name,
176+
}
177+
178+
op, err := svc.GetDeliveryDestinationPolicy(ctx, params)
179+
if err != nil {
180+
plugin.Logger(ctx).Error("aws_cloudwatch_log_delivery_destination.getCloudWatchLogDeliveryDestination", "api_error", err)
181+
return nil, err
182+
}
183+
184+
if op.Policy != nil {
185+
return op.Policy, nil
186+
}
187+
188+
return nil, nil
189+
}

0 commit comments

Comments
 (0)