/
pipelines.go
288 lines (279 loc) · 9.91 KB
/
pipelines.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
package codepipeline
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/codepipeline"
"github.com/aws/aws-sdk-go-v2/service/codepipeline/types"
"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 pipelines --config gen.hcl --output .
func Pipelines() *schema.Table {
return &schema.Table{
Name: "aws_codepipeline_pipelines",
Description: "Represents the output of a GetPipeline action",
Resolver: fetchCodepipelinePipelines,
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: "tags",
Description: "The tags associated with the pipeline.",
Type: schema.TypeJSON,
Resolver: resolveCodepipelinePipelineTags,
},
{
Name: "created",
Description: "The date and time the pipeline was created, in timestamp format",
Type: schema.TypeTimestamp,
Resolver: schema.PathResolver("Metadata.Created"),
},
{
Name: "arn",
Description: "The Amazon Resource Name (ARN) of the pipeline",
Type: schema.TypeString,
Resolver: schema.PathResolver("Metadata.PipelineArn"),
},
{
Name: "updated",
Description: "The date and time the pipeline was last updated, in timestamp format",
Type: schema.TypeTimestamp,
Resolver: schema.PathResolver("Metadata.Updated"),
},
{
Name: "name",
Description: "The name of the pipeline",
Type: schema.TypeString,
Resolver: schema.PathResolver("Pipeline.Name"),
},
{
Name: "role_arn",
Description: "The Amazon Resource Name (ARN) for AWS CodePipeline to use to either perform actions with no actionRoleArn, or to use to assume roles for actions with an actionRoleArn",
Type: schema.TypeString,
Resolver: schema.PathResolver("Pipeline.RoleArn"),
},
{
Name: "artifact_store_location",
Description: "The S3 bucket used for storing the artifacts for a pipeline",
Type: schema.TypeString,
Resolver: schema.PathResolver("Pipeline.ArtifactStore.Location"),
},
{
Name: "artifact_store_type",
Description: "The type of the artifact store, such as S3",
Type: schema.TypeString,
Resolver: schema.PathResolver("Pipeline.ArtifactStore.Type"),
},
{
Name: "artifact_store_encryption_key_id",
Description: "The ID used to identify the key",
Type: schema.TypeString,
Resolver: schema.PathResolver("Pipeline.ArtifactStore.EncryptionKey.Id"),
},
{
Name: "artifact_store_encryption_key_type",
Description: "The type of encryption key, such as an AWS Key Management Service (AWS KMS) key When creating or updating a pipeline, the value must be set to 'KMS'",
Type: schema.TypeString,
Resolver: schema.PathResolver("Pipeline.ArtifactStore.EncryptionKey.Type"),
},
{
Name: "artifact_stores",
Description: "A mapping of artifactStore objects and their corresponding AWS Regions",
Type: schema.TypeJSON,
Resolver: schema.PathResolver("Pipeline.ArtifactStores"),
},
{
Name: "version",
Description: "The version number of the pipeline",
Type: schema.TypeBigInt,
Resolver: schema.PathResolver("Pipeline.Version"),
},
},
Relations: []*schema.Table{
{
Name: "aws_codepipeline_pipeline_stages",
Description: "Represents information about a stage and its definition",
Resolver: fetchCodepipelinePipelineStages,
Columns: []schema.Column{
{
Name: "pipeline_cq_id",
Description: "Unique CloudQuery ID of aws_codepipeline_pipelines table (FK)",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "stage_order",
Description: "The stage order in the pipeline.",
Type: schema.TypeBigInt,
},
{
Name: "name",
Description: "The name of the stage",
Type: schema.TypeString,
},
{
Name: "blockers",
Description: "Reserved for future use",
Type: schema.TypeJSON,
Resolver: schema.PathResolver("Blockers"),
IgnoreInTests: true,
},
},
Relations: []*schema.Table{
{
Name: "aws_codepipeline_pipeline_stage_actions",
Description: "Represents information about an action declaration",
Resolver: schema.PathTableResolver("Actions"),
Columns: []schema.Column{
{
Name: "pipeline_stage_cq_id",
Description: "Unique CloudQuery ID of aws_codepipeline_pipeline_stages table (FK)",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "category",
Description: "A category defines what kind of action can be taken in the stage, and constrains the provider type for the action",
Type: schema.TypeString,
Resolver: schema.PathResolver("ActionTypeId.Category"),
},
{
Name: "owner",
Description: "The creator of the action being called",
Type: schema.TypeString,
Resolver: schema.PathResolver("ActionTypeId.Owner"),
},
{
Name: "provider",
Description: "The provider of the service being called by the action",
Type: schema.TypeString,
Resolver: schema.PathResolver("ActionTypeId.Provider"),
},
{
Name: "version",
Description: "A string that describes the action version",
Type: schema.TypeString,
Resolver: schema.PathResolver("ActionTypeId.Version"),
},
{
Name: "name",
Description: "The action declaration's name",
Type: schema.TypeString,
},
{
Name: "configuration",
Description: "The action's configuration",
Type: schema.TypeJSON,
},
{
Name: "input_artifacts",
Description: "The name or ID of the artifact consumed by the action, such as a test or build artifact",
Type: schema.TypeStringArray,
Resolver: schema.PathResolver("InputArtifacts.Name"),
},
{
Name: "namespace",
Description: "The variable namespace associated with the action",
Type: schema.TypeString,
IgnoreInTests: true,
},
{
Name: "output_artifacts",
Description: "The name or ID of the result of the action declaration, such as a test or build artifact",
Type: schema.TypeStringArray,
Resolver: schema.PathResolver("OutputArtifacts.Name"),
},
{
Name: "region",
Description: "The action declaration's AWS Region, such as us-east-1",
Type: schema.TypeString,
IgnoreInTests: true,
},
{
Name: "role_arn",
Description: "The ARN of the IAM service role that performs the declared action",
Type: schema.TypeString,
IgnoreInTests: true,
},
{
Name: "run_order",
Description: "The order in which actions are run",
Type: schema.TypeBigInt,
},
},
},
},
},
},
}
}
// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================
func fetchCodepipelinePipelines(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
c := meta.(*client.Client)
svc := c.Services().CodePipeline
config := codepipeline.ListPipelinesInput{}
for {
response, err := svc.ListPipelines(ctx, &config)
if err != nil {
return diag.WrapError(err)
}
for i := range response.Pipelines {
response, err := svc.GetPipeline(ctx, &codepipeline.GetPipelineInput{Name: response.Pipelines[i].Name})
if err != nil {
if c.IsNotFoundError(err) {
continue
}
return diag.WrapError(err)
}
res <- response
}
if aws.ToString(response.NextToken) == "" {
break
}
config.NextToken = response.NextToken
}
return nil
}
func resolveCodepipelinePipelineTags(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource, c schema.Column) error {
pipeline := resource.Item.(*codepipeline.GetPipelineOutput)
cl := meta.(*client.Client)
svc := cl.Services().CodePipeline
response, err := svc.ListTagsForResource(ctx, &codepipeline.ListTagsForResourceInput{
ResourceArn: pipeline.Metadata.PipelineArn,
})
if err != nil {
return diag.WrapError(err)
}
return diag.WrapError(resource.Set(c.Name, client.TagsToMap(response.Tags)))
}
func fetchCodepipelinePipelineStages(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
type StageWrapper struct {
types.StageDeclaration
StageOrder int32
}
r := parent.Item.(*codepipeline.GetPipelineOutput)
for i, stage := range r.Pipeline.Stages {
res <- StageWrapper{
StageDeclaration: stage,
StageOrder: int32(i),
}
}
return nil
}