provider/powerdns: Clean up gofmt errors

This commit is contained in:
James Nugent 2016-01-25 12:50:58 -06:00
parent 3cfe3374a3
commit ff8cb7270e
5 changed files with 62 additions and 63 deletions

View File

@ -1,30 +1,31 @@
package powerdns
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"github.com/hashicorp/go-cleanhttp"
"fmt"
"encoding/json"
"bytes"
"io"
"strings"
"github.com/hashicorp/go-cleanhttp"
)
type Client struct {
// Location of PowerDNS server to use
ServerUrl string
// REST API Static authentication key
ApiKey string
Http *http.Client
ApiKey string
Http *http.Client
}
// NewClient returns a new PowerDNS client
func NewClient(serverUrl string, apiKey string) (*Client, error) {
client := Client{
ServerUrl:serverUrl,
ApiKey:apiKey,
Http: cleanhttp.DefaultClient(),
ServerUrl: serverUrl,
ApiKey: apiKey,
Http: cleanhttp.DefaultClient(),
}
return &client, nil
}
@ -58,27 +59,27 @@ func (c *Client) newRequest(method string, endpoint string, body []byte) (*http.
}
type ZoneInfo struct {
Id string `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
Kind string `json:"kind"`
DnsSec bool `json:"dnsssec"`
Serial int64 `json:"serial"`
Records []Record `json:"records,omitempty"`
Id string `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
Kind string `json:"kind"`
DnsSec bool `json:"dnsssec"`
Serial int64 `json:"serial"`
Records []Record `json:"records,omitempty"`
}
type Record struct {
Name string `json:"name"`
Type string `json:"type"`
Content string `json:"content"`
TTL int `json:"ttl"`
Disabled bool `json:"disabled"`
TTL int `json:"ttl"`
Disabled bool `json:"disabled"`
}
type ResourceRecordSet struct {
Name string `json:"name"`
Type string `json:"type"`
ChangeType string `json:"changetype"`
Name string `json:"name"`
Type string `json:"type"`
ChangeType string `json:"changetype"`
Records []Record `json:"records,omitempty"`
}
@ -101,7 +102,7 @@ func (rrSet *ResourceRecordSet) Id() string {
// Returns name and type of record or record set based on it's ID
func parseId(recId string) (string, string, error) {
s := strings.Split(recId, "-")
if (len(s) == 2) {
if len(s) == 2 {
return s[0], s[1], nil
} else {
return "", "", fmt.Errorf("Unknown record ID format")
@ -209,11 +210,11 @@ func (client *Client) RecordExistsByID(zone string, recId string) (bool, error)
func (client *Client) CreateRecord(zone string, record Record) (string, error) {
reqBody, _ := json.Marshal(zonePatchRequest{
RecordSets: []ResourceRecordSet{
ResourceRecordSet{
Name: record.Name,
Type: record.Type,
{
Name: record.Name,
Type: record.Type,
ChangeType: "REPLACE",
Records: []Record{record},
Records: []Record{record},
},
},
})
@ -246,7 +247,7 @@ func (client *Client) ReplaceRecordSet(zone string, rrSet ResourceRecordSet) (st
rrSet.ChangeType = "REPLACE"
reqBody, _ := json.Marshal(zonePatchRequest{
RecordSets: []ResourceRecordSet{rrSet },
RecordSets: []ResourceRecordSet{rrSet},
})
req, err := client.newRequest("PATCH", fmt.Sprintf("/servers/localhost/zones/%s", zone), reqBody)
@ -276,9 +277,9 @@ func (client *Client) ReplaceRecordSet(zone string, rrSet ResourceRecordSet) (st
func (client *Client) DeleteRecordSet(zone string, name string, tpe string) error {
reqBody, _ := json.Marshal(zonePatchRequest{
RecordSets: []ResourceRecordSet{
ResourceRecordSet{
Name: name,
Type: tpe,
{
Name: name,
Type: tpe,
ChangeType: "DELETE",
},
},
@ -315,4 +316,4 @@ func (client *Client) DeleteRecordSetByID(zone string, recId string) error {
} else {
return client.DeleteRecordSet(zone, name, tpe)
}
}
}

View File

@ -1,8 +1,8 @@
package powerdns
import (
"log"
"fmt"
"log"
)
type Config struct {

View File

@ -10,13 +10,13 @@ import (
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"api_key": &schema.Schema{
"api_key": {
Type: schema.TypeString,
Required: true,
DefaultFunc: envDefaultFunc("PDNS_API_KEY"),
Description: "REST API authentication key",
},
"server_url": &schema.Schema{
"server_url": {
Type: schema.TypeString,
Required: true,
DefaultFunc: envDefaultFunc("PDNS_SERVER_URL"),
@ -34,7 +34,7 @@ func Provider() terraform.ResourceProvider {
func providerConfigure(data *schema.ResourceData) (interface{}, error) {
config := Config{
ApiKey: data.Get("api_key").(string),
ApiKey: data.Get("api_key").(string),
ServerUrl: data.Get("server_url").(string),
}
@ -50,4 +50,3 @@ func envDefaultFunc(k string) schema.SchemaDefaultFunc {
return nil, nil
}
}

View File

@ -3,8 +3,9 @@ package powerdns
import (
"log"
"github.com/hashicorp/terraform/helper/schema"
"fmt"
"github.com/hashicorp/terraform/helper/schema"
)
func resourcePDNSRecord() *schema.Resource {
@ -15,43 +16,41 @@ func resourcePDNSRecord() *schema.Resource {
Exists: resourcePDNSRecordExists,
Schema: map[string]*schema.Schema{
"zone": &schema.Schema{
"zone": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"name": &schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"type": &schema.Schema{
"type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"ttl": &schema.Schema{
"ttl": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
},
"records": &schema.Schema{
"records": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Required: true,
ForceNew: true,
Set: schema.HashString,
},
},
}
}
func resourcePDNSRecordCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Client)
@ -64,10 +63,10 @@ func resourcePDNSRecordCreate(d *schema.ResourceData, meta interface{}) error {
ttl := d.Get("ttl").(int)
recs := d.Get("records").(*schema.Set).List()
if (len(recs) > 0) {
if len(recs) > 0 {
records := make([]Record, 0, len(recs))
for _, recContent := range recs {
records = append(records, Record{Name: rrSet.Name, Type:rrSet.Type, TTL: ttl, Content: recContent.(string)})
records = append(records, Record{Name: rrSet.Name, Type: rrSet.Type, TTL: ttl, Content: recContent.(string)})
}
rrSet.Records = records
@ -109,7 +108,7 @@ func resourcePDNSRecordRead(d *schema.ResourceData, meta interface{}) error {
}
d.Set("records", recs)
if (len(records) > 0) {
if len(records) > 0 {
d.Set("ttl", records[0].TTL)
}
@ -144,4 +143,4 @@ func resourcePDNSRecordExists(d *schema.ResourceData, meta interface{}) (bool, e
} else {
return exists, nil
}
}
}

View File

@ -14,7 +14,7 @@ func TestAccPDNSRecord_A(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckPDNSRecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testPDNSRecordConfigA,
Check: resource.ComposeTestCheckFunc(
testAccCheckPDNSRecordExists("powerdns_record.test-a"),
@ -30,7 +30,7 @@ func TestAccPDNSRecord_AAAA(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckPDNSRecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testPDNSRecordConfigAAAA,
Check: resource.ComposeTestCheckFunc(
testAccCheckPDNSRecordExists("powerdns_record.test-aaaa"),
@ -46,7 +46,7 @@ func TestAccPDNSRecord_CNAME(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckPDNSRecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testPDNSRecordConfigCNAME,
Check: resource.ComposeTestCheckFunc(
testAccCheckPDNSRecordExists("powerdns_record.test-cname"),
@ -62,7 +62,7 @@ func TestAccPDNSRecord_HINFO(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckPDNSRecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testPDNSRecordConfigHINFO,
Check: resource.ComposeTestCheckFunc(
testAccCheckPDNSRecordExists("powerdns_record.test-hinfo"),
@ -78,7 +78,7 @@ func TestAccPDNSRecord_LOC(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckPDNSRecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testPDNSRecordConfigLOC,
Check: resource.ComposeTestCheckFunc(
testAccCheckPDNSRecordExists("powerdns_record.test-loc"),
@ -94,13 +94,13 @@ func TestAccPDNSRecord_MX(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckPDNSRecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testPDNSRecordConfigMX,
Check: resource.ComposeTestCheckFunc(
testAccCheckPDNSRecordExists("powerdns_record.test-mx"),
),
},
resource.TestStep{
{
Config: testPDNSRecordConfigMXMulti,
Check: resource.ComposeTestCheckFunc(
testAccCheckPDNSRecordExists("powerdns_record.test-mx-multi"),
@ -116,7 +116,7 @@ func TestAccPDNSRecord_NAPTR(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckPDNSRecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testPDNSRecordConfigNAPTR,
Check: resource.ComposeTestCheckFunc(
testAccCheckPDNSRecordExists("powerdns_record.test-naptr"),
@ -132,7 +132,7 @@ func TestAccPDNSRecord_NS(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckPDNSRecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testPDNSRecordConfigNS,
Check: resource.ComposeTestCheckFunc(
testAccCheckPDNSRecordExists("powerdns_record.test-ns"),
@ -148,7 +148,7 @@ func TestAccPDNSRecord_SPF(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckPDNSRecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testPDNSRecordConfigSPF,
Check: resource.ComposeTestCheckFunc(
testAccCheckPDNSRecordExists("powerdns_record.test-spf"),
@ -164,7 +164,7 @@ func TestAccPDNSRecord_SSHFP(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckPDNSRecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testPDNSRecordConfigSSHFP,
Check: resource.ComposeTestCheckFunc(
testAccCheckPDNSRecordExists("powerdns_record.test-sshfp"),
@ -180,7 +180,7 @@ func TestAccPDNSRecord_SRV(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckPDNSRecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testPDNSRecordConfigSRV,
Check: resource.ComposeTestCheckFunc(
testAccCheckPDNSRecordExists("powerdns_record.test-srv"),
@ -196,7 +196,7 @@ func TestAccPDNSRecord_TXT(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckPDNSRecordDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testPDNSRecordConfigTXT,
Check: resource.ComposeTestCheckFunc(
testAccCheckPDNSRecordExists("powerdns_record.test-txt"),
@ -364,4 +364,4 @@ resource "powerdns_record" "test-txt" {
type = "TXT"
ttl = 60
records = [ "\"text record payload\"" ]
}`
}`