provider/fastly: Update Gzip handling with new go-fastly (#6334)

* provider/fastly: Bump to latest go-fastly

* provider/fastly: Update Gzip handling with new go-fastly
This commit is contained in:
Clint 2016-04-27 10:46:20 -05:00
parent ccedadc9ac
commit 813f2ca708
3 changed files with 5 additions and 25 deletions

2
Godeps/Godeps.json generated
View File

@ -1177,7 +1177,7 @@
}, },
{ {
"ImportPath": "github.com/sethvargo/go-fastly", "ImportPath": "github.com/sethvargo/go-fastly",
"Rev": "b00964ba5a45ca385e9299c9803d6d2a8105d65b" "Rev": "058f71c351c7fd4b7cf7e4604e827f9705a35ce0"
}, },
{ {
"ImportPath": "github.com/soniah/dnsmadeeasy", "ImportPath": "github.com/soniah/dnsmadeeasy",

View File

@ -616,22 +616,6 @@ func resourceServiceV1Update(d *schema.ResourceData, meta interface{}) error {
Name: df["name"].(string), Name: df["name"].(string),
} }
// Fastly API will fill in ContentTypes or Extensions with default
// values if they are omitted, which is not what we want. Ex: creating a
// gzip rule for content types of "text/html", and not supplying any
// extensions, will apply automatic values to extensions for css, js,
// html. Given Go's nature of default values, and go-fastly's usage of
// omitempty for empty strings, we need to pre-fill the ContentTypes and
// Extensions with and empty space " " in order to not receive the
// default values for each field. This space is checked and then ignored
// in the flattenGzips function.
//
// I've opened a support case with Fastly to find if this is a bug or
// feature. If feature, we'll update the go-fastly library to not use
// omitempty in the definition. If bug, we'll have to weather it until
// they fix it
opts.Extensions = " "
opts.ContentTypes = " "
if v, ok := df["content_types"]; ok { if v, ok := df["content_types"]; ok {
if len(v.(*schema.Set).List()) > 0 { if len(v.(*schema.Set).List()) > 0 {
var cl []string var cl []string
@ -1014,11 +998,7 @@ func flattenGzips(gzipsList []*gofastly.Gzip) []map[string]interface{} {
"cache_condition": g.CacheCondition, "cache_condition": g.CacheCondition,
} }
// Fastly API provides default values for Extensions or ContentTypes, in the if g.Extensions != "" {
// event that you do not specify them. To work around this, if they are
// omitted we'll use an empty space as a sentinel value to indicate not to
// include them, and filter on that
if g.Extensions != "" && g.Extensions != " " {
e := strings.Split(g.Extensions, " ") e := strings.Split(g.Extensions, " ")
var et []interface{} var et []interface{}
for _, ev := range e { for _, ev := range e {
@ -1027,7 +1007,7 @@ func flattenGzips(gzipsList []*gofastly.Gzip) []map[string]interface{} {
ng["extensions"] = schema.NewSet(schema.HashString, et) ng["extensions"] = schema.NewSet(schema.HashString, et)
} }
if g.ContentTypes != "" && g.ContentTypes != " " { if g.ContentTypes != "" {
c := strings.Split(g.ContentTypes, " ") c := strings.Split(g.ContentTypes, " ")
var ct []interface{} var ct []interface{}
for _, cv := range c { for _, cv := range c {

View File

@ -67,8 +67,8 @@ type CreateGzipInput struct {
Version string Version string
Name string `form:"name,omitempty"` Name string `form:"name,omitempty"`
ContentTypes string `form:"content_types,omitempty"` ContentTypes string `form:"content_types"`
Extensions string `form:"extensions,omitempty"` Extensions string `form:"extensions"`
CacheCondition string `form:"cache_condition,omitempty"` CacheCondition string `form:"cache_condition,omitempty"`
} }