diff --git a/go.mod b/go.mod index cd47348e40..39ac0bf7d7 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,12 @@ module github.com/terraform-providers/terraform-provider-cloudflare go 1.12 require ( - github.com/cloudflare/cloudflare-go v0.10.8 + github.com/cloudflare/cloudflare-go v0.10.9 github.com/hashicorp/go-cleanhttp v0.5.1 github.com/hashicorp/terraform-plugin-sdk v1.4.0 github.com/pkg/errors v0.8.1 golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect - golang.org/x/net v0.0.0-20191109021931-daa7c04131f5 + golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 golang.org/x/sys v0.0.0-20191010194322-b09406accb47 // indirect google.golang.org/genproto v0.0.0-20191009194640-548a555dbc03 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect diff --git a/go.sum b/go.sum index 8e2721e87e..a95f14411c 100644 --- a/go.sum +++ b/go.sum @@ -33,8 +33,8 @@ github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cloudflare/cloudflare-go v0.10.8 h1:waPdLF0S9hb9Q8unE3A/zFJDMaPI1xZNYu/WL0aw8rE= -github.com/cloudflare/cloudflare-go v0.10.8/go.mod h1:+LCrBrz3ssRmKHnlTwQOUmi3tMcNi0H5UqpMUgKkwcg= +github.com/cloudflare/cloudflare-go v0.10.9 h1:d8KOgLpYiC+Xq3T4tuO+/goM+RZvuO+T4pojuv8giL8= +github.com/cloudflare/cloudflare-go v0.10.9/go.mod h1:5TrsWH+3f4NV6WjtS5QFp+DifH81rph40gU374Sh0dQ= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -133,6 +133,7 @@ github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx github.com/mattn/go-isatty v0.0.5 h1:tHXDdz1cpzGaovsTB+TVB8q90WEokoVmfMqoVcrLUgw= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mitchellh/cli v1.0.0 h1:iGBIsUe3+HZ/AD/Vd7DErOt5sU9fa8Uj7A2s1aggv1Y= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= @@ -155,8 +156,7 @@ github.com/mitchellh/reflectwalk v1.0.1 h1:FVzMWA5RllMAKIdUSC8mdWo3XtwoecrH79BY7 github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= -github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= -github.com/olekukonko/tablewriter v0.0.2/go.mod h1:rSAaSIOAGT9odnlyGlUfAJaoc5w2fSBUmeGDbRWPxyQ= +github.com/olekukonko/tablewriter v0.0.3/go.mod h1:YZeBtGzYYEsCHp2LST/u/0NDwGkRoBtmn1cIWCJiS6M= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -180,7 +180,7 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/ulikunitz/xz v0.5.5 h1:pFrO0lVpTBXLpYw+pnLj6TbvHuyjXMfjGeCwSqCVwok= github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8= -github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/vmihailenco/msgpack v3.3.3+incompatible h1:wapg9xDUZDzGCNFlwc5SqI1rvcciqcxEHac4CYj89xI= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack v4.0.1+incompatible h1:RMF1enSPeKTlXrXdOcqjFUElywVZjjC6pqse21bKbEU= @@ -220,8 +220,8 @@ golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191009170851-d66e71096ffb/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191109021931-daa7c04131f5 h1:bHNaocaoJxYBo5cw41UyTMLjYlb8wPY7+WFrnklbHOM= -golang.org/x/net v0.0.0-20191109021931-daa7c04131f5/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 h1:e6HwijUxhDe+hPNjZQQn9bA5PW3vNmnN64U2ZW759Lk= +golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= diff --git a/vendor/github.com/cloudflare/cloudflare-go/go.mod b/vendor/github.com/cloudflare/cloudflare-go/go.mod index 12d7023ac3..e13f3c1829 100644 --- a/vendor/github.com/cloudflare/cloudflare-go/go.mod +++ b/vendor/github.com/cloudflare/cloudflare-go/go.mod @@ -4,10 +4,10 @@ go 1.11 require ( github.com/davecgh/go-spew v1.1.1 // indirect - github.com/olekukonko/tablewriter v0.0.2 + github.com/olekukonko/tablewriter v0.0.3 github.com/pkg/errors v0.8.1 github.com/stretchr/testify v1.4.0 - github.com/urfave/cli v1.22.1 - golang.org/x/net v0.0.0-20191109021931-daa7c04131f5 + github.com/urfave/cli v1.22.2 + golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 golang.org/x/time v0.0.0-20191024005414-555d28b269f0 ) diff --git a/vendor/github.com/cloudflare/cloudflare-go/go.sum b/vendor/github.com/cloudflare/cloudflare-go/go.sum index d3fbf18b56..8604e4a3fe 100644 --- a/vendor/github.com/cloudflare/cloudflare-go/go.sum +++ b/vendor/github.com/cloudflare/cloudflare-go/go.sum @@ -6,10 +6,14 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/mattn/go-runewidth v0.0.6 h1:V2iyH+aX9C5fsYCpK60U8BYIvmhqxuOL3JZcqc1NB7k= +github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8urCTFX88= github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= github.com/olekukonko/tablewriter v0.0.2 h1:sq53g+DWf0J6/ceFUHpQ0nAEb6WgM++fq16MZ91cS6o= github.com/olekukonko/tablewriter v0.0.2/go.mod h1:rSAaSIOAGT9odnlyGlUfAJaoc5w2fSBUmeGDbRWPxyQ= +github.com/olekukonko/tablewriter v0.0.3 h1:i0LBnzgiChAWHJYTQAZJDOgf8MNxAVYZJ2m63SIDimI= +github.com/olekukonko/tablewriter v0.0.3/go.mod h1:YZeBtGzYYEsCHp2LST/u/0NDwGkRoBtmn1cIWCJiS6M= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -23,6 +27,8 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo= +github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20191021144547-ec77196f6094 h1:5O4U9trLjNpuhpynaDsqwCk+Tw6seqJz1EbqbnzHrc8= golang.org/x/net v0.0.0-20191021144547-ec77196f6094/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -36,6 +42,11 @@ golang.org/x/net v0.0.0-20191108063844-7e6e90b9ea88 h1:Duq71GDCs3Cs8n6cRINv6SutZ golang.org/x/net v0.0.0-20191108063844-7e6e90b9ea88/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20191109021931-daa7c04131f5 h1:bHNaocaoJxYBo5cw41UyTMLjYlb8wPY7+WFrnklbHOM= golang.org/x/net v0.0.0-20191109021931-daa7c04131f5/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914 h1:MlY3mEfbnWGmUi4rtHOtNnnnN4UJRGSyLPx+DXA5Sq4= +golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191125084936-ffdde1057850 h1:Vq85/r8R9IdcUHmZ0/nQlUg1v15rzvQ2sHdnZAj/x7s= +golang.org/x/net v0.0.0-20191125084936-ffdde1057850/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/vendor/github.com/cloudflare/cloudflare-go/origin_ca.go b/vendor/github.com/cloudflare/cloudflare-go/origin_ca.go index fdd8c4273d..f10f3fcd7a 100644 --- a/vendor/github.com/cloudflare/cloudflare-go/origin_ca.go +++ b/vendor/github.com/cloudflare/cloudflare-go/origin_ca.go @@ -22,6 +22,38 @@ type OriginCACertificate struct { CSR string `json:"csr"` } +// UnmarshalJSON handles custom parsing from an API response to an OriginCACertificate +// http://choly.ca/post/go-json-marshalling/ +func (c *OriginCACertificate) UnmarshalJSON(data []byte) error { + type alias OriginCACertificate + + aux := &struct { + ExpiresOn string `json:"expires_on"` + *alias + }{ + alias: (*alias)(c), + } + + var err error + + if err = json.Unmarshal(data, &aux); err != nil { + return err + } + + // This format comes from time.Time.String() source + c.ExpiresOn, err = time.Parse("2006-01-02 15:04:05.999999999 -0700 MST", aux.ExpiresOn) + + if err != nil { + c.ExpiresOn, err = time.Parse(time.RFC3339, aux.ExpiresOn) + } + + if err != nil { + return err + } + + return nil +} + // OriginCACertificateListOptions represents the parameters used to list Cloudflare-issued certificates. type OriginCACertificateListOptions struct { ZoneID string diff --git a/vendor/github.com/cloudflare/cloudflare-go/waf.go b/vendor/github.com/cloudflare/cloudflare-go/waf.go index 9b67f79a7a..e1ce417b7c 100644 --- a/vendor/github.com/cloudflare/cloudflare-go/waf.go +++ b/vendor/github.com/cloudflare/cloudflare-go/waf.go @@ -2,6 +2,8 @@ package cloudflare import ( "encoding/json" + "net/url" + "strconv" "github.com/pkg/errors" ) @@ -101,26 +103,46 @@ type WAFRuleOptions struct { // // API Reference: https://api.cloudflare.com/#waf-rule-packages-list-firewall-packages func (api *API) ListWAFPackages(zoneID string) ([]WAFPackage, error) { - var p WAFPackagesResponse + // Construct a query string + v := url.Values{} + // Request as many WAF packages as possible per page - API max is 100 + v.Set("per_page", "100") + var packages []WAFPackage var res []byte var err error - uri := "/zones/" + zoneID + "/firewall/waf/packages" - res, err = api.makeRequest("GET", uri, nil) - if err != nil { - return []WAFPackage{}, errors.Wrap(err, errMakeRequestError) - } - err = json.Unmarshal(res, &p) - if err != nil { - return []WAFPackage{}, errors.Wrap(err, errUnmarshalError) - } - if !p.Success { - // TODO: Provide an actual error message instead of always returning nil - return []WAFPackage{}, err - } - for pi := range p.Result { - packages = append(packages, p.Result[pi]) + page := 1 + + // Loop over makeRequest until what we've fetched all records + for { + v.Set("page", strconv.Itoa(page)) + query := "?" + v.Encode() + uri := "/zones/" + zoneID + "/firewall/waf/packages" + query + res, err = api.makeRequest("GET", uri, nil) + if err != nil { + return []WAFPackage{}, errors.Wrap(err, errMakeRequestError) + } + + var p WAFPackagesResponse + err = json.Unmarshal(res, &p) + if err != nil { + return []WAFPackage{}, errors.Wrap(err, errUnmarshalError) + } + + if !p.Success { + // TODO: Provide an actual error message instead of always returning nil + return []WAFPackage{}, err + } + + packages = append(packages, p.Result...) + if p.ResultInfo.Page >= p.ResultInfo.TotalPages { + break + } + + // Loop around and fetch the next page + page++ } + return packages, nil } @@ -165,29 +187,44 @@ func (api *API) UpdateWAFPackage(zoneID, packageID string, opts WAFPackageOption // // API Reference: https://api.cloudflare.com/#waf-rule-groups-list-rule-groups func (api *API) ListWAFGroups(zoneID, packageID string) ([]WAFGroup, error) { + // Construct a query string + v := url.Values{} + // Request as many WAF groups as possible per page - API max is 100 + v.Set("per_page", "100") + var groups []WAFGroup var res []byte var err error - - uri := "/zones/" + zoneID + "/firewall/waf/packages/" + packageID + "/groups" - res, err = api.makeRequest("GET", uri, nil) - if err != nil { - return []WAFGroup{}, errors.Wrap(err, errMakeRequestError) - } - - var r WAFGroupsResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []WAFGroup{}, errors.Wrap(err, errUnmarshalError) - } - - if !r.Success { - // TODO: Provide an actual error message instead of always returning nil - return []WAFGroup{}, err - } - - for gi := range r.Result { - groups = append(groups, r.Result[gi]) + page := 1 + + // Loop over makeRequest until what we've fetched all records + for { + v.Set("page", strconv.Itoa(page)) + query := "?" + v.Encode() + uri := "/zones/" + zoneID + "/firewall/waf/packages/" + packageID + "/groups" + query + res, err = api.makeRequest("GET", uri, nil) + if err != nil { + return []WAFGroup{}, errors.Wrap(err, errMakeRequestError) + } + + var r WAFGroupsResponse + err = json.Unmarshal(res, &r) + if err != nil { + return []WAFGroup{}, errors.Wrap(err, errUnmarshalError) + } + + if !r.Success { + // TODO: Provide an actual error message instead of always returning nil + return []WAFGroup{}, err + } + + groups = append(groups, r.Result...) + if r.ResultInfo.Page >= r.ResultInfo.TotalPages { + break + } + + // Loop around and fetch the next page + page++ } return groups, nil } @@ -234,30 +271,46 @@ func (api *API) UpdateWAFGroup(zoneID, packageID, groupID, mode string) (WAFGrou // // API Reference: https://api.cloudflare.com/#waf-rules-list-rules func (api *API) ListWAFRules(zoneID, packageID string) ([]WAFRule, error) { + // Construct a query string + v := url.Values{} + // Request as many WAF rules as possible per page - API max is 100 + v.Set("per_page", "100") + var rules []WAFRule var res []byte var err error - - uri := "/zones/" + zoneID + "/firewall/waf/packages/" + packageID + "/rules" - res, err = api.makeRequest("GET", uri, nil) - if err != nil { - return []WAFRule{}, errors.Wrap(err, errMakeRequestError) + page := 1 + + // Loop over makeRequest until what we've fetched all records + for { + v.Set("page", strconv.Itoa(page)) + query := "?" + v.Encode() + uri := "/zones/" + zoneID + "/firewall/waf/packages/" + packageID + "/rules" + query + res, err = api.makeRequest("GET", uri, nil) + if err != nil { + return []WAFRule{}, errors.Wrap(err, errMakeRequestError) + } + + var r WAFRulesResponse + err = json.Unmarshal(res, &r) + if err != nil { + return []WAFRule{}, errors.Wrap(err, errUnmarshalError) + } + + if !r.Success { + // TODO: Provide an actual error message instead of always returning nil + return []WAFRule{}, err + } + + rules = append(rules, r.Result...) + if r.ResultInfo.Page >= r.ResultInfo.TotalPages { + break + } + + // Loop around and fetch the next page + page++ } - var r WAFRulesResponse - err = json.Unmarshal(res, &r) - if err != nil { - return []WAFRule{}, errors.Wrap(err, errUnmarshalError) - } - - if !r.Success { - // TODO: Provide an actual error message instead of always returning nil - return []WAFRule{}, err - } - - for ri := range r.Result { - rules = append(rules, r.Result[ri]) - } return rules, nil } diff --git a/vendor/github.com/cloudflare/cloudflare-go/zone.go b/vendor/github.com/cloudflare/cloudflare-go/zone.go index 1b7511f936..52014f9bf1 100644 --- a/vendor/github.com/cloudflare/cloudflare-go/zone.go +++ b/vendor/github.com/cloudflare/cloudflare-go/zone.go @@ -832,3 +832,14 @@ func (api *API) UpdateZoneSingleSetting(zoneID, settingName string, setting Zone return response, nil } + +// ZoneExport returns the text BIND config for the given zone +// +// API reference: https://api.cloudflare.com/#dns-records-for-a-zone-export-dns-records +func (api *API) ZoneExport(zoneID string) (string, error) { + res, err := api.makeRequest("GET", "/zones/"+zoneID+"/dns_records/export", nil) + if err != nil { + return "", errors.Wrap(err, errMakeRequestError) + } + return string(res), nil +} diff --git a/vendor/golang.org/x/net/http2/transport.go b/vendor/golang.org/x/net/http2/transport.go index 42ad181448..8e0059db66 100644 --- a/vendor/golang.org/x/net/http2/transport.go +++ b/vendor/golang.org/x/net/http2/transport.go @@ -227,6 +227,7 @@ type ClientConn struct { br *bufio.Reader fr *Framer lastActive time.Time + lastIdle time.Time // time last idle // Settings from peer: (also guarded by mu) maxFrameSize uint32 maxConcurrentStreams uint32 @@ -736,7 +737,8 @@ func (cc *ClientConn) idleStateLocked() (st clientConnIdleState) { } st.canTakeNewRequest = cc.goAway == nil && !cc.closed && !cc.closing && maxConcurrentOkay && - int64(cc.nextStreamID)+2*int64(cc.pendingRequests) < math.MaxInt32 + int64(cc.nextStreamID)+2*int64(cc.pendingRequests) < math.MaxInt32 && + !cc.tooIdleLocked() st.freshConn = cc.nextStreamID == 1 && st.canTakeNewRequest return } @@ -746,6 +748,16 @@ func (cc *ClientConn) canTakeNewRequestLocked() bool { return st.canTakeNewRequest } +// tooIdleLocked reports whether this connection has been been sitting idle +// for too much wall time. +func (cc *ClientConn) tooIdleLocked() bool { + // The Round(0) strips the monontonic clock reading so the + // times are compared based on their wall time. We don't want + // to reuse a connection that's been sitting idle during + // VM/laptop suspend if monotonic time was also frozen. + return cc.idleTimeout != 0 && !cc.lastIdle.IsZero() && time.Since(cc.lastIdle.Round(0)) > cc.idleTimeout +} + // onIdleTimeout is called from a time.AfterFunc goroutine. It will // only be called when we're idle, but because we're coming from a new // goroutine, there could be a new request coming in at the same time, @@ -1150,6 +1162,7 @@ func (cc *ClientConn) awaitOpenSlotForRequest(req *http.Request) error { } return errClientConnUnusable } + cc.lastIdle = time.Time{} if int64(len(cc.streams))+1 <= int64(cc.maxConcurrentStreams) { if waitingForConn != nil { close(waitingForConn) @@ -1638,6 +1651,7 @@ func (cc *ClientConn) streamByID(id uint32, andRemove bool) *clientStream { delete(cc.streams, id) if len(cc.streams) == 0 && cc.idleTimer != nil { cc.idleTimer.Reset(cc.idleTimeout) + cc.lastIdle = time.Now() } close(cs.done) // Wake up checkResetOrDone via clientStream.awaitFlowControl and diff --git a/vendor/modules.txt b/vendor/modules.txt index b8934ee81f..9dfe11bb4a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -56,7 +56,7 @@ github.com/aws/aws-sdk-go/service/sts/stsiface github.com/bgentry/go-netrc/netrc # github.com/bgentry/speakeasy v0.1.0 github.com/bgentry/speakeasy -# github.com/cloudflare/cloudflare-go v0.10.8 +# github.com/cloudflare/cloudflare-go v0.10.9 github.com/cloudflare/cloudflare-go # github.com/davecgh/go-spew v1.1.1 github.com/davecgh/go-spew/spew @@ -264,7 +264,7 @@ golang.org/x/crypto/openpgp/packet golang.org/x/crypto/openpgp/s2k golang.org/x/crypto/poly1305 golang.org/x/crypto/ssh -# golang.org/x/net v0.0.0-20191109021931-daa7c04131f5 +# golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 golang.org/x/net/context golang.org/x/net/context/ctxhttp golang.org/x/net/http/httpguts