func DomainList(session rackspace.AuthSession) ([]Domain, error) { // TODO: Inspect the Catalog to ensure this session has CloudDNS ability req, _ := http.NewRequest("GET", session.ServiceCatalog().CloudDNS[0].PublicURL+"/domains", nil) req.Header.Set("Accept", "application/json") req.Header.Set("X-Auth-Token", session.Id()) resp, err := session.Client().Do(req) if err != nil { return nil, err } responseBody, _ := ioutil.ReadAll(resp.Body) switch resp.StatusCode { default: fallthrough case 401, 403, 400, 500, 503: return nil, errors.New(fmt.Sprintf("%s", responseBody)) case 200, 203: } domainListResponse := &DomainListResponse{rawJson: string(responseBody)} // Parse Response Body err = json.Unmarshal(responseBody, domainListResponse) if err != nil { return nil, err } return domainListResponse.Domains, nil }
func AddRecords(session rackspace.AuthSession, domain Domain, records []Record) (*rackspace.JobStatus, error) { recordList := RecordList{records} recordListJson, err := json.Marshal(recordList) if err != nil { return nil, err } // TODO: Inspect the Catalog to ensure this session has CloudDNS ability reqUrl := fmt.Sprintf("%s/domains/%d/records", session.ServiceCatalog().CloudDNS[0].PublicURL, domain.Id) req, _ := http.NewRequest("POST", reqUrl, bytes.NewBuffer(recordListJson)) req.Header.Set("Content-type", "application/json") req.Header.Set("Accept", "application/json") req.Header.Set("X-Auth-Token", session.Id()) resp, err := session.Client().Do(req) if err != nil { return nil, err } responseBody, _ := ioutil.ReadAll(resp.Body) switch resp.StatusCode { default: fallthrough case 400, 401, 404, 413, 500, 503: return nil, errors.New(fmt.Sprintf("%s", responseBody)) case 200, 202: } jobStatus := &rackspace.JobStatus{} err = json.Unmarshal(responseBody, jobStatus) if err != nil { return nil, err } return jobStatus, nil }