Skip to content

Commit

Permalink
Merge pull request #591 from cloudflare/dependabot/go_modules/github.…
Browse files Browse the repository at this point in the history
…com/cloudflare/cloudflare-go-0.73.0

build(deps): bump github.com/cloudflare/cloudflare-go from 0.72.0 to 0.73.0
  • Loading branch information
jacobbednarz authored Jul 20, 2023
2 parents 7030396 + 17f6ef7 commit 7696d03
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 110 deletions.
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/MakeNowJust/heredoc/v2 v2.0.1
github.com/cloudflare/cloudflare-go v0.72.0
github.com/cloudflare/cloudflare-go v0.73.0
github.com/dnaeon/go-vcr v1.2.0
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/hc-install v0.5.2
Expand Down Expand Up @@ -42,11 +42,11 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/crypto v0.10.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.11.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/cloudflare/cloudflare-go v0.72.0 h1:khsJV4IE3I7U8eK9CUreGnxQm16MEFN5d0xPJfPnA+0=
github.com/cloudflare/cloudflare-go v0.72.0/go.mod h1:VW6GuazkaZ4xEDkFt24lkXQUsE8q7BiGqDniC2s8WEM=
github.com/cloudflare/cloudflare-go v0.73.0 h1:yBjVidAbzdI3aNSFotJdyIBswDWMO4k9Qpd25z7a16M=
github.com/cloudflare/cloudflare-go v0.73.0/go.mod h1:5xOc5nIVnd+5ai+10r+5NdFHf92RPRx5AM+aekMIhco=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
Expand Down Expand Up @@ -254,8 +254,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM=
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -323,8 +323,8 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
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/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -382,8 +382,8 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -393,8 +393,8 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
145 changes: 57 additions & 88 deletions internal/app/cf-terraforming/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,105 +710,74 @@ func generateResources() func(cmd *cobra.Command, args []string) {
}
}
case "cloudflare_ruleset":
if accountID != "" {
jsonPayload, err := api.ListAccountRulesets(context.Background(), accountID)
if err != nil {
log.Fatal(err)
}

var nonManagedRules []cloudflare.Ruleset

// A little annoying but makes more sense doing it this way. Only append
// the non-managed rules to the usable nonManagedRules variable instead
// of attempting to delete from an existing slice and just reassign.
for _, r := range jsonPayload {
if r.Kind != string(cloudflare.RulesetKindManaged) {
nonManagedRules = append(nonManagedRules, r)
}
}
jsonPayload = nonManagedRules

for i, rule := range nonManagedRules {
ruleset, _ := api.GetAccountRuleset(context.Background(), accountID, rule.ID)
jsonPayload[i].Rules = ruleset.Rules
}

resourceCount = len(jsonPayload)
m, _ := json.Marshal(jsonPayload)
err = json.Unmarshal(m, &jsonStructData)
if err != nil {
log.Fatal(err)
}
} else {
jsonPayload, err := api.ListZoneRulesets(context.Background(), zoneID)
if err != nil {
log.Fatal(err)
}
jsonPayload, err := api.ListRulesets(context.Background(), identifier, cloudflare.ListRulesetsParams{})
if err != nil {
log.Fatal(err)
}

var nonManagedRules []cloudflare.Ruleset
var nonManagedRules []cloudflare.Ruleset

// A little annoying but makes more sense doing it this way. Only append
// the non-managed rules to the usable nonManagedRules variable instead
// of attempting to delete from an existing slice and just reassign.
for _, r := range jsonPayload {
if r.Kind != string(cloudflare.RulesetKindManaged) {
nonManagedRules = append(nonManagedRules, r)
}
// A little annoying but makes more sense doing it this way. Only append
// the non-managed rules to the usable nonManagedRules variable instead
// of attempting to delete from an existing slice and just reassign.
for _, r := range jsonPayload {
if r.Kind != string(cloudflare.RulesetKindManaged) {
nonManagedRules = append(nonManagedRules, r)
}
jsonPayload = nonManagedRules
ruleHeaders := map[string][]map[string]interface{}{}
for i, rule := range nonManagedRules {
ruleset, _ := api.GetZoneRuleset(context.Background(), zoneID, rule.ID)
jsonPayload[i].Rules = ruleset.Rules

if ruleset.Rules != nil {
for _, rule := range ruleset.Rules {
if rule.ActionParameters != nil && rule.ActionParameters.Headers != nil {
// Sort the headers to have deterministic config output
keys := make([]string, 0, len(rule.ActionParameters.Headers))
for k := range rule.ActionParameters.Headers {
keys = append(keys, k)
}
sort.Strings(keys)

// The structure of the API response for headers differs from the
// structure terraform requires. So we collect all the headers
// indexed by rule.ID to massage the jsonStructData later
for _, headerName := range keys {
header := map[string]interface{}{
"name": headerName,
"operation": rule.ActionParameters.Headers[headerName].Operation,
"expression": rule.ActionParameters.Headers[headerName].Expression,
"value": rule.ActionParameters.Headers[headerName].Value,
}
ruleHeaders[rule.ID] = append(ruleHeaders[rule.ID], header)
}
jsonPayload = nonManagedRules
ruleHeaders := map[string][]map[string]interface{}{}
for i, rule := range nonManagedRules {
ruleset, _ := api.GetRuleset(context.Background(), identifier, rule.ID)
jsonPayload[i].Rules = ruleset.Rules

if ruleset.Rules != nil {
for _, rule := range ruleset.Rules {
if rule.ActionParameters != nil && rule.ActionParameters.Headers != nil {
// Sort the headers to have deterministic config output
keys := make([]string, 0, len(rule.ActionParameters.Headers))
for k := range rule.ActionParameters.Headers {
keys = append(keys, k)
}
sort.Strings(keys)

// The structure of the API response for headers differs from the
// structure terraform requires. So we collect all the headers
// indexed by rule.ID to massage the jsonStructData later
for _, headerName := range keys {
header := map[string]interface{}{
"name": headerName,
"operation": rule.ActionParameters.Headers[headerName].Operation,
"expression": rule.ActionParameters.Headers[headerName].Expression,
"value": rule.ActionParameters.Headers[headerName].Value,
}
ruleHeaders[rule.ID] = append(ruleHeaders[rule.ID], header)
}
}
}
}
}

sort.Slice(jsonPayload, func(i, j int) bool {
return jsonPayload[i].Phase < jsonPayload[j].Phase
})
sort.Slice(jsonPayload, func(i, j int) bool {
return jsonPayload[i].Phase < jsonPayload[j].Phase
})

resourceCount = len(jsonPayload)
m, _ := json.Marshal(jsonPayload)
err = json.Unmarshal(m, &jsonStructData)
if err != nil {
log.Fatal(err)
}
resourceCount = len(jsonPayload)
m, _ := json.Marshal(jsonPayload)
err = json.Unmarshal(m, &jsonStructData)
if err != nil {
log.Fatal(err)
}

// Make the rules have the correct header structure
for i, ruleset := range jsonStructData {
if ruleset.(map[string]interface{})["rules"] != nil {
for j, rule := range ruleset.(map[string]interface{})["rules"].([]interface{}) {
ID := rule.(map[string]interface{})["id"]
if ID != nil {
headers, exists := ruleHeaders[ID.(string)]
if exists {
jsonStructData[i].(map[string]interface{})["rules"].([]interface{})[j].(map[string]interface{})["action_parameters"].(map[string]interface{})["headers"] = headers
}
// Make the rules have the correct header structure
for i, ruleset := range jsonStructData {
if ruleset.(map[string]interface{})["rules"] != nil {
for j, rule := range ruleset.(map[string]interface{})["rules"].([]interface{}) {
ID := rule.(map[string]interface{})["id"]
if ID != nil {
headers, exists := ruleHeaders[ID.(string)]
if exists {
jsonStructData[i].(map[string]interface{})["rules"].([]interface{})[j].(map[string]interface{})["action_parameters"].(map[string]interface{})["headers"] = headers
}
}
}
Expand Down
8 changes: 1 addition & 7 deletions internal/app/cf-terraforming/cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,7 @@ func runImport() func(cmd *cobra.Command, args []string) {
log.Fatal(err)
}
case "cloudflare_ruleset":
var err error
var jsonPayload []cloudflare.Ruleset
if accountID != "" {
jsonPayload, err = api.ListAccountRulesets(context.Background(), accountID)
} else {
jsonPayload, err = api.ListZoneRulesets(context.Background(), zoneID)
}
jsonPayload, err := api.ListRulesets(context.Background(), identifier, cloudflare.ListRulesetsParams{})
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 7696d03

Please sign in to comment.