1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

VULTR: Update govultr to v1.0.0 (fixes #892) (#897)

This commit is contained in:
Patrick Gaskin
2020-10-08 16:12:56 -04:00
committed by GitHub
parent 38d9f059a7
commit 26c7c356f4
4 changed files with 31 additions and 17 deletions

2
go.mod
View File

@@ -48,7 +48,7 @@ require (
github.com/tdewolff/parse v2.3.4+incompatible // indirect github.com/tdewolff/parse v2.3.4+incompatible // indirect
github.com/tdewolff/test v1.0.6 // indirect github.com/tdewolff/test v1.0.6 // indirect
github.com/urfave/cli/v2 v2.2.0 github.com/urfave/cli/v2 v2.2.0
github.com/vultr/govultr v0.2.0 github.com/vultr/govultr v1.0.0
golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0 golang.org/x/net v0.0.0-20201006153459-a7d1128ccaa0
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43 golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43
golang.org/x/tools v0.0.0-20201007032633-0806396f153e // indirect golang.org/x/tools v0.0.0-20201007032633-0806396f153e // indirect

8
go.sum
View File

@@ -214,8 +214,8 @@ github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uP
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY= github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY=
github.com/hashicorp/go-retryablehttp v0.5.4/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-retryablehttp v0.5.4/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
github.com/hashicorp/go-retryablehttp v0.6.3 h1:tuulM+WnToeqa05z83YLmKabZxrySOmJAd4mJ+s2Nfg= github.com/hashicorp/go-retryablehttp v0.6.7 h1:8/CAEZt/+F7kR7GevNHulKkUjLht3CPmn7egmhieNKo=
github.com/hashicorp/go-retryablehttp v0.6.3/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-retryablehttp v0.6.7/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/hashicorp/go-rootcerts v1.0.1 h1:DMo4fmknnz0E0evoNYnV48RjWndOsmd6OW+09R3cEP8= github.com/hashicorp/go-rootcerts v1.0.1 h1:DMo4fmknnz0E0evoNYnV48RjWndOsmd6OW+09R3cEP8=
github.com/hashicorp/go-rootcerts v1.0.1/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= github.com/hashicorp/go-rootcerts v1.0.1/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8=
github.com/hashicorp/go-sockaddr v1.0.2 h1:ztczhD1jLxIRjVejw8gFomI1BQZOe2WoVOu0SyteCQc= github.com/hashicorp/go-sockaddr v1.0.2 h1:ztczhD1jLxIRjVejw8gFomI1BQZOe2WoVOu0SyteCQc=
@@ -335,8 +335,8 @@ github.com/tdewolff/test v1.0.6 h1:76mzYJQ83Op284kMT+63iCNCI7NEERsIN8dLM+RiKr4=
github.com/tdewolff/test v1.0.6/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE= github.com/tdewolff/test v1.0.6/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE=
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4= github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/vultr/govultr v0.2.0 h1:CZSNNCk+PHz9hzmfH2PFGkDgc3qNetwZqtcaqL8shlg= github.com/vultr/govultr v1.0.0 h1:yeJrYp9wyA4xXaQZ7eOL2u1wKn2JU79HjRevwvpxbJ4=
github.com/vultr/govultr v0.2.0/go.mod h1:glSLa57Jdj5s860EEc6+DEBbb/t3aUOKnB4gVPmDVlQ= github.com/vultr/govultr v1.0.0/go.mod h1:wZZXZbYbqyY1n3AldoeYNZK4Wnmmoq6dNFkvd5TV3ss=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

View File

@@ -29,14 +29,15 @@ func TestConversion(t *testing.T) {
Type: "SRV", Type: "SRV",
Name: "_ssh_.tcp", Name: "_ssh_.tcp",
Data: "5 22 ssh.example.com", Data: "5 22 ssh.example.com",
Priority: 5, Priority: intPtr(5),
TTL: 300, TTL: 300,
}, },
{ {
Type: "MX", Type: "MX",
Name: "", Name: "",
Data: "mail.example.com", Data: "mail.example.com",
TTL: 300, Priority: intPtr(0),
TTL: 300,
}, },
{ {
Type: "NS", Type: "NS",
@@ -66,8 +67,12 @@ func TestConversion(t *testing.T) {
converted := toVultrRecord(dc, rc, 0) converted := toVultrRecord(dc, rc, 0)
if converted.Type != record.Type || converted.Name != record.Name || converted.Data != record.Data || converted.Priority != record.Priority || converted.TTL != record.TTL { if converted.Type != record.Type || converted.Name != record.Name || converted.Data != record.Data || ((converted.Priority == nil) != (record.Priority == nil) || (converted.Priority != nil && *converted.Priority != *record.Priority)) || converted.TTL != record.TTL {
t.Error("Vultr record conversion mismatch", record, rc, converted) t.Error("Vultr record conversion mismatch", record, rc, converted)
} }
} }
} }
func intPtr(v int) *int {
return &v
}

View File

@@ -119,7 +119,7 @@ func (api *Provider) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Co
corrections = append(corrections, &models.Correction{ corrections = append(corrections, &models.Correction{
Msg: mod.String(), Msg: mod.String(),
F: func() error { F: func() error {
return api.client.DNSRecord.Create(context.Background(), dc.Name, r.Type, r.Name, r.Data, r.TTL, r.Priority) return api.client.DNSRecord.Create(context.Background(), dc.Name, r.Type, r.Name, r.Data, r.TTL, vultrPriority(r))
}, },
}) })
} }
@@ -191,10 +191,10 @@ func toRecordConfig(domain string, r *govultr.DNSRecord) (*models.RecordConfig,
if !strings.HasSuffix(data, ".") { if !strings.HasSuffix(data, ".") {
data = data + "." data = data + "."
} }
return rc, rc.SetTargetMX(uint16(r.Priority), data) return rc, rc.SetTargetMX(uint16(vultrPriority(r)), data)
case "SRV": case "SRV":
// Vultr returns SRV records in the format "[weight] [port] [target]". // Vultr returns SRV records in the format "[weight] [port] [target]".
return rc, rc.SetTargetSRVPriorityString(uint16(r.Priority), data) return rc, rc.SetTargetSRVPriorityString(uint16(vultrPriority(r)), data)
case "TXT": case "TXT":
// Remove quotes if it is a TXT record. // Remove quotes if it is a TXT record.
if !strings.HasPrefix(data, `"`) || !strings.HasSuffix(data, `"`) { if !strings.HasPrefix(data, `"`) || !strings.HasSuffix(data, `"`) {
@@ -225,13 +225,15 @@ func toVultrRecord(dc *models.DomainConfig, rc *models.RecordConfig, vultrID int
data = fmt.Sprintf(`"%s"`, data) data = fmt.Sprintf(`"%s"`, data)
} }
priority := 0 var priority *int
if rc.Type == "MX" { if rc.Type == "MX" {
priority = int(rc.MxPreference) tmp := int(rc.MxPreference)
priority = &tmp
} }
if rc.Type == "SRV" { if rc.Type == "SRV" {
priority = int(rc.SrvPriority) tmp := int(rc.SrvPriority)
priority = &tmp
} }
r := &govultr.DNSRecord{ r := &govultr.DNSRecord{
@@ -254,3 +256,10 @@ func toVultrRecord(dc *models.DomainConfig, rc *models.RecordConfig, vultrID int
return r return r
} }
func vultrPriority(r *govultr.DNSRecord) int {
if r.Priority == nil {
return 0
}
return *r.Priority
}