Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DNSRecords Linter warnings #107

Merged
merged 1 commit into from
Oct 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions commands/dns-records.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,31 +50,34 @@ func (cmd *DNSRecords) Run(c *cli.Context) error {
}

// LoadRecords retrieves the records from DNSDock and processes/return them
// nolint: golint
func (cmd *DNSRecords) LoadRecords() ([]map[string]interface{}, error) {
if ip, ipErr := exec.Command("docker", "inspect", "--format", "{{.NetworkSettings.IPAddress}}", "dnsdock").Output(); ipErr == nil {
if response, httpErr := http.Get(fmt.Sprintf("http://%s/services", strings.Trim(string(ip), "\n"))); httpErr == nil && response.StatusCode == 200 {
defer response.Body.Close()
if body, readErr := ioutil.ReadAll(response.Body); readErr == nil {
if js, jsonErr := simplejson.NewJson(body); jsonErr == nil {
dnsdockMap, _ := js.Map()
records := []map[string]interface{}{}
for id, value := range dnsdockMap {
record := value.(map[string]interface{})
record["Id"] = id
records = append(records, record)
}
return records, nil
} else {
return nil, fmt.Errorf("Failed to parse dnsdock JSON: %s", jsonErr)
}
} else {
return nil, fmt.Errorf("Unable to get response from dnsdock. %s", readErr)
}
} else {
return nil, fmt.Errorf("Response from dnsdock: %s", httpErr)
}
} else {
return nil, fmt.Errorf("Failed to discover dnsdock IP address: %s", ipErr)
ip, err := exec.Command("docker", "inspect", "--format", "{{.NetworkSettings.IPAddress}}", "dnsdock").Output()
if err != nil {
return nil, fmt.Errorf("failed to discover dnsdock IP address: %s", err)
}

response, err := http.Get(fmt.Sprintf("http://%s/services", strings.Trim(string(ip), "\n")))
if err != nil || response.StatusCode != 200 {
return nil, fmt.Errorf("response from dnsdock: %s", err)
}

defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return nil, fmt.Errorf("unable to get response from dnsdock. %s", err)
}

js, err := simplejson.NewJson(body)
if err != nil {
return nil, fmt.Errorf("failed to parse dnsdock JSON: %s", err)
}

dnsdockMap, _ := js.Map()
records := []map[string]interface{}{}
for id, value := range dnsdockMap {
record := value.(map[string]interface{})
record["Id"] = id
records = append(records, record)
}
return records, nil
}