This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
/
groups.go
115 lines (106 loc) · 3.73 KB
/
groups.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package xray
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/xray"
"github.com/aws/aws-sdk-go-v2/service/xray/types"
"github.com/cloudquery/cq-provider-aws/client"
"github.com/cloudquery/cq-provider-sdk/provider/diag"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
)
//go:generate cq-gen --resource groups --config gen.hcl --output .
func Groups() *schema.Table {
return &schema.Table{
Name: "aws_xray_groups",
Description: "Details for a group.",
Resolver: fetchXrayGroups,
Multiplex: client.ServiceAccountRegionMultiplexer("xray"),
IgnoreError: client.IgnoreCommonErrors,
DeleteFilter: client.DeleteAccountRegionFilter,
Options: schema.TableCreationOptions{PrimaryKeys: []string{"arn"}},
Columns: []schema.Column{
{
Name: "account_id",
Description: "The AWS Account ID of the resource.",
Type: schema.TypeString,
Resolver: client.ResolveAWSAccount,
},
{
Name: "region",
Description: "The AWS Region of the resource.",
Type: schema.TypeString,
Resolver: client.ResolveAWSRegion,
},
{
Name: "tags",
Description: "A list of Tags that specify information about the group.",
Type: schema.TypeJSON,
Resolver: ResolveXrayGroupTags,
},
{
Name: "filter_expression",
Description: "The filter expression defining the parameters to include traces.",
Type: schema.TypeString,
},
{
Name: "arn",
Description: "The ARN of the group generated based on the GroupName.",
Type: schema.TypeString,
Resolver: schema.PathResolver("GroupARN"),
},
{
Name: "group_name",
Description: "The unique case-sensitive name of the group.",
Type: schema.TypeString,
},
{
Name: "insights_enabled",
Description: "Set the InsightsEnabled value to true to enable insights or false to disable insights.",
Type: schema.TypeBool,
Resolver: schema.PathResolver("InsightsConfiguration.InsightsEnabled"),
},
{
Name: "notifications_enabled",
Description: "Set the NotificationsEnabled value to true to enable insights notifications. Notifications can only be enabled on a group with InsightsEnabled set to true.",
Type: schema.TypeBool,
Resolver: schema.PathResolver("InsightsConfiguration.NotificationsEnabled"),
},
},
}
}
// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================
func fetchXrayGroups(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
c := meta.(*client.Client)
svc := c.Services().Xray
input := xray.GetGroupsInput{}
for {
output, err := svc.GetGroups(ctx, &input)
if err != nil {
return diag.WrapError(err)
}
res <- output.Groups
if aws.ToString(output.NextToken) == "" {
break
}
input.NextToken = output.NextToken
}
return nil
}
func ResolveXrayGroupTags(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
group := resource.Item.(types.GroupSummary)
cl := meta.(*client.Client)
svc := cl.Services().Xray
params := xray.ListTagsForResourceInput{ResourceARN: group.GroupARN}
output, err := svc.ListTagsForResource(ctx, ¶ms)
if err != nil {
if cl.IsNotFoundError(err) {
return nil
}
return diag.WrapError(err)
}
tags := map[string]string{}
client.TagsIntoMap(output.Tags, tags)
return diag.WrapError(resource.Set(c.Name, tags))
}