/
webhooks.go
153 lines (147 loc) · 5.24 KB
/
webhooks.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package codepipeline
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/codepipeline"
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
"github.com/cloudquery/cq-provider-sdk/provider/diag"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
)
//go:generate cq-gen --resource webhooks --config gen.hcl --output .
func Webhooks() *schema.Table {
return &schema.Table{
Name: "aws_codepipeline_webhooks",
Description: "The detail returned for each webhook after listing webhooks, such as the webhook URL, the webhook name, and the webhook ARN",
Resolver: fetchCodepipelineWebhooks,
Multiplex: client.ServiceAccountRegionMultiplexer("codepipeline"),
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: "authentication",
Description: "Supported options are GITHUB_HMAC, IP, and UNAUTHENTICATED",
Type: schema.TypeString,
Resolver: schema.PathResolver("Definition.Authentication"),
},
{
Name: "authentication_allowed_ip_range",
Description: "The property used to configure acceptance of webhooks in an IP address range For IP, only the AllowedIPRange property must be set",
Type: schema.TypeString,
Resolver: schema.PathResolver("Definition.AuthenticationConfiguration.AllowedIPRange"),
},
{
Name: "authentication_secret_token",
Description: "The property used to configure GitHub authentication",
Type: schema.TypeString,
Resolver: schema.PathResolver("Definition.AuthenticationConfiguration.SecretToken"),
},
{
Name: "name",
Description: "The name of the webhook",
Type: schema.TypeString,
Resolver: schema.PathResolver("Definition.Name"),
},
{
Name: "target_action",
Description: "The name of the action in a pipeline you want to connect to the webhook",
Type: schema.TypeString,
Resolver: schema.PathResolver("Definition.TargetAction"),
},
{
Name: "target_pipeline",
Description: "The name of the pipeline you want to connect to the webhook",
Type: schema.TypeString,
Resolver: schema.PathResolver("Definition.TargetPipeline"),
},
{
Name: "url",
Description: "A unique URL generated by CodePipeline",
Type: schema.TypeString,
},
{
Name: "arn",
Description: "The Amazon Resource Name (ARN) of the webhook",
Type: schema.TypeString,
},
{
Name: "error_code",
Description: "The number code of the error",
Type: schema.TypeString,
},
{
Name: "error_message",
Description: "The text of the error message about the webhook",
Type: schema.TypeString,
},
{
Name: "last_triggered",
Description: "The date and time a webhook was last successfully triggered, in timestamp format",
Type: schema.TypeTimestamp,
},
{
Name: "tags",
Description: "The tags associated with the webhook",
Type: schema.TypeJSON,
Resolver: client.ResolveTags,
},
},
Relations: []*schema.Table{
{
Name: "aws_codepipeline_webhook_filters",
Description: "The event criteria that specify when a webhook notification is sent to your URL",
Resolver: schema.PathTableResolver("Definition.Filters"),
Columns: []schema.Column{
{
Name: "webhook_cq_id",
Description: "Unique CloudQuery ID of aws_codepipeline_webhooks table (FK)",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "json_path",
Description: "A JsonPath expression that is applied to the body/payload of the webhook",
Type: schema.TypeString,
},
{
Name: "match_equals",
Description: "The value selected by the JsonPath expression must match what is supplied in the MatchEquals field",
Type: schema.TypeString,
},
},
},
},
}
}
// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================
func fetchCodepipelineWebhooks(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
c := meta.(*client.Client)
svc := c.Services().CodePipeline
config := codepipeline.ListWebhooksInput{}
for {
response, err := svc.ListWebhooks(ctx, &config)
if err != nil {
return diag.WrapError(err)
}
res <- response.Webhooks
if aws.ToString(response.NextToken) == "" {
break
}
config.NextToken = response.NextToken
}
return nil
}