fix!: parse ttl correctly

This commit is contained in:
decentral1se 2021-12-23 01:41:12 +01:00
parent 844961d016
commit 0362928840
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
3 changed files with 27 additions and 10 deletions

View File

@ -113,13 +113,12 @@ var DNSValueFlag = &cli.StringFlag{
Destination: &DNSValue,
}
var DNSTTL int
var DNSTTLFlag = &cli.IntFlag{
var DNSTTL string
var DNSTTLFlag = &cli.StringFlag{
Name: "ttl",
Value: 600,
Value: "600s",
Aliases: []string{"T"},
Usage: "Domain name TTL value)",
Usage: "Domain name TTL value (seconds)",
Destination: &DNSTTL,
}

View File

@ -3,7 +3,6 @@ package record
import (
"fmt"
"strconv"
"time"
abraFormatter "coopcloud.tech/abra/cli/formatter"
"coopcloud.tech/abra/cli/internal"
@ -91,11 +90,16 @@ You may also invoke this command in "wizard" mode and be prompted for input
logrus.Fatal(err)
}
ttl, err := dns.GetTTL(internal.DNSTTL)
if err != nil {
return err
}
record := libdns.Record{
Type: internal.DNSType,
Name: internal.DNSName,
Value: internal.DNSValue,
TTL: time.Duration(internal.DNSTTL),
TTL: ttl,
}
if internal.DNSType == "MX" || internal.DNSType == "SRV" || internal.DNSType == "URI" {
@ -160,18 +164,23 @@ func autoConfigure(c *cli.Context, provider *gandi.Provider, zone string) error
return err
}
ttl, err := dns.GetTTL(internal.DNSTTL)
if err != nil {
return err
}
atRecord := libdns.Record{
Type: "A",
Name: "@",
Value: ipv4,
TTL: time.Duration(internal.DNSTTL),
TTL: ttl,
}
wildcardRecord := libdns.Record{
Type: "A",
Name: "*",
Value: ipv4,
TTL: time.Duration(internal.DNSTTL),
TTL: ttl,
}
records := []libdns.Record{atRecord, wildcardRecord}
@ -189,7 +198,7 @@ func autoConfigure(c *cli.Context, provider *gandi.Provider, zone string) error
if existingRecord.Type == record.Type &&
existingRecord.Name == record.Name &&
existingRecord.Value == record.Value {
logrus.Warnf("%s record for %s already exists?", record.Type, zone)
logrus.Warnf("%v for %s already exists?", record, zone)
continue
}
}

View File

@ -94,3 +94,12 @@ func EnsureDomainsResolveSameIPv4(domainName, server string) (string, error) {
return ipv4, nil
}
// GetTTL parses a ttl string into a duration
func GetTTL(ttl string) (time.Duration, error) {
val, err := time.ParseDuration(ttl)
if err != nil {
return val, err
}
return val, nil
}