MAINT: Refactor GetDNSConfig (#1466)

* MAINT: Refactor GetDNSConfig

* do not return junk data
This commit is contained in:
Tom Limoncelli 2022-03-27 18:00:13 -04:00 committed by GitHub
parent 73de17adc2
commit 729672f039
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -95,29 +95,36 @@ func (args *GetDNSConfigArgs) flags() []cli.Flag {
// GetDNSConfig reads the json-formatted IR file. Or executes javascript. All depending on flags provided.
func GetDNSConfig(args GetDNSConfigArgs) (*models.DNSConfig, error) {
if args.JSONFile != "" {
var err error
cfg := &models.DNSConfig{}
if args.JSONFile == "" {
// No IR file specified. Generate the IR by running dnsconfig.json
// as normal.
cfg, err = ExecuteDSL(args.ExecuteDSLArgs)
if err != nil {
return nil, err
}
} else {
// Read an IR file.
f, err := os.Open(args.JSONFile)
if err != nil {
return nil, err
}
defer f.Close()
dec := json.NewDecoder(f)
cfg := &models.DNSConfig{}
if err = dec.Decode(cfg); err != nil {
return nil, err
}
return preloadProviders(cfg, nil)
}
return preloadProviders(ExecuteDSL(args.ExecuteDSLArgs))
return preloadProviders(cfg)
}
// the json only contains provider names inside domains. This denormalizes the data for more
// convenient access patterns. Does everything we need to prepare for the validation phase, but
// cannot do anything that requires the credentials file yet.
func preloadProviders(cfg *models.DNSConfig, err error) (*models.DNSConfig, error) {
if err != nil {
return cfg, err
}
func preloadProviders(cfg *models.DNSConfig) (*models.DNSConfig, error) {
//build name to type maps
cfg.RegistrarsByName = map[string]*models.RegistrarConfig{}
cfg.DNSProvidersByName = map[string]*models.DNSProviderConfig{}