chore: 兼容新版 cloudflare api
This commit is contained in:
@@ -12,6 +12,7 @@ type DnsProvider struct {
|
|||||||
Api *cloudflare.API `mapstructure:"-"`
|
Api *cloudflare.API `mapstructure:"-"`
|
||||||
TTL int `mapstructure:"-"`
|
TTL int `mapstructure:"-"`
|
||||||
Zone string `mapstructure:"zone"`
|
Zone string `mapstructure:"zone"`
|
||||||
|
ZoneResource *cloudflare.ResourceContainer `mapstructure:"-"`
|
||||||
Token string `mapstructure:"token"`
|
Token string `mapstructure:"token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +27,10 @@ func New(ttl int, conf map[string]interface{}, Http *http.Client) (*DnsProvider,
|
|||||||
|
|
||||||
if p.Zone == "" {
|
if p.Zone == "" {
|
||||||
return nil, errors.New("cloudflare zone 不能为空")
|
return nil, errors.New("cloudflare zone 不能为空")
|
||||||
} else if p.Token == "" {
|
}
|
||||||
|
p.ZoneResource = cloudflare.ZoneIdentifier(p.Zone)
|
||||||
|
|
||||||
|
if p.Token == "" {
|
||||||
return nil, errors.New("cloudflare token 不能为空")
|
return nil, errors.New("cloudflare token 不能为空")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +39,7 @@ func New(ttl int, conf map[string]interface{}, Http *http.Client) (*DnsProvider,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a DnsProvider) SetDomainRecord(domain, ip string) error {
|
func (a DnsProvider) SetDomainRecord(domain, ip string) error {
|
||||||
records, e := a.Api.DNSRecords(context.Background(), a.Zone, cloudflare.DNSRecord{
|
records, _, e := a.Api.ListDNSRecords(context.Background(), a.ZoneResource, cloudflare.ListDNSRecordsParams{
|
||||||
Type: "A",
|
Type: "A",
|
||||||
Name: domain,
|
Name: domain,
|
||||||
})
|
})
|
||||||
@@ -44,7 +48,7 @@ func (a DnsProvider) SetDomainRecord(domain, ip string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(records) == 0 {
|
if len(records) == 0 {
|
||||||
_, e = a.Api.CreateDNSRecord(context.Background(), a.Zone, cloudflare.DNSRecord{
|
_, e = a.Api.CreateDNSRecord(context.Background(), a.ZoneResource, cloudflare.CreateDNSRecordParams{
|
||||||
Type: "A",
|
Type: "A",
|
||||||
Name: domain,
|
Name: domain,
|
||||||
Content: ip,
|
Content: ip,
|
||||||
@@ -53,11 +57,12 @@ func (a DnsProvider) SetDomainRecord(domain, ip string) error {
|
|||||||
return e
|
return e
|
||||||
} else {
|
} else {
|
||||||
record := records[0]
|
record := records[0]
|
||||||
|
|
||||||
if record.Content == ip {
|
if record.Content == ip {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
record.Content = ip
|
return a.Api.UpdateDNSRecord(context.Background(), a.ZoneResource, cloudflare.UpdateDNSRecordParams{
|
||||||
return a.Api.UpdateDNSRecord(context.Background(), a.Zone, record.ID, record)
|
ID: record.ID,
|
||||||
|
Content: ip,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user