This repository has been archived by the owner on Aug 16, 2022. It is now read-only.
/
cache_policies.go
181 lines (175 loc) · 7.98 KB
/
cache_policies.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
package cloudfront
import (
"context"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudfront"
"github.com/aws/aws-sdk-go-v2/service/cloudfront/types"
"github.com/cloudquery/cq-provider-aws/client"
"github.com/cloudquery/cq-provider-sdk/provider/diag"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
)
func CloudfrontCachePolicies() *schema.Table {
return &schema.Table{
Name: "aws_cloudfront_cache_policies",
Description: "Contains a cache policy.",
Resolver: fetchCloudfrontCachePolicies,
Multiplex: client.AccountMultiplex,
IgnoreError: client.IgnoreCommonErrors,
DeleteFilter: client.DeleteAccountFilter,
Options: schema.TableCreationOptions{PrimaryKeys: []string{"account_id", "id"}},
Columns: []schema.Column{
{
Name: "account_id",
Description: "The AWS Account ID of the resource.",
Type: schema.TypeString,
Resolver: client.ResolveAWSAccount,
},
{
Name: "arn",
Description: "The Amazon Resource Name (ARN) for the resource.",
Type: schema.TypeString,
Resolver: client.ResolveARNWithAccount(client.CloudfrontService, func(resource *schema.Resource) ([]string, error) {
return []string{"cache-policy", *resource.Item.(types.CachePolicySummary).CachePolicy.Id}, nil
}),
},
{
Name: "min_ttl",
Description: "The minimum amount of time, in seconds, that you want objects to stay in the CloudFront cache before CloudFront sends another request to the origin to see if the object has been updated",
Type: schema.TypeBigInt,
Resolver: schema.PathResolver("CachePolicy.CachePolicyConfig.MinTTL"),
},
{
Name: "name",
Description: "A unique name to identify the cache policy",
Type: schema.TypeString,
Resolver: schema.PathResolver("CachePolicy.CachePolicyConfig.Name"),
},
{
Name: "comment",
Description: "A comment to describe the cache policy",
Type: schema.TypeString,
Resolver: schema.PathResolver("CachePolicy.CachePolicyConfig.Comment"),
},
{
Name: "default_ttl",
Description: "The default amount of time, in seconds, that you want objects to stay in the CloudFront cache before CloudFront sends another request to the origin to see if the object has been updated",
Type: schema.TypeBigInt,
Resolver: schema.PathResolver("CachePolicy.CachePolicyConfig.DefaultTTL"),
},
{
Name: "max_ttl",
Description: "The maximum amount of time, in seconds, that objects stay in the CloudFront cache before CloudFront sends another request to the origin to see if the object has been updated",
Type: schema.TypeBigInt,
Resolver: schema.PathResolver("CachePolicy.CachePolicyConfig.MaxTTL"),
},
{
Name: "cookies_behavior",
Description: "Determines whether any cookies in viewer requests are included in the cache key and automatically included in requests that CloudFront sends to the origin",
Type: schema.TypeString,
Resolver: schema.PathResolver("CachePolicy.CachePolicyConfig.ParametersInCacheKeyAndForwardedToOrigin.CookiesConfig.CookieBehavior"),
},
{
Name: "cookies_quantity",
Description: "The number of cookie names in the Items list",
Type: schema.TypeInt,
Resolver: schema.PathResolver("CachePolicy.CachePolicyConfig.ParametersInCacheKeyAndForwardedToOrigin.CookiesConfig.Cookies.Quantity"),
IgnoreInTests: true,
},
{
Name: "cookies",
Description: "A list of cookie names",
Type: schema.TypeStringArray,
Resolver: schema.PathResolver("CachePolicy.CachePolicyConfig.ParametersInCacheKeyAndForwardedToOrigin.CookiesConfig.Cookies.Items"),
IgnoreInTests: true,
},
{
Name: "enable_accept_encoding_gzip",
Description: "A flag that can affect whether the Accept-Encoding HTTP header is included in the cache key and included in requests that CloudFront sends to the origin",
Type: schema.TypeBool,
Resolver: schema.PathResolver("CachePolicy.CachePolicyConfig.ParametersInCacheKeyAndForwardedToOrigin.EnableAcceptEncodingGzip"),
},
{
Name: "headers_behavior",
Description: "Determines whether any HTTP headers are included in the cache key and automatically included in requests that CloudFront sends to the origin",
Type: schema.TypeString,
Resolver: schema.PathResolver("CachePolicy.CachePolicyConfig.ParametersInCacheKeyAndForwardedToOrigin.HeadersConfig.HeaderBehavior"),
},
{
Name: "headers_quantity",
Description: "The number of header names in the Items list",
Type: schema.TypeInt,
Resolver: schema.PathResolver("CachePolicy.CachePolicyConfig.ParametersInCacheKeyAndForwardedToOrigin.HeadersConfig.Headers.Quantity"),
},
{
Name: "headers",
Description: "A list of HTTP header names",
Type: schema.TypeStringArray,
Resolver: schema.PathResolver("CachePolicy.CachePolicyConfig.ParametersInCacheKeyAndForwardedToOrigin.HeadersConfig.Headers.Items"),
},
{
Name: "query_strings_behavior",
Description: "Determines whether any URL query strings in viewer requests are included in the cache key and automatically included in requests that CloudFront sends to the origin",
Type: schema.TypeString,
Resolver: schema.PathResolver("CachePolicy.CachePolicyConfig.ParametersInCacheKeyAndForwardedToOrigin.QueryStringsConfig.QueryStringBehavior"),
},
{
Name: "query_strings_quantity",
Description: "The number of query string names in the Items list",
Type: schema.TypeInt,
Resolver: schema.PathResolver("CachePolicy.CachePolicyConfig.ParametersInCacheKeyAndForwardedToOrigin.QueryStringsConfig.QueryStrings.Quantity"),
},
{
Name: "query_strings",
Description: "A list of query string names",
Type: schema.TypeStringArray,
Resolver: schema.PathResolver("CachePolicy.CachePolicyConfig.ParametersInCacheKeyAndForwardedToOrigin.QueryStringsConfig.QueryStrings.Items"),
},
{
Name: "enable_accept_encoding_brotli",
Description: "A flag that can affect whether the Accept-Encoding HTTP header is included in the cache key and included in requests that CloudFront sends to the origin",
Type: schema.TypeBool,
Resolver: schema.PathResolver("CachePolicy.CachePolicyConfig.ParametersInCacheKeyAndForwardedToOrigin.EnableAcceptEncodingBrotli"),
},
{
Name: "id",
Description: "The unique identifier for the cache policy",
Type: schema.TypeString,
Resolver: schema.PathResolver("CachePolicy.Id"),
},
{
Name: "last_modified_time",
Description: "The date and time when the cache policy was last modified",
Type: schema.TypeTimestamp,
Resolver: schema.PathResolver("CachePolicy.LastModifiedTime"),
},
{
Name: "type",
Description: "The type of cache policy, either managed (created by AWS) or custom (created in this AWS account)",
Type: schema.TypeString,
},
},
}
}
// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================
func fetchCloudfrontCachePolicies(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
var config cloudfront.ListCachePoliciesInput
c := meta.(*client.Client)
s := c.Services()
svc := s.Cloudfront
for {
response, err := svc.ListCachePolicies(ctx, nil)
if err != nil {
return diag.WrapError(err)
}
if response.CachePolicyList != nil {
res <- response.CachePolicyList.Items
}
if aws.ToString(response.CachePolicyList.NextMarker) == "" {
break
}
config.Marker = response.CachePolicyList.NextMarker
}
return nil
}