mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-12-09 13:46:07 +08:00
wip!
This commit is contained in:
parent
a5a624ff96
commit
1efa022349
12 changed files with 109 additions and 182 deletions
|
|
@ -42,11 +42,11 @@ type RecordConfig struct {
|
|||
// Comparable is an opaque string that can be used to compare two
|
||||
// RecordConfigs for equality. Typically this is the Zonefile line minus the
|
||||
// label and TTL.
|
||||
Comparable string `json:"-"` // Cache of ToComparableNoTTL()
|
||||
Comparable string `json:"comparable,omitempty"` // Cache of ToComparableNoTTL()
|
||||
|
||||
// ZonefilePartial is the partial zonefile line for this record, excluding
|
||||
// the label and TTL. If this is not an official RR type, we invent the format.
|
||||
ZonefilePartial string `json:"-"`
|
||||
ZonefilePartial string `json:"zonfefilepartial,omitempty"`
|
||||
|
||||
//// Fields only relevant when RecordConfig was created from data in dnsconfig.js:
|
||||
|
||||
|
|
@ -329,6 +329,10 @@ func (rc *RecordConfig) GetLabelFQDN() string {
|
|||
// metafields. Provider-specific metafields like CF_PROXY are not the same as
|
||||
// pseudo-records like ANAME or R53_ALIAS
|
||||
func (rc *RecordConfig) ToComparableNoTTL() string {
|
||||
if rc.IsModernType() {
|
||||
return rc.Comparable
|
||||
}
|
||||
|
||||
switch rc.Type {
|
||||
case "SOA":
|
||||
return fmt.Sprintf("%s %v %d %d %d %d", rc.target, rc.SoaMbox, rc.SoaRefresh, rc.SoaRetry, rc.SoaExpire, rc.SoaMinttl)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
"name": "foo.com",
|
||||
"records": [
|
||||
{
|
||||
"comparable": "name=(001,301,test1.foo.com,https://goo.com/$1) code=(301) when=(http.host eq \"test1.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))",
|
||||
"fields": {
|
||||
"code": 301,
|
||||
"sr_display": "name=(001,301,test1.foo.com,https://goo.com/$1) code=(301) when=(http.host eq \"test1.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))",
|
||||
|
|
@ -20,11 +21,13 @@
|
|||
"name": "@",
|
||||
"name_raw": "@",
|
||||
"name_unicode": "@",
|
||||
"target": "test1.foo.com,https://goo.com/$1",
|
||||
"target": "name=(001,301,test1.foo.com,https://goo.com/$1) code=(301) when=(http.host eq \"test1.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))",
|
||||
"ttl": 1,
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT",
|
||||
"zonfefilepartial": "name=(001,301,test1.foo.com,https://goo.com/$1) code=(301) when=(http.host eq \"test1.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))"
|
||||
},
|
||||
{
|
||||
"comparable": "name=(002,302,test2.foo.com,https://goo.com/$1) code=(302) when=(http.host eq \"test2.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))",
|
||||
"fields": {
|
||||
"code": 302,
|
||||
"sr_display": "name=(002,302,test2.foo.com,https://goo.com/$1) code=(302) when=(http.host eq \"test2.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))",
|
||||
|
|
@ -36,9 +39,10 @@
|
|||
"name": "@",
|
||||
"name_raw": "@",
|
||||
"name_unicode": "@",
|
||||
"target": "test2.foo.com,https://goo.com/$1",
|
||||
"target": "name=(002,302,test2.foo.com,https://goo.com/$1) code=(302) when=(http.host eq \"test2.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))",
|
||||
"ttl": 1,
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT",
|
||||
"zonfefilepartial": "name=(002,302,test2.foo.com,https://goo.com/$1) code=(302) when=(http.host eq \"test2.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))"
|
||||
}
|
||||
],
|
||||
"registrar": "none"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
$TTL 300
|
||||
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT test1.foo.com,https://goo.com/$1
|
||||
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT test2.foo.com,https://goo.com/$1
|
||||
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT name=(001,301,test1.foo.com,https://goo.com/$1) code=(301) when=(http.host eq "test1.foo.com" and http.request.uri.path eq "/") then=(concat("https://goo.com", http.request.uri.path))
|
||||
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT name=(002,302,test2.foo.com,https://goo.com/$1) code=(302) when=(http.host eq "test2.foo.com" and http.request.uri.path eq "/") then=(concat("https://goo.com", http.request.uri.path))
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
"type": "CF_WORKER_ROUTE"
|
||||
},
|
||||
{
|
||||
"comparable": "name=(003,301,test1.foo.com,https://goo.com/$1) code=(301) when=(http.host eq \"test1.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))",
|
||||
"fields": {
|
||||
"code": 301,
|
||||
"sr_display": "name=(003,301,test1.foo.com,https://goo.com/$1) code=(301) when=(http.host eq \"test1.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))",
|
||||
|
|
@ -37,11 +38,13 @@
|
|||
"name": "@",
|
||||
"name_raw": "@",
|
||||
"name_unicode": "@",
|
||||
"target": "test1.foo.com,https://goo.com/$1",
|
||||
"target": "name=(003,301,test1.foo.com,https://goo.com/$1) code=(301) when=(http.host eq \"test1.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))",
|
||||
"ttl": 1,
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT",
|
||||
"zonfefilepartial": "name=(003,301,test1.foo.com,https://goo.com/$1) code=(301) when=(http.host eq \"test1.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))"
|
||||
},
|
||||
{
|
||||
"comparable": "name=(004,302,test2.foo.com,https://goo.com/$1) code=(302) when=(http.host eq \"test2.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))",
|
||||
"fields": {
|
||||
"code": 302,
|
||||
"sr_display": "name=(004,302,test2.foo.com,https://goo.com/$1) code=(302) when=(http.host eq \"test2.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))",
|
||||
|
|
@ -53,9 +56,10 @@
|
|||
"name": "@",
|
||||
"name_raw": "@",
|
||||
"name_unicode": "@",
|
||||
"target": "test2.foo.com,https://goo.com/$1",
|
||||
"target": "name=(004,302,test2.foo.com,https://goo.com/$1) code=(302) when=(http.host eq \"test2.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))",
|
||||
"ttl": 1,
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT",
|
||||
"zonfefilepartial": "name=(004,302,test2.foo.com,https://goo.com/$1) code=(302) when=(http.host eq \"test2.foo.com\" and http.request.uri.path eq \"/\") then=(concat(\"https://goo.com\", http.request.uri.path))"
|
||||
},
|
||||
{
|
||||
"filepos": "[line:6:5]",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
$TTL 300
|
||||
;@ IN CF_WORKER_ROUTE test3.foo.com,test-worker
|
||||
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT test1.foo.com,https://goo.com/$1
|
||||
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT test2.foo.com,https://goo.com/$1
|
||||
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT name=(003,301,test1.foo.com,https://goo.com/$1) code=(301) when=(http.host eq "test1.foo.com" and http.request.uri.path eq "/") then=(concat("https://goo.com", http.request.uri.path))
|
||||
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT name=(004,302,test2.foo.com,https://goo.com/$1) code=(302) when=(http.host eq "test2.foo.com" and http.request.uri.path eq "/") then=(concat("https://goo.com", http.request.uri.path))
|
||||
test1.foo.com.sub IN A 10.2.3.1
|
||||
test2.foo.com.sub IN A 10.2.3.2
|
||||
test3.foo.com.sub IN A 10.2.3.3
|
||||
test3.foo.com.sub IN A 10.2.3.3
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
"name": "foo.com",
|
||||
"records": [
|
||||
{
|
||||
"comparable": "name=(name1) code=(301) when=(when1) then=(then1)",
|
||||
"fields": {
|
||||
"code": 301,
|
||||
"sr_display": "name=(name1) code=(301) when=(when1) then=(then1)",
|
||||
|
|
@ -20,11 +21,13 @@
|
|||
"name": "@",
|
||||
"name_raw": "@",
|
||||
"name_unicode": "@",
|
||||
"target": "name1",
|
||||
"target": "name=(name1) code=(301) when=(when1) then=(then1)",
|
||||
"ttl": 1,
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT",
|
||||
"zonfefilepartial": "name=(name1) code=(301) when=(when1) then=(then1)"
|
||||
},
|
||||
{
|
||||
"comparable": "name=(name2) code=(302) when=(when2) then=(then2)",
|
||||
"fields": {
|
||||
"code": 302,
|
||||
"sr_display": "name=(name2) code=(302) when=(when2) then=(then2)",
|
||||
|
|
@ -36,11 +39,13 @@
|
|||
"name": "@",
|
||||
"name_raw": "@",
|
||||
"name_unicode": "@",
|
||||
"target": "name2",
|
||||
"target": "name=(name2) code=(302) when=(when2) then=(then2)",
|
||||
"ttl": 1,
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT",
|
||||
"zonfefilepartial": "name=(name2) code=(302) when=(when2) then=(then2)"
|
||||
},
|
||||
{
|
||||
"comparable": "name=(name3) code=(301) when=(when3) then=(then3)",
|
||||
"fields": {
|
||||
"code": 301,
|
||||
"sr_display": "name=(name3) code=(301) when=(when3) then=(then3)",
|
||||
|
|
@ -52,11 +57,13 @@
|
|||
"name": "@",
|
||||
"name_raw": "@",
|
||||
"name_unicode": "@",
|
||||
"target": "name3",
|
||||
"target": "name=(name3) code=(301) when=(when3) then=(then3)",
|
||||
"ttl": 1,
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT",
|
||||
"zonfefilepartial": "name=(name3) code=(301) when=(when3) then=(then3)"
|
||||
},
|
||||
{
|
||||
"comparable": "name=(namemeta) code=(302) when=(whenmeta) then=(thenmeta)",
|
||||
"fields": {
|
||||
"code": 302,
|
||||
"sr_display": "name=(namemeta) code=(302) when=(whenmeta) then=(thenmeta)",
|
||||
|
|
@ -68,11 +75,13 @@
|
|||
"name": "@",
|
||||
"name_raw": "@",
|
||||
"name_unicode": "@",
|
||||
"target": "namemeta",
|
||||
"target": "name=(namemeta) code=(302) when=(whenmeta) then=(thenmeta)",
|
||||
"ttl": 1,
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT",
|
||||
"zonfefilepartial": "name=(namemeta) code=(302) when=(whenmeta) then=(thenmeta)"
|
||||
},
|
||||
{
|
||||
"comparable": "name=(namettl) code=(302) when=(whenttl) then=(thenttl)",
|
||||
"fields": {
|
||||
"code": 302,
|
||||
"sr_display": "name=(namettl) code=(302) when=(whenttl) then=(thenttl)",
|
||||
|
|
@ -84,9 +93,10 @@
|
|||
"name": "@",
|
||||
"name_raw": "@",
|
||||
"name_unicode": "@",
|
||||
"target": "namettl",
|
||||
"target": "name=(namettl) code=(302) when=(whenttl) then=(thenttl)",
|
||||
"ttl": 1,
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT"
|
||||
"type": "CLOUDFLAREAPI_SINGLE_REDIRECT",
|
||||
"zonfefilepartial": "name=(namettl) code=(302) when=(whenttl) then=(thenttl)"
|
||||
},
|
||||
{
|
||||
"filepos": "[line:2:5]",
|
||||
|
|
|
|||
7
pkg/js/parse_tests/050-cfSingleRedirect/foo.com.zone
Normal file
7
pkg/js/parse_tests/050-cfSingleRedirect/foo.com.zone
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
$TTL 300
|
||||
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT name=(name1) code=(301) when=(when1) then=(then1)
|
||||
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT name=(name2) code=(302) when=(when2) then=(then2)
|
||||
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT name=(name3) code=(301) when=(when3) then=(then3)
|
||||
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT name=(namemeta) code=(302) when=(whenmeta) then=(thenmeta)
|
||||
;@ 1 IN CLOUDFLAREAPI_SINGLE_REDIRECT name=(namettl) code=(302) when=(whenttl) then=(thenttl)
|
||||
name1 IN A 1.2.3.4
|
||||
|
|
@ -16,6 +16,8 @@ type RType interface {
|
|||
|
||||
// RecordConfig factory. Updates a RecordConfig's fields based on args.
|
||||
FromArgs(*models.DomainConfig, *models.RecordConfig, []any) error
|
||||
|
||||
CopyToLegacyFields(*models.RecordConfig)
|
||||
}
|
||||
|
||||
// Map of registered rtypes.
|
||||
|
|
|
|||
|
|
@ -429,11 +429,10 @@ func (c *cloudflareProvider) checkUniversalSSL(dc *models.DomainConfig, id strin
|
|||
}
|
||||
|
||||
const (
|
||||
metaProxy = "cloudflare_proxy"
|
||||
metaProxyDefault = metaProxy + "_default"
|
||||
metaOriginalIP = "original_ip" // TODO(tlim): Unclear what this means.
|
||||
metaUniversalSSL = "cloudflare_universalssl"
|
||||
metaIPConversions = "ip_conversions" // TODO(tlim): Rename to obscure_rules.
|
||||
metaProxy = "cloudflare_proxy"
|
||||
metaProxyDefault = metaProxy + "_default"
|
||||
metaOriginalIP = "original_ip" // TODO(tlim): Unclear what this means.
|
||||
metaUniversalSSL = "cloudflare_universalssl"
|
||||
)
|
||||
|
||||
func checkProxyVal(v string) (string, error) {
|
||||
|
|
@ -798,17 +797,17 @@ func uint16Zero(value interface{}) uint16 {
|
|||
return 0
|
||||
}
|
||||
|
||||
// intZero converts value to uint16 or returns 0.
|
||||
func intZero(value interface{}) uint16 {
|
||||
switch v := value.(type) {
|
||||
case float64:
|
||||
return uint16(v)
|
||||
case int:
|
||||
return uint16(v)
|
||||
case nil:
|
||||
}
|
||||
return 0
|
||||
}
|
||||
// // intZero converts value to uint16 or returns 0.
|
||||
// func intZero(value interface{}) uint16 {
|
||||
// switch v := value.(type) {
|
||||
// case float64:
|
||||
// return uint16(v)
|
||||
// case int:
|
||||
// return uint16(v)
|
||||
// case nil:
|
||||
// }
|
||||
// return 0
|
||||
// }
|
||||
|
||||
// stringDefault returns the value as a string or returns the default value if nil.
|
||||
func stringDefault(value interface{}, def string) string {
|
||||
|
|
|
|||
|
|
@ -297,10 +297,6 @@ func (c *cloudflareProvider) getSingleRedirects(id string, domain string) ([]*mo
|
|||
srThen := pr.ActionParameters.FromValue.TargetURL.Expression
|
||||
code := uint16(pr.ActionParameters.FromValue.StatusCode)
|
||||
|
||||
// if err := cfsingleredirect.MakeSingleRedirectFromAPI(r, code, srName, srWhen, srThen); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// r.SetLabel("@", domain)
|
||||
rec, err := rtypecontrol.NewRecordConfigFromRaw(
|
||||
"CLOUDFLAREAPI_SINGLE_REDIRECT",
|
||||
[]any{srName, code, srWhen, srThen},
|
||||
|
|
@ -310,7 +306,7 @@ func (c *cloudflareProvider) getSingleRedirects(id string, domain string) ([]*mo
|
|||
}
|
||||
rec.Original = thisPr
|
||||
|
||||
// Store the IDs
|
||||
// Store the IDs. These will be needed for update/delete operations.
|
||||
sr := rec.F.(*cfsingleredirect.SingleRedirectConfig)
|
||||
sr.SRRRulesetID = rules.ID
|
||||
sr.SRRRulesetRuleID = pr.ID
|
||||
|
|
@ -365,33 +361,6 @@ func (c *cloudflareProvider) createSingleRedirect(domainID string, cfr cfsingler
|
|||
}
|
||||
|
||||
func (c *cloudflareProvider) deleteSingleRedirects(domainID string, cfr cfsingleredirect.SingleRedirectConfig) error {
|
||||
// This block should delete rules using the as is Cloudflare Golang lib in theory, need to debug why it isn't
|
||||
// updatedRuleset := cloudflare.UpdateEntrypointRulesetParams{}
|
||||
// updatedRulesetRules := []cloudflare.RulesetRule{}
|
||||
|
||||
// rules, err := c.cfClient.GetEntrypointRuleset(context.Background(), cloudflare.ZoneIdentifier(domainID), "http_request_dynamic_redirect")
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("failed fetching redirect rule list cloudflare: %s", err)
|
||||
// }
|
||||
|
||||
// for _, rule := range rules.Rules {
|
||||
// if rule.ID != cfr.SRRRulesetRuleID {
|
||||
// updatedRulesetRules = append(updatedRulesetRules, rule)
|
||||
// } else {
|
||||
// printer.Printf("DEBUG: MATCH %v : %v\n", rule.ID, cfr.SRRRulesetRuleID)
|
||||
// }
|
||||
// }
|
||||
// updatedRuleset.Rules = updatedRulesetRules
|
||||
// _, err = c.cfClient.UpdateEntrypointRuleset(context.Background(), cloudflare.ZoneIdentifier(domainID), updatedRuleset)
|
||||
|
||||
// Old Code
|
||||
|
||||
// rules, err := c.cfClient.GetEntrypointRuleset(context.Background(), cloudflare.ZoneIdentifier(domainID), "http_request_dynamic_redirect")
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// printer.Printf("DEBUG: CALLING API DeleteRulesetRule: SRRRulesetID=%v, cfr.SRRRulesetRuleID=%v\n", cfr.SRRRulesetID, cfr.SRRRulesetRuleID)
|
||||
|
||||
err := c.cfClient.DeleteRulesetRule(context.Background(), cloudflare.ZoneIdentifier(domainID), cloudflare.DeleteRulesetRuleParams{
|
||||
RulesetID: cfr.SRRRulesetID,
|
||||
RulesetRuleID: cfr.SRRRulesetRuleID,
|
||||
|
|
@ -412,77 +381,6 @@ func (c *cloudflareProvider) updateSingleRedirect(domainID string, oldrec, newre
|
|||
return c.createSingleRedirect(domainID, *newrec.F.(*cfsingleredirect.SingleRedirectConfig))
|
||||
}
|
||||
|
||||
// func (c *cloudflareProvider) getPageRules(id string, domain string) ([]*models.RecordConfig, error) {
|
||||
// rules, err := c.cfClient.ListPageRules(context.Background(), id)
|
||||
// if err != nil {
|
||||
// return nil, fmt.Errorf("failed fetching page rule list cloudflare: %w", err)
|
||||
// }
|
||||
// recs := []*models.RecordConfig{}
|
||||
// for _, pr := range rules {
|
||||
// // only interested in forwarding rules. Lets be very specific, and skip anything else
|
||||
// if len(pr.Actions) != 1 || len(pr.Targets) != 1 {
|
||||
// continue
|
||||
// }
|
||||
// if pr.Actions[0].ID != "forwarding_url" {
|
||||
// continue
|
||||
// }
|
||||
// value := pr.Actions[0].Value.(map[string]interface{})
|
||||
// thisPr := pr
|
||||
// r := &models.RecordConfig{
|
||||
// Original: thisPr,
|
||||
// }
|
||||
|
||||
// code := intZero(value["status_code"])
|
||||
|
||||
// when := pr.Targets[0].Constraint.Value
|
||||
// then := value["url"].(string)
|
||||
// currentPrPrio := pr.Priority
|
||||
|
||||
// if err := cfsingleredirect.MakePageRule(r, currentPrPrio, code, when, then); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// r.SetLabel("@", domain)
|
||||
|
||||
// recs = append(recs, r)
|
||||
// }
|
||||
// return recs, nil
|
||||
// }
|
||||
|
||||
// func (c *cloudflareProvider) deletePageRule(recordID, domainID string) error {
|
||||
// return c.cfClient.DeletePageRule(context.Background(), domainID, recordID)
|
||||
// }
|
||||
|
||||
// func (c *cloudflareProvider) updatePageRule(recordID, domainID string, cfr models.CloudflareSingleRedirectConfig) error {
|
||||
// // maybe someday?
|
||||
// // c.apiProvider.UpdatePageRule(context.Background(), domainId, recordID, )
|
||||
// if err := c.deletePageRule(recordID, domainID); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return c.createPageRule(domainID, cfr)
|
||||
// }
|
||||
|
||||
// func (c *cloudflareProvider) createPageRule(domainID string, cfr models.CloudflareSingleRedirectConfig) error {
|
||||
// priority := cfr.PRPriority
|
||||
// code := cfr.Code
|
||||
// prWhen := cfr.PRWhen
|
||||
// prThen := cfr.PRThen
|
||||
// pr := cloudflare.PageRule{
|
||||
// Status: "active",
|
||||
// Priority: priority,
|
||||
// Targets: []cloudflare.PageRuleTarget{
|
||||
// {Target: "url", Constraint: pageRuleConstraint{Operator: "matches", Value: prWhen}},
|
||||
// },
|
||||
// Actions: []cloudflare.PageRuleAction{
|
||||
// {ID: "forwarding_url", Value: &pageRuleFwdInfo{
|
||||
// StatusCode: code,
|
||||
// URL: prThen,
|
||||
// }},
|
||||
// },
|
||||
// }
|
||||
// _, err := c.cfClient.CreatePageRule(context.Background(), domainID, pr)
|
||||
// return err
|
||||
// }
|
||||
|
||||
func (c *cloudflareProvider) getWorkerRoutes(id string, domain string) ([]*models.RecordConfig, error) {
|
||||
res, err := c.cfClient.ListWorkerRoutes(context.Background(), cloudflare.ZoneIdentifier(id), cloudflare.ListWorkerRoutesParams{})
|
||||
if err != nil {
|
||||
|
|
@ -516,9 +414,6 @@ func (c *cloudflareProvider) deleteWorkerRoute(recordID, domainID string) error
|
|||
}
|
||||
|
||||
func (c *cloudflareProvider) updateWorkerRoute(recordID, domainID string, target string) error {
|
||||
// Causing Stack Overflow (!?)
|
||||
// return c.updateWorkerRoute(recordID, domainID, target)
|
||||
|
||||
if err := c.deleteWorkerRoute(recordID, domainID); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -544,12 +439,12 @@ func (c *cloudflareProvider) createWorkerRoute(domainID string, target string) e
|
|||
// https://github.com/dominikh/go-tools/issues/810
|
||||
//
|
||||
//lint:ignore U1000 false positive due to
|
||||
type pageRuleConstraint struct {
|
||||
Operator string `json:"operator"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
// type pageRuleConstraint struct {
|
||||
// Operator string `json:"operator"`
|
||||
// Value string `json:"value"`
|
||||
// }
|
||||
|
||||
type pageRuleFwdInfo struct {
|
||||
URL string `json:"url"`
|
||||
StatusCode uint16 `json:"status_code"`
|
||||
}
|
||||
// type pageRuleFwdInfo struct {
|
||||
// URL string `json:"url"`
|
||||
// StatusCode uint16 `json:"status_code"`
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -21,10 +21,13 @@ func (handle *CfRedirect) Name() string {
|
|||
}
|
||||
|
||||
func (handle *CfRedirect) FromArgs(dc *models.DomainConfig, rec *models.RecordConfig, args []any) error {
|
||||
//fmt.Printf("DEBUG: CF_REDIRECT FromArgs called with args=%+v\n", args)
|
||||
return FromArgs_helper(dc, rec, args, 301)
|
||||
}
|
||||
|
||||
func (handle *CfRedirect) CopyToLegacyFields(rec *models.RecordConfig) {
|
||||
// Nothing needs to be copied. The CLOUDFLAREAPI_SINGLE_REDIRECT FromArgs copies everything needed.
|
||||
}
|
||||
|
||||
type CfTempRedirect struct{}
|
||||
|
||||
// Name returns the text (all caps) name of the rtype.
|
||||
|
|
@ -32,27 +35,14 @@ func (handle *CfTempRedirect) Name() string {
|
|||
return "CF_TEMP_REDIRECT"
|
||||
}
|
||||
|
||||
var redirCount = map[string]int{}
|
||||
var redirCountMutex = sync.RWMutex{}
|
||||
|
||||
func incRedirCount(name string) {
|
||||
redirCountMutex.Lock()
|
||||
defer redirCountMutex.Unlock()
|
||||
|
||||
redirCount[name]++
|
||||
}
|
||||
|
||||
func getRedirCount(name string) int {
|
||||
redirCountMutex.Lock()
|
||||
defer redirCountMutex.Unlock()
|
||||
return redirCount[name]
|
||||
}
|
||||
|
||||
func (handle *CfTempRedirect) FromArgs(dc *models.DomainConfig, rec *models.RecordConfig, args []any) error {
|
||||
//fmt.Printf("DEBUG: CF_TEMP_REDIRECT FromArgs called with args=%+v\n", args)
|
||||
return FromArgs_helper(dc, rec, args, 302)
|
||||
}
|
||||
|
||||
func (handle *CfTempRedirect) CopyToLegacyFields(rec *models.RecordConfig) {
|
||||
// Nothing needs to be copied. The CLOUDFLAREAPI_SINGLE_REDIRECT FromArgs copies everything needed.
|
||||
}
|
||||
|
||||
func FromArgs_helper(dc *models.DomainConfig, rec *models.RecordConfig, args []any, code int) error {
|
||||
|
||||
// Pave the args to be the expected types.
|
||||
|
|
@ -68,9 +58,9 @@ func FromArgs_helper(dc *models.DomainConfig, rec *models.RecordConfig, args []a
|
|||
return err
|
||||
}
|
||||
|
||||
// Create the old-school name with a count prefix.
|
||||
incRedirCount(dc.UniqueName)
|
||||
name := fmt.Sprintf("%03d,%03d,%s,%s", getRedirCount(dc.UniqueName), code, prWhen, prThen)
|
||||
target := fmt.Sprintf("%s,%s", prWhen, prThen)
|
||||
|
||||
sr := SingleRedirectConfig{}
|
||||
rec.Type = sr.Name() // This record is now a CLOUDFLAREAPI_SINGLE_REDIRECT
|
||||
|
|
@ -78,6 +68,24 @@ func FromArgs_helper(dc *models.DomainConfig, rec *models.RecordConfig, args []a
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_ = rec.SetTarget(target) // Overwrite target to old-style for compatibility
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// The legacy system prepended a count to the name to coordinate ordering.
|
||||
|
||||
var redirCount = map[string]int{}
|
||||
var redirCountMutex = sync.RWMutex{}
|
||||
|
||||
func incRedirCount(name string) {
|
||||
redirCountMutex.Lock()
|
||||
defer redirCountMutex.Unlock()
|
||||
|
||||
redirCount[name]++
|
||||
}
|
||||
|
||||
func getRedirCount(name string) int {
|
||||
redirCountMutex.Lock()
|
||||
defer redirCountMutex.Unlock()
|
||||
return redirCount[name]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@ func (handle *SingleRedirectConfig) Name() string {
|
|||
}
|
||||
|
||||
func (handle *SingleRedirectConfig) FromArgs(dc *models.DomainConfig, rec *models.RecordConfig, args []any) error {
|
||||
//fmt.Printf("DEBUG: CLOUDFLAREAPI_SINGLE_REDIRECT FromArgs called with args=%+v\n", args)
|
||||
|
||||
// Pave the args to be the expected types.
|
||||
if err := rtypecontrol.PaveArgs(args, "siss"); err != nil {
|
||||
return err
|
||||
|
|
@ -89,9 +87,5 @@ func targetFromRaw(name string, code uint16, when, then string) string {
|
|||
}
|
||||
|
||||
func (handle *SingleRedirectConfig) CopyToLegacyFields(rec *models.RecordConfig) {
|
||||
//rec.SetTarget(handle.SRDisplay)
|
||||
_ = rec.SetTarget(handle.SRName)
|
||||
_ = rec.SetTarget(rec.F.(*SingleRedirectConfig).SRDisplay)
|
||||
}
|
||||
|
||||
//func (handle *SingleRedirectConfig) IDNFields(argsRaw) (argsIDN, argsUnicode, error) {}
|
||||
//func (handle *SingleRedirectConfig) CopyFromLegacyFields(*models.RecordConfig) {}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue