Skip to content
This repository was archived by the owner on Mar 1, 2023. It is now read-only.

Commit 6ffd17c

Browse files
vvelikodnyVitaly Velikodny
andauthored
add 'ignore_query_string', 'query_params_whitelist', 'query_params_blacklist' options (#80)
Co-authored-by: Vitaly Velikodny <[email protected]>
1 parent 51e8387 commit 6ffd17c

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

gcore/resource_gcore_cdn_resource.go

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,65 @@ var (
234234
},
235235
},
236236
},
237+
"ignore_query_string": {
238+
Type: schema.TypeList,
239+
MaxItems: 1,
240+
Optional: true,
241+
Description: "",
242+
Elem: &schema.Resource{
243+
Schema: map[string]*schema.Schema{
244+
"enabled": {
245+
Type: schema.TypeBool,
246+
Optional: true,
247+
Default: true,
248+
},
249+
"value": {
250+
Type: schema.TypeBool,
251+
Required: true,
252+
},
253+
},
254+
},
255+
},
256+
"query_params_whitelist": {
257+
Type: schema.TypeList,
258+
MaxItems: 1,
259+
Optional: true,
260+
Description: "",
261+
Elem: &schema.Resource{
262+
Schema: map[string]*schema.Schema{
263+
"enabled": {
264+
Type: schema.TypeBool,
265+
Optional: true,
266+
Default: true,
267+
},
268+
"value": {
269+
Type: schema.TypeSet,
270+
Elem: &schema.Schema{Type: schema.TypeString},
271+
Required: true,
272+
},
273+
},
274+
},
275+
},
276+
"query_params_blacklist": {
277+
Type: schema.TypeList,
278+
MaxItems: 1,
279+
Optional: true,
280+
Description: "",
281+
Elem: &schema.Resource{
282+
Schema: map[string]*schema.Schema{
283+
"enabled": {
284+
Type: schema.TypeBool,
285+
Optional: true,
286+
Default: true,
287+
},
288+
"value": {
289+
Type: schema.TypeSet,
290+
Elem: &schema.Schema{Type: schema.TypeString},
291+
Required: true,
292+
},
293+
},
294+
},
295+
},
237296
},
238297
},
239298
}
@@ -544,6 +603,40 @@ func listToOptions(l []interface{}) *gcdn.Options {
544603
CustomHostname: opt["custom_hostname"].(string),
545604
}
546605
}
606+
if opt, ok := getOptByName(fields, "ignore_query_string"); ok {
607+
enabled := true
608+
if _, ok := opt["enabled"]; ok {
609+
enabled = opt["enabled"].(bool)
610+
}
611+
opts.IgnoreQueryString = &gcdn.IgnoreQueryString{
612+
Enabled: enabled,
613+
Value: opt["value"].(bool),
614+
}
615+
}
616+
if opt, ok := getOptByName(fields, "query_params_whitelist"); ok {
617+
enabled := true
618+
if _, ok := opt["enabled"]; ok {
619+
enabled = opt["enabled"].(bool)
620+
}
621+
opts.QueryParamsWhitelist = &gcdn.QueryParamsWhitelist{
622+
Enabled: enabled,
623+
}
624+
for _, v := range opt["value"].(*schema.Set).List() {
625+
opts.QueryParamsWhitelist.Value = append(opts.QueryParamsWhitelist.Value, v.(string))
626+
}
627+
}
628+
if opt, ok := getOptByName(fields, "query_params_blacklist"); ok {
629+
enabled := true
630+
if _, ok := opt["enabled"]; ok {
631+
enabled = opt["enabled"].(bool)
632+
}
633+
opts.QueryParamsBlacklist = &gcdn.QueryParamsBlacklist{
634+
Enabled: enabled,
635+
}
636+
for _, v := range opt["value"].(*schema.Set).List() {
637+
opts.QueryParamsBlacklist.Value = append(opts.QueryParamsBlacklist.Value, v.(string))
638+
}
639+
}
547640
return &opts
548641
}
549642

@@ -607,6 +700,18 @@ func optionsToList(options *gcdn.Options) []interface{} {
607700
m := structToMap(options.SNI)
608701
result["sni"] = []interface{}{m}
609702
}
703+
if options.IgnoreQueryString != nil {
704+
m := structToMap(options.IgnoreQueryString)
705+
result["ignore_query_string"] = []interface{}{m}
706+
}
707+
if options.QueryParamsWhitelist != nil {
708+
m := structToMap(options.QueryParamsWhitelist)
709+
result["query_params_whitelist"] = []interface{}{m}
710+
}
711+
if options.QueryParamsBlacklist != nil {
712+
m := structToMap(options.QueryParamsBlacklist)
713+
result["query_params_blacklist"] = []interface{}{m}
714+
}
610715
return []interface{}{result}
611716
}
612717

0 commit comments

Comments
 (0)