mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-02-24 15:43:08 +08:00
MAINT: Refactor GetDNSConfig (#1466)
* MAINT: Refactor GetDNSConfig * do not return junk data
This commit is contained in:
parent
73de17adc2
commit
729672f039
1 changed files with 15 additions and 8 deletions
|
@ -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{}
|
||||
|
|
Loading…
Reference in a new issue