refactor!: remove auto dns, too magic, too broken
This commit is contained in:
parent
a33767f848
commit
9f2bb3f74f
|
@ -326,13 +326,6 @@ var StdErrOnlyFlag = &cli.BoolFlag{
|
|||
Destination: &StdErrOnly,
|
||||
}
|
||||
|
||||
var AutoDNSRecord bool
|
||||
var AutoDNSRecordFlag = &cli.BoolFlag{
|
||||
Name: "auto, a",
|
||||
Usage: "Automatically configure DNS records",
|
||||
Destination: &AutoDNSRecord,
|
||||
}
|
||||
|
||||
var DontWaitConverge bool
|
||||
var DontWaitConvergeFlag = &cli.BoolFlag{
|
||||
Name: "no-converge-checks, nc",
|
||||
|
|
|
@ -30,7 +30,6 @@ var RecordNewCommand = cli.Command{
|
|||
internal.DNSValueFlag,
|
||||
internal.DNSTTLFlag,
|
||||
internal.DNSPriorityFlag,
|
||||
internal.AutoDNSRecordFlag,
|
||||
},
|
||||
Before: internal.SubCommandBefore,
|
||||
Description: `
|
||||
|
@ -43,13 +42,7 @@ Example:
|
|||
|
||||
abra record new foo.com -p gandi -t A -n myapp -v 192.168.178.44
|
||||
|
||||
Typically, you need two records, an A record which points at the zone (@.) and
|
||||
a wildcard record for your apps (*.). Pass "--auto" to have Abra automatically
|
||||
set this up.
|
||||
|
||||
abra record new --auto foo.com -p gandi -v 192.168.178.44
|
||||
|
||||
You may also invoke this command in "wizard" mode and be prompted for input
|
||||
You may also invoke this command in "wizard" mode and be prompted for input:
|
||||
|
||||
abra record new
|
||||
|
||||
|
@ -75,25 +68,6 @@ You may also invoke this command in "wizard" mode and be prompted for input
|
|||
logrus.Fatalf("%s is not a supported DNS provider", internal.DNSProvider)
|
||||
}
|
||||
|
||||
if internal.AutoDNSRecord {
|
||||
ipv4, err := dns.EnsureIPv4(zone)
|
||||
if err != nil {
|
||||
logrus.Debugf("no ipv4 associated with %s, prompting for input", zone)
|
||||
if err := internal.EnsureDNSValueFlag(c); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
ipv4 = internal.DNSValue
|
||||
}
|
||||
|
||||
logrus.Infof("automatically configuring @./*. A records for %s for %s (--auto)", zone, ipv4)
|
||||
|
||||
if err := autoConfigure(c, &provider, zone, ipv4); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := internal.EnsureDNSTypeFlag(c); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
@ -173,84 +147,3 @@ You may also invoke this command in "wizard" mode and be prompted for input
|
|||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
func autoConfigure(c *cli.Context, provider *gandi.Provider, zone, ipv4 string) error {
|
||||
ttl, err := dns.GetTTL(internal.DNSTTL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
atRecord := libdns.Record{
|
||||
Type: "A",
|
||||
Name: "@",
|
||||
Value: ipv4,
|
||||
TTL: ttl,
|
||||
}
|
||||
|
||||
wildcardRecord := libdns.Record{
|
||||
Type: "A",
|
||||
Name: "*",
|
||||
Value: ipv4,
|
||||
TTL: ttl,
|
||||
}
|
||||
|
||||
records := []libdns.Record{atRecord, wildcardRecord}
|
||||
|
||||
tableCol := []string{"type", "name", "value", "TTL", "priority"}
|
||||
table := formatter.CreateTable(tableCol)
|
||||
|
||||
for _, record := range records {
|
||||
existingRecords, err := provider.GetRecords(context.Background(), zone)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
discovered := false
|
||||
for _, existingRecord := range existingRecords {
|
||||
if existingRecord.Type == record.Type &&
|
||||
existingRecord.Name == record.Name &&
|
||||
existingRecord.Value == record.Value {
|
||||
logrus.Warnf("%s record: %s %s for %s already exists?", record.Type, record.Name, record.Value, zone)
|
||||
discovered = true
|
||||
}
|
||||
}
|
||||
|
||||
if discovered {
|
||||
continue
|
||||
}
|
||||
|
||||
createdRecords, err := provider.SetRecords(
|
||||
context.Background(),
|
||||
zone,
|
||||
[]libdns.Record{record},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(createdRecords) == 0 {
|
||||
return fmt.Errorf("provider library reports that no record was created?")
|
||||
}
|
||||
|
||||
createdRecord := createdRecords[0]
|
||||
|
||||
value := createdRecord.Value
|
||||
if len(createdRecord.Value) > 30 {
|
||||
value = fmt.Sprintf("%s...", createdRecord.Value[:30])
|
||||
}
|
||||
|
||||
table.Append([]string{
|
||||
createdRecord.Type,
|
||||
createdRecord.Name,
|
||||
value,
|
||||
createdRecord.TTL.String(),
|
||||
strconv.Itoa(createdRecord.Priority),
|
||||
})
|
||||
}
|
||||
|
||||
if table.NumLines() > 0 {
|
||||
table.Render()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue