mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-12-11 22:56:09 +08:00
get-zones: generate R53_ALIAS right (#721)
* get-zones: generate R53_ALIAS right * R53_ALIAS.md: Examples should use ' not " * Handle TTLs
This commit is contained in:
parent
02e6a49bb8
commit
22b9afee3b
3 changed files with 98 additions and 9 deletions
|
|
@ -235,7 +235,7 @@ func GetZone(args GetZoneArgs) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("format %q unknown", args.OutputFile)
|
return fmt.Errorf("format %q unknown", args.OutputFormat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -245,9 +245,11 @@ func formatDsl(zonename string, rec *models.RecordConfig, defaultTTL uint32) str
|
||||||
|
|
||||||
target := rec.GetTargetCombined()
|
target := rec.GetTargetCombined()
|
||||||
|
|
||||||
|
ttl := uint32(0)
|
||||||
ttlop := ""
|
ttlop := ""
|
||||||
if rec.TTL != defaultTTL && rec.TTL != 0 {
|
if rec.TTL != defaultTTL && rec.TTL != 0 {
|
||||||
ttlop = fmt.Sprintf(", TTL(%d)", rec.TTL)
|
ttl = rec.TTL
|
||||||
|
ttlop = fmt.Sprintf(", TTL(%d)", ttl)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch rec.Type { // #rtype_variations
|
switch rec.Type { // #rtype_variations
|
||||||
|
|
@ -277,6 +279,8 @@ func formatDsl(zonename string, rec *models.RecordConfig, defaultTTL uint32) str
|
||||||
return fmt.Sprintf("NAMESERVER('%s')", target)
|
return fmt.Sprintf("NAMESERVER('%s')", target)
|
||||||
}
|
}
|
||||||
target = "'" + target + "'"
|
target = "'" + target + "'"
|
||||||
|
case "R53_ALIAS":
|
||||||
|
return makeR53alias(rec, ttl)
|
||||||
default:
|
default:
|
||||||
target = "'" + target + "'"
|
target = "'" + target + "'"
|
||||||
}
|
}
|
||||||
|
|
@ -295,3 +299,18 @@ func makeCaa(rec *models.RecordConfig, ttlop string) string {
|
||||||
|
|
||||||
// TODO(tlim): Generate a CAA_BUILDER() instead?
|
// TODO(tlim): Generate a CAA_BUILDER() instead?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeR53alias(rec *models.RecordConfig, ttl uint32) string {
|
||||||
|
items := []string{
|
||||||
|
"'" + rec.Name + "'",
|
||||||
|
"'" + rec.R53Alias["type"] + "'",
|
||||||
|
"'" + rec.GetTargetField() + "'",
|
||||||
|
}
|
||||||
|
if z, ok := rec.R53Alias["zone_id"]; ok {
|
||||||
|
items = append(items, "R53_ZONE('"+z+"')")
|
||||||
|
}
|
||||||
|
if ttl != 0 {
|
||||||
|
items = append(items, fmt.Sprintf("TTL(%d)", ttl))
|
||||||
|
}
|
||||||
|
return rec.Type + "(" + strings.Join(items, ", ") + ")"
|
||||||
|
}
|
||||||
|
|
|
||||||
70
commands/r53_test.go
Normal file
70
commands/r53_test.go
Normal file
|
|
@ -0,0 +1,70 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/StackExchange/dnscontrol/v3/models"
|
||||||
|
_ "github.com/StackExchange/dnscontrol/v3/providers/_all"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestR53Test_1(t *testing.T) {
|
||||||
|
rec := models.RecordConfig{
|
||||||
|
Type: "R53_ALIAS",
|
||||||
|
Name: "foo",
|
||||||
|
NameFQDN: "foo.domain.tld",
|
||||||
|
Target: "bar",
|
||||||
|
}
|
||||||
|
rec.R53Alias = make(map[string]string)
|
||||||
|
rec.R53Alias["type"] = "A"
|
||||||
|
w := `R53_ALIAS('foo', 'A', 'bar')`
|
||||||
|
if g := makeR53alias(&rec, 0); g != w {
|
||||||
|
t.Errorf("makeR53alias failure: got `%s` want `%s`", g, w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestR53Test_1ttl(t *testing.T) {
|
||||||
|
rec := models.RecordConfig{
|
||||||
|
Type: "R53_ALIAS",
|
||||||
|
Name: "foo",
|
||||||
|
NameFQDN: "foo.domain.tld",
|
||||||
|
Target: "bar",
|
||||||
|
}
|
||||||
|
rec.R53Alias = make(map[string]string)
|
||||||
|
rec.R53Alias["type"] = "A"
|
||||||
|
w := `R53_ALIAS('foo', 'A', 'bar', TTL(321))`
|
||||||
|
if g := makeR53alias(&rec, 321); g != w {
|
||||||
|
t.Errorf("makeR53alias failure: got `%s` want `%s`", g, w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestR53Test_2(t *testing.T) {
|
||||||
|
rec := models.RecordConfig{
|
||||||
|
Type: "R53_ALIAS",
|
||||||
|
Name: "foo",
|
||||||
|
NameFQDN: "foo.domain.tld",
|
||||||
|
Target: "bar",
|
||||||
|
}
|
||||||
|
rec.R53Alias = make(map[string]string)
|
||||||
|
rec.R53Alias["type"] = "A"
|
||||||
|
rec.R53Alias["zone_id"] = "blarg"
|
||||||
|
w := `R53_ALIAS('foo', 'A', 'bar', R53_ZONE('blarg'))`
|
||||||
|
if g := makeR53alias(&rec, 0); g != w {
|
||||||
|
t.Errorf("makeR53alias failure: got `%s` want `%s`", g, w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestR53Test_2ttl(t *testing.T) {
|
||||||
|
rec := models.RecordConfig{
|
||||||
|
Type: "R53_ALIAS",
|
||||||
|
Name: "foo",
|
||||||
|
NameFQDN: "foo.domain.tld",
|
||||||
|
Target: "bar",
|
||||||
|
}
|
||||||
|
rec.R53Alias = make(map[string]string)
|
||||||
|
rec.R53Alias["type"] = "A"
|
||||||
|
rec.R53Alias["zone_id"] = "blarg"
|
||||||
|
w := `R53_ALIAS('foo', 'A', 'bar', R53_ZONE('blarg'), TTL(123))`
|
||||||
|
if g := makeR53alias(&rec, 123); g != w {
|
||||||
|
t.Errorf("makeR53alias failure: got `%s` want `%s`", g, w)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -35,12 +35,12 @@ The zone id can be found depending on the target type:
|
||||||
{% include startExample.html %}
|
{% include startExample.html %}
|
||||||
{% highlight js %}
|
{% highlight js %}
|
||||||
|
|
||||||
D("example.com", REGISTRAR, DnsProvider("ROUTE53"),
|
D('example.com', REGISTRAR, DnsProvider('ROUTE53'),
|
||||||
R53_ALIAS("foo", "A", "bar"), // record in same zone
|
R53_ALIAS('foo', 'A', 'bar'), // record in same zone
|
||||||
R53_ALIAS("foo", "A", "bar", R53_ZONE('Z35SXDOTRQ7X7K')), // record in same zone, zone specified
|
R53_ALIAS('foo', 'A', 'bar', R53_ZONE('Z35SXDOTRQ7X7K')), // record in same zone, zone specified
|
||||||
R53_ALIAS("foo", "A", "blahblah.elasticloadbalancing.us-west-1.amazonaws.com", R53_ZONE('Z368ELLRRE2KJ0')), // a classic ELB in us-west-1
|
R53_ALIAS('foo', 'A', 'blahblah.elasticloadbalancing.us-west-1.amazonaws.com', R53_ZONE('Z368ELLRRE2KJ0')), // a classic ELB in us-west-1
|
||||||
R53_ALIAS("foo", "A", "blahblah.elasticbeanstalk.us-west-2.amazonaws.com", R53_ZONE('Z38NKT9BP95V3O')), // an Elastic Beanstalk environment in us-west-2
|
R53_ALIAS('foo', 'A', 'blahblah.elasticbeanstalk.us-west-2.amazonaws.com', R53_ZONE('Z38NKT9BP95V3O')), // an Elastic Beanstalk environment in us-west-2
|
||||||
R53_ALIAS("foo", "A", "blahblah-bucket.s3-website-us-west-1.amazonaws.com", R53_ZONE('Z2F56UZL2M1ACD')), // a website S3 Bucket in us-west-1
|
R53_ALIAS('foo', 'A', 'blahblah-bucket.s3-website-us-west-1.amazonaws.com', R53_ZONE('Z2F56UZL2M1ACD')), // a website S3 Bucket in us-west-1
|
||||||
);
|
);
|
||||||
|
|
||||||
{%endhighlight%}
|
{%endhighlight%}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue