From e59e22dc5b8a92665a66036f7a595288f2888ce5 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Wed, 27 Mar 2019 10:50:42 +1100 Subject: [PATCH 1/4] Bump cloudflare-go to ce422d1b74b3 --- go.mod | 2 +- go.sum | 4 +- .../cloudflare/cloudflare-go/.travis.yml | 15 +- .../cloudflare-go/account_members.go | 20 ++ .../cloudflare/cloudflare-go/duration.go | 40 ++++ .../cloudflare/cloudflare-go/errors.go | 1 + .../cloudflare-go/load_balancing.go | 44 +++++ .../cloudflare/cloudflare-go/rate_limiting.go | 2 +- .../cloudflare/cloudflare-go/registrar.go | 175 ++++++++++++++++++ .../golang.org/x/crypto/poly1305/mac_noasm.go | 11 ++ .../poly1305/{sum_ref.go => sum_generic.go} | 121 +++++++----- vendor/modules.txt | 2 +- 12 files changed, 376 insertions(+), 61 deletions(-) create mode 100644 vendor/github.com/cloudflare/cloudflare-go/duration.go create mode 100644 vendor/github.com/cloudflare/cloudflare-go/registrar.go create mode 100644 vendor/golang.org/x/crypto/poly1305/mac_noasm.go rename vendor/golang.org/x/crypto/poly1305/{sum_ref.go => sum_generic.go} (54%) diff --git a/go.mod b/go.mod index c87b403298..5b0cb71860 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/armon/go-radix v1.0.0 // indirect github.com/aws/aws-sdk-go v1.18.3 // indirect github.com/blang/semver v3.5.1+incompatible // indirect - github.com/cloudflare/cloudflare-go v0.0.0-20190123152938-9837a599c0ba + github.com/cloudflare/cloudflare-go v0.8.6-0.20190326234830-ce422d1b74b3 github.com/hashicorp/go-cleanhttp v0.5.0 github.com/hashicorp/go-getter v1.2.0 // indirect github.com/hashicorp/go-hclog v0.8.0 // indirect diff --git a/go.sum b/go.sum index 4956cdd085..68a170a317 100644 --- a/go.sum +++ b/go.sum @@ -68,8 +68,8 @@ github.com/chzyer/readline v0.0.0-20161106042343-c914be64f07d/go.mod h1:nSuG5e5P github.com/chzyer/test v0.0.0-20160617131543-bea8f082b6fd/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cloudflare/cloudflare-go v0.0.0-20190123152938-9837a599c0ba h1:BneYz3wK+QFvatwOnkKWm/lwA1Ix+kOV1whaDaG8Xz0= -github.com/cloudflare/cloudflare-go v0.0.0-20190123152938-9837a599c0ba/go.mod h1:qKQ9S///VKEax9N8kFel9/AvmnkYgvb8uiKTnoVFvpg= +github.com/cloudflare/cloudflare-go v0.8.6-0.20190326234830-ce422d1b74b3 h1:0dNTaRXwkmW8cyENqbaMsDGQjH1ZOUErEC07mBSvhQc= +github.com/cloudflare/cloudflare-go v0.8.6-0.20190326234830-ce422d1b74b3/go.mod h1:qKQ9S///VKEax9N8kFel9/AvmnkYgvb8uiKTnoVFvpg= github.com/codegangsta/cli v1.20.0/go.mod h1:/qJNoX69yVSKu5o4jLyXAENLRyk1uhi7zkbQ3slBdOA= github.com/coreos/bbolt v1.3.1-coreos.1/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.2.0-rc.1.0.20170908195435-80aa810309d4+incompatible h1:VLCxgrfBsnJtqTy0WFP0GsjjwWZQiuQiNgiWnY6g6Gc= diff --git a/vendor/github.com/cloudflare/cloudflare-go/.travis.yml b/vendor/github.com/cloudflare/cloudflare-go/.travis.yml index ec1e9fc650..1c2aeb930a 100644 --- a/vendor/github.com/cloudflare/cloudflare-go/.travis.yml +++ b/vendor/github.com/cloudflare/cloudflare-go/.travis.yml @@ -3,25 +3,16 @@ sudo: false env: global: - - MOD_VENDOR="" + - MOD_VENDOR="-mod=vendor" + - GO111MODULE=on matrix: fast_finish: true include: - - go: 1.10.x - go: 1.11.x - env: - - GO111MODULE=on - - MOD_VENDOR="-mod=vendor" + - go: 1.12.x - go: 1.x - env: - - LATEST=true - - GO111MODULE=on - - MOD_VENDOR="-mod=vendor" - go: tip - env: - - GO111MODULE=on - - MOD_VENDOR="-mod=vendor" allow_failures: - go: tip diff --git a/vendor/github.com/cloudflare/cloudflare-go/account_members.go b/vendor/github.com/cloudflare/cloudflare-go/account_members.go index f8f8c65316..42166e922f 100644 --- a/vendor/github.com/cloudflare/cloudflare-go/account_members.go +++ b/vendor/github.com/cloudflare/cloudflare-go/account_members.go @@ -56,6 +56,10 @@ type AccountMemberInvitation struct { // // API reference: https://api.cloudflare.com/#accounts-list-accounts func (api *API) AccountMembers(accountID string, pageOpts PaginationOptions) ([]AccountMember, ResultInfo, error) { + if accountID == "" { + return []AccountMember{}, ResultInfo{}, errors.New(errMissingAccountID) + } + v := url.Values{} if pageOpts.PerPage > 0 { v.Set("per_page", strconv.Itoa(pageOpts.PerPage)) @@ -87,6 +91,10 @@ func (api *API) AccountMembers(accountID string, pageOpts PaginationOptions) ([] // // API reference: https://api.cloudflare.com/#account-members-add-member func (api *API) CreateAccountMember(accountID string, emailAddress string, roles []string) (AccountMember, error) { + if accountID == "" { + return AccountMember{}, errors.New(errMissingAccountID) + } + uri := "/accounts/" + accountID + "/members" var newMember = AccountMemberInvitation{ @@ -111,6 +119,10 @@ func (api *API) CreateAccountMember(accountID string, emailAddress string, roles // // API reference: https://api.cloudflare.com/#account-members-remove-member func (api *API) DeleteAccountMember(accountID string, userID string) error { + if accountID == "" { + return errors.New(errMissingAccountID) + } + uri := fmt.Sprintf("/accounts/%s/members/%s", accountID, userID) _, err := api.makeRequest("DELETE", uri, nil) @@ -125,6 +137,10 @@ func (api *API) DeleteAccountMember(accountID string, userID string) error { // // API reference: https://api.cloudflare.com/#account-members-update-member func (api *API) UpdateAccountMember(accountID string, userID string, member AccountMember) (AccountMember, error) { + if accountID == "" { + return AccountMember{}, errors.New(errMissingAccountID) + } + uri := fmt.Sprintf("/accounts/%s/members/%s", accountID, userID) res, err := api.makeRequest("PUT", uri, member) @@ -145,6 +161,10 @@ func (api *API) UpdateAccountMember(accountID string, userID string, member Acco // // API reference: https://api.cloudflare.com/#account-members-member-details func (api *API) AccountMember(accountID string, memberID string) (AccountMember, error) { + if accountID == "" { + return AccountMember{}, errors.New(errMissingAccountID) + } + uri := fmt.Sprintf( "/accounts/%s/members/%s", accountID, diff --git a/vendor/github.com/cloudflare/cloudflare-go/duration.go b/vendor/github.com/cloudflare/cloudflare-go/duration.go new file mode 100644 index 0000000000..ba2418acda --- /dev/null +++ b/vendor/github.com/cloudflare/cloudflare-go/duration.go @@ -0,0 +1,40 @@ +package cloudflare + +import ( + "encoding/json" + "time" +) + +// Duration implements json.Marshaler and json.Unmarshaler for time.Duration +// using the fmt.Stringer interface of time.Duration and time.ParseDuration. +type Duration struct { + time.Duration +} + +// MarshalJSON encodes a Duration as a JSON string formatted using String. +func (d Duration) MarshalJSON() ([]byte, error) { + return json.Marshal(d.Duration.String()) +} + +// UnmarshalJSON decodes a Duration from a JSON string parsed using time.ParseDuration. +func (d *Duration) UnmarshalJSON(buf []byte) error { + var str string + + err := json.Unmarshal(buf, &str) + if err != nil { + return err + } + + dur, err := time.ParseDuration(str) + if err != nil { + return err + } + + d.Duration = dur + return nil +} + +var ( + _ = json.Marshaler((*Duration)(nil)) + _ = json.Unmarshaler((*Duration)(nil)) +) diff --git a/vendor/github.com/cloudflare/cloudflare-go/errors.go b/vendor/github.com/cloudflare/cloudflare-go/errors.go index 2fff3db304..bc23631f34 100644 --- a/vendor/github.com/cloudflare/cloudflare-go/errors.go +++ b/vendor/github.com/cloudflare/cloudflare-go/errors.go @@ -6,6 +6,7 @@ const ( errMakeRequestError = "error from makeRequest" errUnmarshalError = "error unmarshalling the JSON response" errRequestNotSuccessful = "error reported by API" + errMissingAccountID = "account ID is empty and must be provided" ) var _ Error = &UserError{} diff --git a/vendor/github.com/cloudflare/cloudflare-go/load_balancing.go b/vendor/github.com/cloudflare/cloudflare-go/load_balancing.go index 3d65a6be24..eeefbaba3b 100644 --- a/vendor/github.com/cloudflare/cloudflare-go/load_balancing.go +++ b/vendor/github.com/cloudflare/cloudflare-go/load_balancing.go @@ -51,6 +51,7 @@ type LoadBalancerMonitor struct { ExpectedCodes string `json:"expected_codes"` FollowRedirects bool `json:"follow_redirects"` AllowInsecure bool `json:"allow_insecure"` + ProbeZone string `json:"probe_zone"` } // LoadBalancer represents a load balancer's properties. @@ -73,10 +74,31 @@ type LoadBalancer struct { // "off" select pools in DefaultPools order // "geo" select pools based on RegionPools/PopPools // "dynamic_latency" select pools based on RTT (requires health checks) + // "random" selects pools in a random order // "" maps to "geo" if RegionPools or PopPools have entries otherwise "off" SteeringPolicy string `json:"steering_policy,omitempty"` } +// LoadBalancerOriginHealth represents the health of the origin. +type LoadBalancerOriginHealth struct { + Healthy bool `json:"healthy,omitempty"` + RTT Duration `json:"rtt,omitempty"` + FailureReason string `json:"failure_reason,omitempty"` + ResponseCode int `json:"response_code,omitempty"` +} + +// LoadBalancerPoolPopHealth represents the health of the pool for given PoP. +type LoadBalancerPoolPopHealth struct { + Healthy bool `json:"healthy,omitempty"` + Origins []map[string]LoadBalancerOriginHealth `json:"origins,omitempty"` +} + +// LoadBalancerPoolHealth represents the healthchecks from different PoPs for a pool. +type LoadBalancerPoolHealth struct { + ID string `json:"pool_id,omitempty"` + PopHealth map[string]LoadBalancerPoolPopHealth `json:"pop_health,omitempty"` +} + // loadBalancerPoolResponse represents the response from the load balancer pool endpoints. type loadBalancerPoolResponse struct { Response @@ -116,6 +138,12 @@ type loadBalancerListResponse struct { ResultInfo ResultInfo `json:"result_info"` } +// loadBalancerPoolHealthResponse represents the response from the Pool Health Details endpoint. +type loadBalancerPoolHealthResponse struct { + Response + Result LoadBalancerPoolHealth `json:"result"` +} + // CreateLoadBalancerPool creates a new load balancer pool. // // API reference: https://api.cloudflare.com/#load-balancer-pools-create-a-pool @@ -340,3 +368,19 @@ func (api *API) ModifyLoadBalancer(zoneID string, lb LoadBalancer) (LoadBalancer } return r.Result, nil } + +// PoolHealthDetails fetches the latest healtcheck details for a single pool. +// +// API reference: https://api.cloudflare.com/#load-balancer-pools-pool-health-details +func (api *API) PoolHealthDetails(poolID string) (LoadBalancerPoolHealth, error) { + uri := api.userBaseURL("/user") + "/load_balancers/pools/" + poolID + "/health" + res, err := api.makeRequest("GET", uri, nil) + if err != nil { + return LoadBalancerPoolHealth{}, errors.Wrap(err, errMakeRequestError) + } + var r loadBalancerPoolHealthResponse + if err := json.Unmarshal(res, &r); err != nil { + return LoadBalancerPoolHealth{}, errors.Wrap(err, errUnmarshalError) + } + return r.Result, nil +} diff --git a/vendor/github.com/cloudflare/cloudflare-go/rate_limiting.go b/vendor/github.com/cloudflare/cloudflare-go/rate_limiting.go index 253c44b1fe..e3eb3e2e7b 100644 --- a/vendor/github.com/cloudflare/cloudflare-go/rate_limiting.go +++ b/vendor/github.com/cloudflare/cloudflare-go/rate_limiting.go @@ -18,7 +18,7 @@ type RateLimit struct { Threshold int `json:"threshold"` Period int `json:"period"` Action RateLimitAction `json:"action"` - Correlate RateLimitCorrelate `json:"correlate"` + Correlate *RateLimitCorrelate `json:"correlate,omitempty"` } // RateLimitTrafficMatcher contains the rules that will be used to apply a rate limit to traffic diff --git a/vendor/github.com/cloudflare/cloudflare-go/registrar.go b/vendor/github.com/cloudflare/cloudflare-go/registrar.go new file mode 100644 index 0000000000..51eacf173a --- /dev/null +++ b/vendor/github.com/cloudflare/cloudflare-go/registrar.go @@ -0,0 +1,175 @@ +package cloudflare + +import ( + "encoding/json" + "fmt" + "time" + + "github.com/pkg/errors" +) + +// RegistrarDomain is the structure of the API response for a new +// Cloudflare Registrar domain. +type RegistrarDomain struct { + ID string `json:"id"` + Available bool `json:"available"` + SupportedTLD bool `json:"supported_tld"` + CanRegister bool `json:"can_register"` + TransferIn RegistrarTransferIn `json:"transfer_in"` + CurrentRegistrar string `json:"current_registrar"` + ExpiresAt time.Time `json:"expires_at"` + RegistryStatuses string `json:"registry_statuses"` + Locked bool `json:"locked"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + RegistrantContact RegistrantContact `json:"registrant_contact"` +} + +// RegistrarTransferIn contains the structure for a domain transfer in +// request. +type RegistrarTransferIn struct { + UnlockDomain string `json:"unlock_domain"` + DisablePrivacy string `json:"disable_privacy"` + EnterAuthCode string `json:"enter_auth_code"` + ApproveTransfer string `json:"approve_transfer"` + AcceptFoa string `json:"accept_foa"` + CanCancelTransfer bool `json:"can_cancel_transfer"` +} + +// RegistrantContact is the contact details for the domain registration. +type RegistrantContact struct { + ID string `json:"id"` + FirstName string `json:"first_name"` + LastName string `json:"last_name"` + Organization string `json:"organization"` + Address string `json:"address"` + Address2 string `json:"address2"` + City string `json:"city"` + State string `json:"state"` + Zip string `json:"zip"` + Country string `json:"country"` + Phone string `json:"phone"` + Email string `json:"email"` + Fax string `json:"fax"` +} + +// RegistrarDomainConfiguration is the structure for making updates to +// and existing domain. +type RegistrarDomainConfiguration struct { + NameServers []string `json:"name_servers"` + Privacy bool `json:"privacy"` + Locked bool `json:"locked"` + AutoRenew bool `json:"auto_renew"` +} + +// RegistrarDomainDetailResponse is the structure of the detailed +// response from the API for a single domain. +type RegistrarDomainDetailResponse struct { + Response + Result RegistrarDomain `json:"result"` +} + +// RegistrarDomainsDetailResponse is the structure of the detailed +// response from the API. +type RegistrarDomainsDetailResponse struct { + Response + Result []RegistrarDomain `json:"result"` +} + +// RegistrarDomain returns a single domain based on the account ID and +// domain name. +// +// API reference: https://api.cloudflare.com/#registrar-domains-get-domain +func (api *API) RegistrarDomain(accountID, domainName string) (RegistrarDomain, error) { + uri := fmt.Sprintf("/accounts/%s/registrar/domains/%s", accountID, domainName) + + res, err := api.makeRequest("GET", uri, nil) + if err != nil { + return RegistrarDomain{}, errors.Wrap(err, errMakeRequestError) + } + + var r RegistrarDomainDetailResponse + err = json.Unmarshal(res, &r) + if err != nil { + return RegistrarDomain{}, errors.Wrap(err, errUnmarshalError) + } + return r.Result, nil +} + +// RegistrarDomains returns all registrar domains based on the account +// ID. +// +// API reference: https://api.cloudflare.com/#registrar-domains-list-domains +func (api *API) RegistrarDomains(accountID string) ([]RegistrarDomain, error) { + uri := "/accounts/" + accountID + "/registrar/domains" + + res, err := api.makeRequest("POST", uri, nil) + if err != nil { + return []RegistrarDomain{}, errors.Wrap(err, errMakeRequestError) + } + + var r RegistrarDomainsDetailResponse + err = json.Unmarshal(res, &r) + if err != nil { + return []RegistrarDomain{}, errors.Wrap(err, errUnmarshalError) + } + return r.Result, nil +} + +// TransferRegistrarDomain initiates the transfer from another registrar +// to Cloudflare Registrar. +// +// API reference: https://api.cloudflare.com/#registrar-domains-transfer-domain +func (api *API) TransferRegistrarDomain(accountID, domainName string) ([]RegistrarDomain, error) { + uri := fmt.Sprintf("/accounts/%s/registrar/domains/%s/transfer", accountID, domainName) + + res, err := api.makeRequest("POST", uri, nil) + if err != nil { + return []RegistrarDomain{}, errors.Wrap(err, errMakeRequestError) + } + + var r RegistrarDomainsDetailResponse + err = json.Unmarshal(res, &r) + if err != nil { + return []RegistrarDomain{}, errors.Wrap(err, errUnmarshalError) + } + return r.Result, nil +} + +// CancelRegistrarDomainTransfer cancels a pending domain transfer. +// +// API reference: https://api.cloudflare.com/#registrar-domains-cancel-transfer +func (api *API) CancelRegistrarDomainTransfer(accountID, domainName string) ([]RegistrarDomain, error) { + uri := fmt.Sprintf("/accounts/%s/registrar/domains/%s/cancel_transfer", accountID, domainName) + + res, err := api.makeRequest("POST", uri, nil) + if err != nil { + return []RegistrarDomain{}, errors.Wrap(err, errMakeRequestError) + } + + var r RegistrarDomainsDetailResponse + err = json.Unmarshal(res, &r) + if err != nil { + return []RegistrarDomain{}, errors.Wrap(err, errUnmarshalError) + } + return r.Result, nil +} + +// UpdateRegistrarDomain updates an existing Registrar Domain configuration. +// +// API reference: https://api.cloudflare.com/#registrar-domains-update-domain +func (api *API) UpdateRegistrarDomain(accountID, domainName string, domainConfiguration RegistrarDomainConfiguration) (RegistrarDomain, error) { + uri := fmt.Sprintf("/accounts/%s/registrar/domains/%s", accountID, domainName) + + res, err := api.makeRequest("PUT", uri, domainConfiguration) + if err != nil { + return RegistrarDomain{}, errors.Wrap(err, errMakeRequestError) + } + + var r RegistrarDomainDetailResponse + err = json.Unmarshal(res, &r) + if err != nil { + return RegistrarDomain{}, errors.Wrap(err, errUnmarshalError) + } + return r.Result, nil +} diff --git a/vendor/golang.org/x/crypto/poly1305/mac_noasm.go b/vendor/golang.org/x/crypto/poly1305/mac_noasm.go new file mode 100644 index 0000000000..8387d29998 --- /dev/null +++ b/vendor/golang.org/x/crypto/poly1305/mac_noasm.go @@ -0,0 +1,11 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !amd64 gccgo appengine + +package poly1305 + +type mac struct{ macGeneric } + +func newMAC(key *[32]byte) mac { return mac{newMACGeneric(key)} } diff --git a/vendor/golang.org/x/crypto/poly1305/sum_ref.go b/vendor/golang.org/x/crypto/poly1305/sum_generic.go similarity index 54% rename from vendor/golang.org/x/crypto/poly1305/sum_ref.go rename to vendor/golang.org/x/crypto/poly1305/sum_generic.go index c4d59bd098..bab76ef0d8 100644 --- a/vendor/golang.org/x/crypto/poly1305/sum_ref.go +++ b/vendor/golang.org/x/crypto/poly1305/sum_generic.go @@ -1,4 +1,4 @@ -// Copyright 2012 The Go Authors. All rights reserved. +// Copyright 2018 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -6,21 +6,79 @@ package poly1305 import "encoding/binary" +const ( + msgBlock = uint32(1 << 24) + finalBlock = uint32(0) +) + // sumGeneric generates an authenticator for msg using a one-time key and // puts the 16-byte result into out. This is the generic implementation of // Sum and should be called if no assembly implementation is available. func sumGeneric(out *[TagSize]byte, msg []byte, key *[32]byte) { - var ( - h0, h1, h2, h3, h4 uint32 // the hash accumulators - r0, r1, r2, r3, r4 uint64 // the r part of the key - ) + h := newMACGeneric(key) + h.Write(msg) + h.Sum(out) +} + +func newMACGeneric(key *[32]byte) (h macGeneric) { + h.r[0] = binary.LittleEndian.Uint32(key[0:]) & 0x3ffffff + h.r[1] = (binary.LittleEndian.Uint32(key[3:]) >> 2) & 0x3ffff03 + h.r[2] = (binary.LittleEndian.Uint32(key[6:]) >> 4) & 0x3ffc0ff + h.r[3] = (binary.LittleEndian.Uint32(key[9:]) >> 6) & 0x3f03fff + h.r[4] = (binary.LittleEndian.Uint32(key[12:]) >> 8) & 0x00fffff + + h.s[0] = binary.LittleEndian.Uint32(key[16:]) + h.s[1] = binary.LittleEndian.Uint32(key[20:]) + h.s[2] = binary.LittleEndian.Uint32(key[24:]) + h.s[3] = binary.LittleEndian.Uint32(key[28:]) + return +} + +type macGeneric struct { + h, r [5]uint32 + s [4]uint32 + + buffer [TagSize]byte + offset int +} + +func (h *macGeneric) Write(p []byte) (n int, err error) { + n = len(p) + if h.offset > 0 { + remaining := TagSize - h.offset + if n < remaining { + h.offset += copy(h.buffer[h.offset:], p) + return n, nil + } + copy(h.buffer[h.offset:], p[:remaining]) + p = p[remaining:] + h.offset = 0 + updateGeneric(h.buffer[:], msgBlock, &(h.h), &(h.r)) + } + if nn := len(p) - (len(p) % TagSize); nn > 0 { + updateGeneric(p, msgBlock, &(h.h), &(h.r)) + p = p[nn:] + } + if len(p) > 0 { + h.offset += copy(h.buffer[h.offset:], p) + } + return n, nil +} - r0 = uint64(binary.LittleEndian.Uint32(key[0:]) & 0x3ffffff) - r1 = uint64((binary.LittleEndian.Uint32(key[3:]) >> 2) & 0x3ffff03) - r2 = uint64((binary.LittleEndian.Uint32(key[6:]) >> 4) & 0x3ffc0ff) - r3 = uint64((binary.LittleEndian.Uint32(key[9:]) >> 6) & 0x3f03fff) - r4 = uint64((binary.LittleEndian.Uint32(key[12:]) >> 8) & 0x00fffff) +func (h *macGeneric) Sum(out *[16]byte) { + H, R := h.h, h.r + if h.offset > 0 { + var buffer [TagSize]byte + copy(buffer[:], h.buffer[:h.offset]) + buffer[h.offset] = 1 // invariant: h.offset < TagSize + updateGeneric(buffer[:], finalBlock, &H, &R) + } + finalizeGeneric(out, &H, &(h.s)) +} +func updateGeneric(msg []byte, flag uint32, h, r *[5]uint32) { + h0, h1, h2, h3, h4 := h[0], h[1], h[2], h[3], h[4] + r0, r1, r2, r3, r4 := uint64(r[0]), uint64(r[1]), uint64(r[2]), uint64(r[3]), uint64(r[4]) R1, R2, R3, R4 := r1*5, r2*5, r3*5, r4*5 for len(msg) >= TagSize { @@ -29,7 +87,7 @@ func sumGeneric(out *[TagSize]byte, msg []byte, key *[32]byte) { h1 += (binary.LittleEndian.Uint32(msg[3:]) >> 2) & 0x3ffffff h2 += (binary.LittleEndian.Uint32(msg[6:]) >> 4) & 0x3ffffff h3 += (binary.LittleEndian.Uint32(msg[9:]) >> 6) & 0x3ffffff - h4 += (binary.LittleEndian.Uint32(msg[12:]) >> 8) | (1 << 24) + h4 += (binary.LittleEndian.Uint32(msg[12:]) >> 8) | flag // h *= r d0 := (uint64(h0) * r0) + (uint64(h1) * R4) + (uint64(h2) * R3) + (uint64(h3) * R2) + (uint64(h4) * R1) @@ -52,36 +110,11 @@ func sumGeneric(out *[TagSize]byte, msg []byte, key *[32]byte) { msg = msg[TagSize:] } - if len(msg) > 0 { - var block [TagSize]byte - off := copy(block[:], msg) - block[off] = 0x01 - - // h += msg - h0 += binary.LittleEndian.Uint32(block[0:]) & 0x3ffffff - h1 += (binary.LittleEndian.Uint32(block[3:]) >> 2) & 0x3ffffff - h2 += (binary.LittleEndian.Uint32(block[6:]) >> 4) & 0x3ffffff - h3 += (binary.LittleEndian.Uint32(block[9:]) >> 6) & 0x3ffffff - h4 += (binary.LittleEndian.Uint32(block[12:]) >> 8) - - // h *= r - d0 := (uint64(h0) * r0) + (uint64(h1) * R4) + (uint64(h2) * R3) + (uint64(h3) * R2) + (uint64(h4) * R1) - d1 := (d0 >> 26) + (uint64(h0) * r1) + (uint64(h1) * r0) + (uint64(h2) * R4) + (uint64(h3) * R3) + (uint64(h4) * R2) - d2 := (d1 >> 26) + (uint64(h0) * r2) + (uint64(h1) * r1) + (uint64(h2) * r0) + (uint64(h3) * R4) + (uint64(h4) * R3) - d3 := (d2 >> 26) + (uint64(h0) * r3) + (uint64(h1) * r2) + (uint64(h2) * r1) + (uint64(h3) * r0) + (uint64(h4) * R4) - d4 := (d3 >> 26) + (uint64(h0) * r4) + (uint64(h1) * r3) + (uint64(h2) * r2) + (uint64(h3) * r1) + (uint64(h4) * r0) - - // h %= p - h0 = uint32(d0) & 0x3ffffff - h1 = uint32(d1) & 0x3ffffff - h2 = uint32(d2) & 0x3ffffff - h3 = uint32(d3) & 0x3ffffff - h4 = uint32(d4) & 0x3ffffff + h[0], h[1], h[2], h[3], h[4] = h0, h1, h2, h3, h4 +} - h0 += uint32(d4>>26) * 5 - h1 += h0 >> 26 - h0 = h0 & 0x3ffffff - } +func finalizeGeneric(out *[TagSize]byte, h *[5]uint32, s *[4]uint32) { + h0, h1, h2, h3, h4 := h[0], h[1], h[2], h[3], h[4] // h %= p reduction h2 += h1 >> 26 @@ -123,13 +156,13 @@ func sumGeneric(out *[TagSize]byte, msg []byte, key *[32]byte) { // s: the s part of the key // tag = (h + s) % (2^128) - t := uint64(h0) + uint64(binary.LittleEndian.Uint32(key[16:])) + t := uint64(h0) + uint64(s[0]) h0 = uint32(t) - t = uint64(h1) + uint64(binary.LittleEndian.Uint32(key[20:])) + (t >> 32) + t = uint64(h1) + uint64(s[1]) + (t >> 32) h1 = uint32(t) - t = uint64(h2) + uint64(binary.LittleEndian.Uint32(key[24:])) + (t >> 32) + t = uint64(h2) + uint64(s[2]) + (t >> 32) h2 = uint32(t) - t = uint64(h3) + uint64(binary.LittleEndian.Uint32(key[28:])) + (t >> 32) + t = uint64(h3) + uint64(s[3]) + (t >> 32) h3 = uint32(t) binary.LittleEndian.PutUint32(out[0:], h0) diff --git a/vendor/modules.txt b/vendor/modules.txt index 9c3d1742ce..54974e57b8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -55,7 +55,7 @@ github.com/bgentry/go-netrc/netrc github.com/bgentry/speakeasy # github.com/blang/semver v3.5.1+incompatible github.com/blang/semver -# github.com/cloudflare/cloudflare-go v0.0.0-20190123152938-9837a599c0ba +# github.com/cloudflare/cloudflare-go v0.8.6-0.20190326234830-ce422d1b74b3 github.com/cloudflare/cloudflare-go # github.com/davecgh/go-spew v1.1.1 github.com/davecgh/go-spew/spew From c6b020d5c01a9993a3043eb2938187a7297e7487 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Wed, 27 Mar 2019 11:00:42 +1100 Subject: [PATCH 2/4] Update rateLimit.Correlate to be a pointer --- cloudflare/resource_cloudflare_rate_limit.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cloudflare/resource_cloudflare_rate_limit.go b/cloudflare/resource_cloudflare_rate_limit.go index 8e7de0559f..04d5aeb424 100644 --- a/cloudflare/resource_cloudflare_rate_limit.go +++ b/cloudflare/resource_cloudflare_rate_limit.go @@ -393,7 +393,7 @@ func expandRateLimitAction(d *schema.ResourceData) (action cloudflare.RateLimitA return action, nil } -func expandRateLimitCorrelate(d *schema.ResourceData) (correlate cloudflare.RateLimitCorrelate, err error) { +func expandRateLimitCorrelate(d *schema.ResourceData) (correlate *cloudflare.RateLimitCorrelate, err error) { v, ok := d.GetOk("correlate") if !ok { return @@ -401,7 +401,7 @@ func expandRateLimitCorrelate(d *schema.ResourceData) (correlate cloudflare.Rate tfCorrelate := v.([]interface{})[0].(map[string]interface{}) - correlate = cloudflare.RateLimitCorrelate{ + correlate = &cloudflare.RateLimitCorrelate{ By: tfCorrelate["by"].(string), } @@ -446,7 +446,7 @@ func resourceCloudflareRateLimitRead(d *schema.ResourceData, meta interface{}) e log.Printf("[WARN] Error setting action on rate limit %q: %s", d.Id(), err) } - d.Set("correlate", flattenRateLimitCorrelate(rateLimit.Correlate)) + d.Set("correlate", flattenRateLimitCorrelate(*rateLimit.Correlate)) d.Set("description", rateLimit.Description) d.Set("disabled", rateLimit.Disabled) From 2f4fa41b0b8e736df47acb010a36f612bfe6d59e Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Wed, 27 Mar 2019 11:03:12 +1100 Subject: [PATCH 3/4] Bump cloudflare-go to ab6ea5d --- go.mod | 2 +- go.sum | 6 ++++-- vendor/github.com/cloudflare/cloudflare-go/go.mod | 3 ++- vendor/github.com/cloudflare/cloudflare-go/go.sum | 10 ++++++++++ .../cloudflare/cloudflare-go/load_balancing.go | 1 + vendor/modules.txt | 2 +- 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 5b0cb71860..9e644f8e65 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/armon/go-radix v1.0.0 // indirect github.com/aws/aws-sdk-go v1.18.3 // indirect github.com/blang/semver v3.5.1+incompatible // indirect - github.com/cloudflare/cloudflare-go v0.8.6-0.20190326234830-ce422d1b74b3 + github.com/cloudflare/cloudflare-go v0.8.6-0.20190327000105-ab6ea5d38409 github.com/hashicorp/go-cleanhttp v0.5.0 github.com/hashicorp/go-getter v1.2.0 // indirect github.com/hashicorp/go-hclog v0.8.0 // indirect diff --git a/go.sum b/go.sum index 68a170a317..0abfbc727d 100644 --- a/go.sum +++ b/go.sum @@ -68,8 +68,8 @@ github.com/chzyer/readline v0.0.0-20161106042343-c914be64f07d/go.mod h1:nSuG5e5P github.com/chzyer/test v0.0.0-20160617131543-bea8f082b6fd/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cloudflare/cloudflare-go v0.8.6-0.20190326234830-ce422d1b74b3 h1:0dNTaRXwkmW8cyENqbaMsDGQjH1ZOUErEC07mBSvhQc= -github.com/cloudflare/cloudflare-go v0.8.6-0.20190326234830-ce422d1b74b3/go.mod h1:qKQ9S///VKEax9N8kFel9/AvmnkYgvb8uiKTnoVFvpg= +github.com/cloudflare/cloudflare-go v0.8.6-0.20190327000105-ab6ea5d38409 h1:QVcUh7/upMWnSzYuGp71O4XzFi6GWmmi2QidzDGRrdQ= +github.com/cloudflare/cloudflare-go v0.8.6-0.20190327000105-ab6ea5d38409/go.mod h1:wqCYq1S9oX9sYJ5O8rF6z8qocTG+vA35evLmFE2Qi60= github.com/codegangsta/cli v1.20.0/go.mod h1:/qJNoX69yVSKu5o4jLyXAENLRyk1uhi7zkbQ3slBdOA= github.com/coreos/bbolt v1.3.1-coreos.1/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.2.0-rc.1.0.20170908195435-80aa810309d4+incompatible h1:VLCxgrfBsnJtqTy0WFP0GsjjwWZQiuQiNgiWnY6g6Gc= @@ -398,6 +398,7 @@ golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/net v0.0.0-20171004034648-a04bdaca5b32/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180811021610-c39426892332/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -448,6 +449,7 @@ golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190228203856-589c23e65e65/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= google.golang.org/api v0.0.0-20171005000305-7a7376eff6a5 h1:PDkJGYjSvxJyevtZRGmBSO+HjbIKuqYEEc8gB51or4o= google.golang.org/api v0.0.0-20171005000305-7a7376eff6a5/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0= diff --git a/vendor/github.com/cloudflare/cloudflare-go/go.mod b/vendor/github.com/cloudflare/cloudflare-go/go.mod index 091f3799be..6960ce4a32 100644 --- a/vendor/github.com/cloudflare/cloudflare-go/go.mod +++ b/vendor/github.com/cloudflare/cloudflare-go/go.mod @@ -8,6 +8,7 @@ require ( github.com/pkg/errors v0.8.0 github.com/pmezard/go-difflib v1.0.0 // indirect github.com/stretchr/testify v1.2.2 - golang.org/x/net v0.0.0-20181029044818-c44066c5c816 // indirect + golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f // indirect golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 + golang.org/x/tools v0.0.0-20190228203856-589c23e65e65 // indirect ) diff --git a/vendor/github.com/cloudflare/cloudflare-go/go.sum b/vendor/github.com/cloudflare/cloudflare-go/go.sum index 7ba4f99a21..63f9d81df5 100644 --- a/vendor/github.com/cloudflare/cloudflare-go/go.sum +++ b/vendor/github.com/cloudflare/cloudflare-go/go.sum @@ -2,6 +2,7 @@ github.com/codegangsta/cli v1.20.0 h1:iX1FXEgwzd5+XN6wk5cVHOGQj6Q3Dcp20lUeS4lHNT github.com/codegangsta/cli v1.20.0/go.mod h1:/qJNoX69yVSKu5o4jLyXAENLRyk1uhi7zkbQ3slBdOA= 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/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/olekukonko/tablewriter v0.0.1 h1:b3iUnf1v+ppJiOfNX4yxxqfWKMQPZR5yoh8urCTFX88= @@ -12,7 +13,16 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f h1:hX65Cu3JDlGH3uEdK7I99Ii+9kjD6mvnnpfLdEAH0x4= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181029044818-c44066c5c816 h1:mVFkLpejdFLXVUv9E42f3XJVfMdqd0IVLVIVLjZWn5o= golang.org/x/net v0.0.0-20181029044818-c44066c5c816/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 h1:+DCIGbF/swA92ohVg0//6X2IVY3KZs6p9mix0ziNYJM= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20190228203856-589c23e65e65 h1:BBwyOPVomIgLIdstraZlzhvsU8izPeuJ/kpowjK4+Y4= +golang.org/x/tools v0.0.0-20190228203856-589c23e65e65/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= diff --git a/vendor/github.com/cloudflare/cloudflare-go/load_balancing.go b/vendor/github.com/cloudflare/cloudflare-go/load_balancing.go index eeefbaba3b..8b2f89a650 100644 --- a/vendor/github.com/cloudflare/cloudflare-go/load_balancing.go +++ b/vendor/github.com/cloudflare/cloudflare-go/load_balancing.go @@ -67,6 +67,7 @@ type LoadBalancer struct { RegionPools map[string][]string `json:"region_pools"` PopPools map[string][]string `json:"pop_pools"` Proxied bool `json:"proxied"` + Enabled *bool `json:"enabled,omitempty"` Persistence string `json:"session_affinity,omitempty"` PersistenceTTL int `json:"session_affinity_ttl,omitempty"` diff --git a/vendor/modules.txt b/vendor/modules.txt index 54974e57b8..6d78d20e2f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -55,7 +55,7 @@ github.com/bgentry/go-netrc/netrc github.com/bgentry/speakeasy # github.com/blang/semver v3.5.1+incompatible github.com/blang/semver -# github.com/cloudflare/cloudflare-go v0.8.6-0.20190326234830-ce422d1b74b3 +# github.com/cloudflare/cloudflare-go v0.8.6-0.20190327000105-ab6ea5d38409 github.com/cloudflare/cloudflare-go # github.com/davecgh/go-spew v1.1.1 github.com/davecgh/go-spew/spew From eee38b586b32a4db5ad8f9cfc428cf6b7b0a7202 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Wed, 27 Mar 2019 11:11:08 +1100 Subject: [PATCH 4/4] rate_limit: Don't set correlate unless it's needed We only want to set `rateLimit.Correlate` when it's required. This stops the value from continiously being updated in the Terraform state but not changed in the remote. Closes #256 --- cloudflare/resource_cloudflare_rate_limit.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cloudflare/resource_cloudflare_rate_limit.go b/cloudflare/resource_cloudflare_rate_limit.go index 04d5aeb424..9d54fcc087 100644 --- a/cloudflare/resource_cloudflare_rate_limit.go +++ b/cloudflare/resource_cloudflare_rate_limit.go @@ -446,7 +446,10 @@ func resourceCloudflareRateLimitRead(d *schema.ResourceData, meta interface{}) e log.Printf("[WARN] Error setting action on rate limit %q: %s", d.Id(), err) } - d.Set("correlate", flattenRateLimitCorrelate(*rateLimit.Correlate)) + if rateLimit.Correlate != nil { + d.Set("correlate", flattenRateLimitCorrelate(*rateLimit.Correlate)) + } + d.Set("description", rateLimit.Description) d.Set("disabled", rateLimit.Disabled)