2020-02-18 21:59:18 +08:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2021-06-25 06:26:21 +08:00
|
|
|
"encoding/json"
|
2020-02-18 21:59:18 +08:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
2020-04-15 04:47:30 +08:00
|
|
|
"github.com/StackExchange/dnscontrol/v3/models"
|
2022-05-03 08:12:30 +08:00
|
|
|
"github.com/StackExchange/dnscontrol/v3/pkg/credsfile"
|
2020-04-15 04:47:30 +08:00
|
|
|
"github.com/StackExchange/dnscontrol/v3/pkg/prettyzone"
|
|
|
|
"github.com/StackExchange/dnscontrol/v3/providers"
|
2020-02-18 21:59:18 +08:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = cmd(catUtils, func() *cli.Command {
|
|
|
|
var args GetZoneArgs
|
|
|
|
return &cli.Command{
|
|
|
|
Name: "get-zones",
|
|
|
|
Aliases: []string{"get-zone"},
|
|
|
|
Usage: "gets a zone from a provider (stand-alone)",
|
|
|
|
Action: func(ctx *cli.Context) error {
|
|
|
|
if ctx.NArg() < 3 {
|
2021-12-14 22:47:32 +08:00
|
|
|
return cli.Exit("Arguments should be: credskey providername zone(s) (Ex: r53 ROUTE53 example.com)", 1)
|
2020-02-18 21:59:18 +08:00
|
|
|
}
|
|
|
|
args.CredName = ctx.Args().Get(0)
|
2022-05-09 02:23:45 +08:00
|
|
|
arg1 := ctx.Args().Get(1)
|
|
|
|
args.ProviderName = arg1
|
|
|
|
// In v4.0, skip the first args.ZoneNames if it it equals "-".
|
2020-02-18 21:59:18 +08:00
|
|
|
args.ZoneNames = ctx.Args().Slice()[2:]
|
2022-05-09 02:23:45 +08:00
|
|
|
|
|
|
|
if arg1 != "" && arg1 != "-" {
|
|
|
|
// NB(tlim): In v4.0 this "if" can be removed.
|
|
|
|
fmt.Fprintf(os.Stderr, "WARNING: To retain compatibility in future versions, please change %q to %q. See %q\n",
|
|
|
|
arg1, "-",
|
2023-01-30 02:14:22 +08:00
|
|
|
"https://docs.dnscontrol.org/commands/get-zones",
|
2022-05-09 02:23:45 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
return exit(GetZone(args))
|
|
|
|
},
|
|
|
|
Flags: args.flags(),
|
|
|
|
UsageText: "dnscontrol get-zones [command options] credkey provider zone [...]",
|
|
|
|
Description: `Download a zone from a provider. This is a stand-alone utility.
|
|
|
|
|
|
|
|
ARGUMENTS:
|
|
|
|
credkey: The name used in creds.json (first parameter to NewDnsProvider() in dnsconfig.js)
|
|
|
|
provider: The name of the provider (second parameter to NewDnsProvider() in dnsconfig.js)
|
|
|
|
zone: One or more zones (domains) to download; or "all".
|
|
|
|
|
|
|
|
FORMATS:
|
2020-03-10 23:32:47 +08:00
|
|
|
--format=js dnsconfig.js format (not perfect, just a decent first draft)
|
2020-06-18 21:37:09 +08:00
|
|
|
--format=djs js with disco commas (leading commas)
|
|
|
|
--format=zone BIND zonefile format
|
2020-03-09 23:42:48 +08:00
|
|
|
--format=tsv TAB separated value (useful for AWK)
|
|
|
|
--format=nameonly Just print the zone names
|
2020-02-18 21:59:18 +08:00
|
|
|
|
2020-03-10 23:32:47 +08:00
|
|
|
The columns in --format=tsv are:
|
|
|
|
FQDN (the label with the domain)
|
|
|
|
ShortName (just the label, "@" if it is the naked domain)
|
|
|
|
TTL
|
|
|
|
Record Type (A, AAAA, CNAME, etc.)
|
|
|
|
Target and arguments (quoted like in a zonefile)
|
2020-11-24 23:30:21 +08:00
|
|
|
Either empty or a comma-separated list of properties like "cloudflare_proxy=true"
|
2020-03-10 23:32:47 +08:00
|
|
|
|
|
|
|
The --ttl flag only applies to zone/js/djs formats.
|
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
EXAMPLES:
|
|
|
|
dnscontrol get-zones myr53 ROUTE53 example.com
|
2020-06-18 21:37:09 +08:00
|
|
|
dnscontrol get-zones gmain GANDI_V5 example.com other.com
|
2020-02-18 21:59:18 +08:00
|
|
|
dnscontrol get-zones cfmain CLOUDFLAREAPI all
|
2020-06-18 21:37:09 +08:00
|
|
|
dnscontrol get-zones --format=tsv bind BIND example.com
|
|
|
|
dnscontrol get-zones --format=djs --out=draft.js glcoud GCLOUD example.com`,
|
2020-02-18 21:59:18 +08:00
|
|
|
}
|
|
|
|
}())
|
|
|
|
|
2020-02-29 22:07:05 +08:00
|
|
|
// check-creds foo bar
|
|
|
|
// is the same as
|
|
|
|
// get-zones --format=nameonly foo bar all
|
|
|
|
var _ = cmd(catUtils, func() *cli.Command {
|
|
|
|
var args GetZoneArgs
|
|
|
|
return &cli.Command{
|
|
|
|
Name: "check-creds",
|
|
|
|
Usage: "Do a small operation to verify credentials (stand-alone)",
|
|
|
|
Action: func(ctx *cli.Context) error {
|
2022-05-09 02:23:45 +08:00
|
|
|
var arg0, arg1 string
|
|
|
|
// This takes one or two command-line args.
|
|
|
|
// Starting in v3.16: Using it with 2 args will generate a warning.
|
|
|
|
// Starting in v4.0: Using it with 2 args might be an error.
|
|
|
|
if ctx.NArg() == 1 {
|
|
|
|
arg0 = ctx.Args().Get(0)
|
|
|
|
arg1 = ""
|
|
|
|
} else if ctx.NArg() == 2 {
|
|
|
|
arg0 = ctx.Args().Get(0)
|
|
|
|
arg1 = ctx.Args().Get(1)
|
|
|
|
} else {
|
|
|
|
return cli.Exit("Arguments should be: credskey [providername] (Ex: r53 ROUTE53)", 1)
|
2020-02-29 22:07:05 +08:00
|
|
|
}
|
2022-05-09 02:23:45 +08:00
|
|
|
args.CredName = arg0
|
|
|
|
args.ProviderName = arg1
|
2020-02-29 22:07:05 +08:00
|
|
|
args.ZoneNames = []string{"all"}
|
|
|
|
args.OutputFormat = "nameonly"
|
|
|
|
return exit(GetZone(args))
|
|
|
|
},
|
|
|
|
Flags: args.flags(),
|
|
|
|
UsageText: "dnscontrol check-creds [command options] credkey provider",
|
|
|
|
Description: `Do a trivia operation to verify credentials. This is a stand-alone utility.
|
|
|
|
|
|
|
|
If successful, a list of zones will be output. If not, hopefully you
|
|
|
|
see verbose error messages.
|
|
|
|
|
|
|
|
ARGUMENTS:
|
|
|
|
credkey: The name used in creds.json (first parameter to NewDnsProvider() in dnsconfig.js)
|
|
|
|
provider: The name of the provider (second parameter to NewDnsProvider() in dnsconfig.js)
|
|
|
|
|
|
|
|
EXAMPLES:
|
2022-05-09 02:23:45 +08:00
|
|
|
dnscontrol check-creds myr53 ROUTE53 # Pre v3.16, or pre-v4.0 for backwards-compatibility
|
|
|
|
dnscontrol check-creds myr53
|
|
|
|
dnscontrol check-creds --out=/dev/null myr53 && echo Success`,
|
2020-02-29 22:07:05 +08:00
|
|
|
}
|
|
|
|
}())
|
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
// GetZoneArgs args required for the create-domain subcommand.
|
|
|
|
type GetZoneArgs struct {
|
|
|
|
GetCredentialsArgs // Args related to creds.json
|
|
|
|
CredName string // key in creds.json
|
2022-05-09 02:23:45 +08:00
|
|
|
ProviderName string // provider type: BIND, GANDI_V5, etc or "-" (NB(tlim): In 4.0, this field goes away.)
|
2020-02-18 21:59:18 +08:00
|
|
|
ZoneNames []string // The zones to get
|
|
|
|
OutputFormat string // Output format
|
|
|
|
OutputFile string // Filename to send output ("" means stdout)
|
|
|
|
DefaultTTL int // default TTL for providers where it is unknown
|
|
|
|
}
|
|
|
|
|
|
|
|
func (args *GetZoneArgs) flags() []cli.Flag {
|
|
|
|
flags := args.GetCredentialsArgs.flags()
|
|
|
|
flags = append(flags, &cli.StringFlag{
|
|
|
|
Name: "format",
|
|
|
|
Destination: &args.OutputFormat,
|
2020-03-09 23:42:48 +08:00
|
|
|
Value: "zone",
|
2020-03-10 23:32:47 +08:00
|
|
|
Usage: `Output format: js djs zone tsv nameonly`,
|
2020-02-18 21:59:18 +08:00
|
|
|
})
|
|
|
|
flags = append(flags, &cli.StringFlag{
|
|
|
|
Name: "out",
|
|
|
|
Destination: &args.OutputFile,
|
|
|
|
Usage: `Instead of stdout, write to this file`,
|
|
|
|
})
|
|
|
|
flags = append(flags, &cli.IntFlag{
|
|
|
|
Name: "ttl",
|
|
|
|
Destination: &args.DefaultTTL,
|
2020-02-25 20:23:40 +08:00
|
|
|
Usage: `Default TTL (0 picks the zone's most common TTL)`,
|
2020-02-18 21:59:18 +08:00
|
|
|
})
|
|
|
|
return flags
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetZone contains all data/flags needed to run get-zones, independently of CLI.
|
|
|
|
func GetZone(args GetZoneArgs) error {
|
|
|
|
var providerConfigs map[string]map[string]string
|
|
|
|
var err error
|
|
|
|
|
|
|
|
// Read it in:
|
2022-05-03 08:12:30 +08:00
|
|
|
providerConfigs, err = credsfile.LoadProviderConfigs(args.CredsFile)
|
2020-02-18 21:59:18 +08:00
|
|
|
if err != nil {
|
2022-03-26 03:20:30 +08:00
|
|
|
return fmt.Errorf("failed GetZone LoadProviderConfigs(%q): %w", args.CredsFile, err)
|
2020-02-18 21:59:18 +08:00
|
|
|
}
|
|
|
|
provider, err := providers.CreateDNSProvider(args.ProviderName, providerConfigs[args.CredName], nil)
|
|
|
|
if err != nil {
|
2022-05-09 02:23:45 +08:00
|
|
|
return fmt.Errorf("failed GetZone CDP: %w", err)
|
2020-02-18 21:59:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// decide which zones we need to convert
|
|
|
|
zones := args.ZoneNames
|
|
|
|
if len(args.ZoneNames) == 1 && args.ZoneNames[0] == "all" {
|
|
|
|
lister, ok := provider.(providers.ZoneLister)
|
|
|
|
if !ok {
|
2023-01-24 23:11:38 +08:00
|
|
|
return fmt.Errorf("provider type %s:%s cannot list zones to use the 'all' feature", args.CredName, args.ProviderName)
|
2020-02-18 21:59:18 +08:00
|
|
|
}
|
|
|
|
zones, err = lister.ListZones()
|
|
|
|
if err != nil {
|
2021-02-01 20:33:56 +08:00
|
|
|
return fmt.Errorf("failed GetZone LZ: %w", err)
|
2020-02-18 21:59:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-22 03:59:47 +08:00
|
|
|
// first open output stream and print initial header (if applicable)
|
|
|
|
w := os.Stdout
|
|
|
|
if args.OutputFile != "" {
|
|
|
|
w, err = os.Create(args.OutputFile)
|
|
|
|
}
|
|
|
|
if err != nil {
|
2021-02-01 20:33:56 +08:00
|
|
|
return fmt.Errorf("failed GetZone Create(%q): %w", args.OutputFile, err)
|
2020-02-22 03:59:47 +08:00
|
|
|
}
|
|
|
|
defer w.Close()
|
|
|
|
|
|
|
|
if args.OutputFormat == "nameonly" {
|
|
|
|
for _, zone := range zones {
|
|
|
|
fmt.Fprintln(w, zone)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-03-10 23:32:47 +08:00
|
|
|
// fetch all of the records
|
2020-02-18 21:59:18 +08:00
|
|
|
zoneRecs := make([]models.Records, len(zones))
|
|
|
|
for i, zone := range zones {
|
2023-05-03 01:04:59 +08:00
|
|
|
recs, err := provider.GetZoneRecords(zone, nil)
|
2020-02-18 21:59:18 +08:00
|
|
|
if err != nil {
|
2021-02-01 20:33:56 +08:00
|
|
|
return fmt.Errorf("failed GetZone gzr: %w", err)
|
2020-02-18 21:59:18 +08:00
|
|
|
}
|
|
|
|
zoneRecs[i] = recs
|
|
|
|
}
|
|
|
|
|
2020-03-10 23:32:47 +08:00
|
|
|
// Write the heading:
|
2020-02-18 21:59:18 +08:00
|
|
|
|
2022-07-19 23:21:37 +08:00
|
|
|
dspVariableName := "DSP_" + strings.ToUpper(args.CredName)
|
|
|
|
|
2020-03-10 23:32:47 +08:00
|
|
|
if args.OutputFormat == "js" || args.OutputFormat == "djs" {
|
2022-07-19 23:21:37 +08:00
|
|
|
|
|
|
|
if args.ProviderName == "-" {
|
|
|
|
fmt.Fprintf(w, `var %s = NewDnsProvider("%s");`+"\n",
|
|
|
|
dspVariableName, args.CredName)
|
|
|
|
} else {
|
|
|
|
fmt.Fprintf(w, `var %s = NewDnsProvider("%s", "%s");`+"\n",
|
|
|
|
dspVariableName, args.CredName, args.ProviderName)
|
|
|
|
}
|
|
|
|
fmt.Fprintf(w, `var REG_CHANGEME = NewRegistrar("none");`+"\n")
|
2020-02-18 21:59:18 +08:00
|
|
|
}
|
|
|
|
|
2020-03-10 23:32:47 +08:00
|
|
|
// print each zone
|
2020-02-18 21:59:18 +08:00
|
|
|
for i, recs := range zoneRecs {
|
|
|
|
zoneName := zones[i]
|
2020-02-22 03:59:47 +08:00
|
|
|
|
2020-02-23 02:27:24 +08:00
|
|
|
z := prettyzone.PrettySort(recs, zoneName, 0, nil)
|
2020-02-18 21:59:18 +08:00
|
|
|
switch args.OutputFormat {
|
2020-02-25 20:23:40 +08:00
|
|
|
|
2020-03-09 23:42:48 +08:00
|
|
|
case "zone":
|
2020-02-18 21:59:18 +08:00
|
|
|
fmt.Fprintf(w, "$ORIGIN %s.\n", zoneName)
|
2020-02-25 20:23:40 +08:00
|
|
|
prettyzone.WriteZoneFileRC(w, z.Records, zoneName, uint32(args.DefaultTTL), nil)
|
2020-02-18 21:59:18 +08:00
|
|
|
fmt.Fprintln(w)
|
|
|
|
|
2020-03-10 23:32:47 +08:00
|
|
|
case "js", "djs":
|
|
|
|
sep := ",\n\t" // Commas at EOL
|
|
|
|
if args.OutputFormat == "djs" {
|
|
|
|
sep = "\n\t, " // Funky comma mode
|
|
|
|
}
|
|
|
|
fmt.Fprintf(w, `D("%s", REG_CHANGEME%s`, zoneName, sep)
|
|
|
|
var o []string
|
2022-07-19 23:21:37 +08:00
|
|
|
o = append(o, fmt.Sprintf("DnsProvider(%s)", dspVariableName))
|
2020-02-25 20:23:40 +08:00
|
|
|
defaultTTL := uint32(args.DefaultTTL)
|
|
|
|
if defaultTTL == 0 {
|
|
|
|
defaultTTL = prettyzone.MostCommonTTL(recs)
|
|
|
|
}
|
2020-02-28 00:11:59 +08:00
|
|
|
if defaultTTL != models.DefaultTTL && defaultTTL != 0 {
|
2020-03-10 23:32:47 +08:00
|
|
|
o = append(o, fmt.Sprintf("DefaultTTL(%d)", defaultTTL))
|
2020-02-25 20:23:40 +08:00
|
|
|
}
|
2020-02-18 21:59:18 +08:00
|
|
|
for _, rec := range recs {
|
2022-08-29 22:18:39 +08:00
|
|
|
if (rec.Type == "CNAME") && (rec.Name == "@") {
|
|
|
|
o = append(o, "// NOTE: CNAME at apex may require manual editing.")
|
|
|
|
}
|
2020-03-10 23:32:47 +08:00
|
|
|
o = append(o, formatDsl(zoneName, rec, defaultTTL))
|
2020-02-18 21:59:18 +08:00
|
|
|
}
|
2020-03-10 23:32:47 +08:00
|
|
|
out := strings.Join(o, sep)
|
2022-08-29 22:18:39 +08:00
|
|
|
|
|
|
|
// Joining with a comma between each item works great but
|
|
|
|
// makes comments look terrible. Here we clean them up
|
|
|
|
// after the fact.
|
|
|
|
if args.OutputFormat == "djs" {
|
|
|
|
out = strings.ReplaceAll(out, "\n\t, //", "\n\t//, ") // Fix comments
|
|
|
|
out = strings.ReplaceAll(out,
|
|
|
|
"//, NOTE: CNAME at apex may require manual editing.",
|
|
|
|
"// NOTE: CNAME at apex may require manual editing.",
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
out = strings.ReplaceAll(out,
|
|
|
|
"// NOTE: CNAME at apex may require manual editing.,",
|
|
|
|
"// NOTE: CNAME at apex may require manual editing.",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
fmt.Fprint(w, out)
|
2020-02-18 21:59:18 +08:00
|
|
|
fmt.Fprint(w, "\n)\n")
|
2020-02-25 20:23:40 +08:00
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
case "tsv":
|
|
|
|
for _, rec := range recs {
|
2020-11-24 23:30:21 +08:00
|
|
|
|
|
|
|
cfproxy := ""
|
|
|
|
if cp, ok := rec.Metadata["cloudflare_proxy"]; ok {
|
|
|
|
if cp == "true" {
|
|
|
|
cfproxy = "\tcloudflare_proxy=true"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Fprintf(w, "%s\t%s\t%d\tIN\t%s\t%s%s\n",
|
|
|
|
rec.NameFQDN, rec.Name, rec.TTL, rec.Type, rec.GetTargetCombined(), cfproxy)
|
2020-02-18 21:59:18 +08:00
|
|
|
}
|
2020-02-25 20:23:40 +08:00
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
default:
|
2020-04-20 23:48:34 +08:00
|
|
|
return fmt.Errorf("format %q unknown", args.OutputFormat)
|
2020-02-18 21:59:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-06-25 06:26:21 +08:00
|
|
|
// jsonQuoted returns a properly escaped JSON string (without quotes).
|
|
|
|
func jsonQuoted(i string) string {
|
|
|
|
// https://stackoverflow.com/questions/51691901
|
|
|
|
b, err := json.Marshal(i)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return string(b)
|
|
|
|
}
|
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
func formatDsl(zonename string, rec *models.RecordConfig, defaultTTL uint32) string {
|
|
|
|
|
|
|
|
target := rec.GetTargetCombined()
|
|
|
|
|
2020-04-20 23:48:34 +08:00
|
|
|
ttl := uint32(0)
|
2020-02-18 21:59:18 +08:00
|
|
|
ttlop := ""
|
|
|
|
if rec.TTL != defaultTTL && rec.TTL != 0 {
|
2020-04-20 23:48:34 +08:00
|
|
|
ttl = rec.TTL
|
|
|
|
ttlop = fmt.Sprintf(", TTL(%d)", ttl)
|
2020-02-18 21:59:18 +08:00
|
|
|
}
|
|
|
|
|
2020-11-24 23:30:21 +08:00
|
|
|
cfproxy := ""
|
|
|
|
if cp, ok := rec.Metadata["cloudflare_proxy"]; ok {
|
|
|
|
if cp == "true" {
|
|
|
|
cfproxy = ", CF_PROXY_ON"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-18 21:59:18 +08:00
|
|
|
switch rec.Type { // #rtype_variations
|
2020-03-10 23:32:47 +08:00
|
|
|
case "CAA":
|
|
|
|
return makeCaa(rec, ttlop)
|
2023-05-08 20:08:26 +08:00
|
|
|
case "DS":
|
|
|
|
target = fmt.Sprintf("%d, %d, %d, '%s'", rec.DsKeyTag, rec.DsAlgorithm, rec.DsDigestType, rec.DsDigest)
|
2020-02-18 21:59:18 +08:00
|
|
|
case "MX":
|
|
|
|
target = fmt.Sprintf("%d, '%s'", rec.MxPreference, rec.GetTargetField())
|
2021-06-25 06:26:21 +08:00
|
|
|
case "NAPTR":
|
|
|
|
target = fmt.Sprintf(`%d, %d, %s, %s, %s, %s`,
|
|
|
|
rec.NaptrOrder, // 1
|
|
|
|
rec.NaptrPreference, // 10
|
|
|
|
jsonQuoted(rec.NaptrFlags), // U
|
|
|
|
jsonQuoted(rec.NaptrService), // E2U+sip
|
|
|
|
jsonQuoted(rec.NaptrRegexp), // regex
|
|
|
|
jsonQuoted(rec.GetTargetField()), // .
|
|
|
|
)
|
2020-03-10 23:32:47 +08:00
|
|
|
case "SSHFP":
|
|
|
|
target = fmt.Sprintf("%d, %d, '%s'", rec.SshfpAlgorithm, rec.SshfpFingerprint, rec.GetTargetField())
|
2020-02-18 21:59:18 +08:00
|
|
|
case "SOA":
|
2020-03-10 23:32:47 +08:00
|
|
|
rec.Type = "//SOA"
|
|
|
|
target = fmt.Sprintf("'%s', '%s', %d, %d, %d, %d, %d", rec.GetTargetField(), rec.SoaMbox, rec.SoaSerial, rec.SoaRefresh, rec.SoaRetry, rec.SoaExpire, rec.SoaMinttl)
|
|
|
|
case "SRV":
|
|
|
|
target = fmt.Sprintf("%d, %d, %d, '%s'", rec.SrvPriority, rec.SrvWeight, rec.SrvPort, rec.GetTargetField())
|
|
|
|
case "TLSA":
|
|
|
|
target = fmt.Sprintf("%d, %d, %d, '%s'", rec.TlsaUsage, rec.TlsaSelector, rec.TlsaMatchingType, rec.GetTargetField())
|
2020-02-18 21:59:18 +08:00
|
|
|
case "TXT":
|
|
|
|
if len(rec.TxtStrings) == 1 {
|
|
|
|
target = `'` + rec.TxtStrings[0] + `'`
|
|
|
|
} else {
|
|
|
|
target = `['` + strings.Join(rec.TxtStrings, `', '`) + `']`
|
|
|
|
}
|
2020-03-10 23:32:47 +08:00
|
|
|
// TODO(tlim): If this is an SPF record, generate a SPF_BUILDER().
|
2020-02-18 21:59:18 +08:00
|
|
|
case "NS":
|
|
|
|
// NS records at the apex should be NAMESERVER() records.
|
2020-05-22 22:20:10 +08:00
|
|
|
// DnsControl uses the API to get this info. NAMESERVER() is just
|
|
|
|
// to override that when needed.
|
2020-02-18 21:59:18 +08:00
|
|
|
if rec.Name == "@" {
|
2020-05-22 22:20:10 +08:00
|
|
|
return fmt.Sprintf("//NAMESERVER('%s')", target)
|
2020-02-18 21:59:18 +08:00
|
|
|
}
|
2020-03-10 23:32:47 +08:00
|
|
|
target = "'" + target + "'"
|
2020-04-20 23:48:34 +08:00
|
|
|
case "R53_ALIAS":
|
|
|
|
return makeR53alias(rec, ttl)
|
2020-02-18 21:59:18 +08:00
|
|
|
default:
|
|
|
|
target = "'" + target + "'"
|
|
|
|
}
|
|
|
|
|
2020-11-24 23:30:21 +08:00
|
|
|
return fmt.Sprintf("%s('%s', %s%s%s)", rec.Type, rec.Name, target, cfproxy, ttlop)
|
2020-03-10 23:32:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func makeCaa(rec *models.RecordConfig, ttlop string) string {
|
|
|
|
var target string
|
|
|
|
if rec.CaaFlag == 128 {
|
|
|
|
target = fmt.Sprintf("'%s', '%s', CAA_CRITICAL", rec.CaaTag, rec.GetTargetField())
|
|
|
|
} else {
|
|
|
|
target = fmt.Sprintf("'%s', '%s'", rec.CaaTag, rec.GetTargetField())
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s('%s', %s%s)", rec.Type, rec.Name, target, ttlop)
|
|
|
|
|
|
|
|
// TODO(tlim): Generate a CAA_BUILDER() instead?
|
2020-02-18 21:59:18 +08:00
|
|
|
}
|
2020-04-20 23:48:34 +08:00
|
|
|
|
|
|
|
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, ", ") + ")"
|
|
|
|
}
|