From 45198243f63587a3da21408248a9dbb865ae8256 Mon Sep 17 00:00:00 2001 From: Joseph Anthony Pasquale Holsten Date: Wed, 7 Sep 2016 09:33:47 -0700 Subject: [PATCH 1/2] vendor: update github.com/ns1/ns1-go The NS1 API previously lived at github.com/bobtfish/go-nsone-api, but has moved to github.com/ns1/ns1-go. This patch: - updates the godep pin - removes the github.com/bobtfish/go-nsone-api from vendor/ - adds github.com/ns1/ns1-go to vendor/ - updates all imports to refer to the new namespace Fixes #TF-53 --- Godeps/Godeps.json | 9 +- builtin/providers/nsone/provider.go | 2 +- builtin/providers/nsone/resource_apikey.go | 2 +- builtin/providers/nsone/resource_datafeed.go | 2 +- .../providers/nsone/resource_datafeed_test.go | 2 +- .../providers/nsone/resource_datasource.go | 2 +- .../nsone/resource_datasource_test.go | 2 +- .../providers/nsone/resource_monitoringjob.go | 2 +- .../nsone/resource_monitoringjob_test.go | 2 +- builtin/providers/nsone/resource_record.go | 2 +- .../providers/nsone/resource_record_test.go | 2 +- builtin/providers/nsone/resource_team.go | 2 +- builtin/providers/nsone/resource_user.go | 2 +- builtin/providers/nsone/resource_zone.go | 2 +- builtin/providers/nsone/resource_zone_test.go | 2 +- .../go-nsone-api => ns1/ns1-go}/.gitignore | 0 vendor/github.com/ns1/ns1-go/.travis.yml | 5 + .../go-nsone-api => ns1/ns1-go}/LICENSE.txt | 0 .../go-nsone-api => ns1/ns1-go}/Makefile | 0 .../README => ns1/ns1-go/README.md} | 0 .../go-nsone-api => ns1/ns1-go}/apikey.go | 1 + .../go-nsone-api => ns1/ns1-go}/datafeed.go | 6 +- .../go-nsone-api => ns1/ns1-go}/datasource.go | 13 ++- .../go-nsone-api => ns1/ns1-go}/monitoring.go | 18 ++- .../go-nsone-api => ns1/ns1-go}/nsone.go | 103 +++++++++++++----- .../go-nsone-api => ns1/ns1-go}/record.go | 15 ++- .../go-nsone-api => ns1/ns1-go}/team.go | 1 + .../go-nsone-api => ns1/ns1-go}/user.go | 8 ++ .../go-nsone-api => ns1/ns1-go}/zone.go | 24 +++- 29 files changed, 172 insertions(+), 59 deletions(-) rename vendor/github.com/{bobtfish/go-nsone-api => ns1/ns1-go}/.gitignore (100%) create mode 100644 vendor/github.com/ns1/ns1-go/.travis.yml rename vendor/github.com/{bobtfish/go-nsone-api => ns1/ns1-go}/LICENSE.txt (100%) rename vendor/github.com/{bobtfish/go-nsone-api => ns1/ns1-go}/Makefile (100%) rename vendor/github.com/{bobtfish/go-nsone-api/README => ns1/ns1-go/README.md} (100%) rename vendor/github.com/{bobtfish/go-nsone-api => ns1/ns1-go}/apikey.go (87%) rename vendor/github.com/{bobtfish/go-nsone-api => ns1/ns1-go}/datafeed.go (61%) rename vendor/github.com/{bobtfish/go-nsone-api => ns1/ns1-go}/datasource.go (56%) rename vendor/github.com/{bobtfish/go-nsone-api => ns1/ns1-go}/monitoring.go (76%) rename vendor/github.com/{bobtfish/go-nsone-api => ns1/ns1-go}/nsone.go (64%) rename vendor/github.com/{bobtfish/go-nsone-api => ns1/ns1-go}/record.go (69%) rename vendor/github.com/{bobtfish/go-nsone-api => ns1/ns1-go}/team.go (79%) rename vendor/github.com/{bobtfish/go-nsone-api => ns1/ns1-go}/user.go (80%) rename vendor/github.com/{bobtfish/go-nsone-api => ns1/ns1-go}/zone.go (67%) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 6b647b2f917d..c2ca0b248f6e 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -530,10 +530,6 @@ "ImportPath": "github.com/bgentry/speakeasy", "Rev": "36e9cfdd690967f4f690c6edcc9ffacd006014a0" }, - { - "ImportPath": "github.com/bobtfish/go-nsone-api", - "Rev": "f3fee829f41c32830c3ea01e00e0dd73f41cf08b" - }, { "ImportPath": "github.com/cenkalti/backoff", "Rev": "4dc77674aceaabba2c7e3da25d4c823edfb73f99" @@ -1015,6 +1011,11 @@ "Comment": "v0.2.0-8-g841842b", "Rev": "841842b16b39cf2b5007278956976d7d909bd98b" }, + { + "ImportPath": "github.com/ns1/ns1-go", + "Comment": "v1-2-g7c167e5", + "Rev": "7c167e5c28b7b40d82fb3d954daf7bfd55f9c6e2" + }, { "ImportPath": "github.com/nu7hatch/gouuid", "Rev": "179d4d0c4d8d407a32af483c2354df1d2c91e6c3" diff --git a/builtin/providers/nsone/provider.go b/builtin/providers/nsone/provider.go index a6805f715644..5b3940bb233a 100644 --- a/builtin/providers/nsone/provider.go +++ b/builtin/providers/nsone/provider.go @@ -1,7 +1,7 @@ package nsone import ( - "github.com/bobtfish/go-nsone-api" + "github.com/ns1/ns1-go" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/terraform" ) diff --git a/builtin/providers/nsone/resource_apikey.go b/builtin/providers/nsone/resource_apikey.go index fdaaa24bbd0e..723e705ac5dc 100644 --- a/builtin/providers/nsone/resource_apikey.go +++ b/builtin/providers/nsone/resource_apikey.go @@ -1,7 +1,7 @@ package nsone import ( - "github.com/bobtfish/go-nsone-api" + "github.com/ns1/ns1-go" "github.com/hashicorp/terraform/helper/schema" ) diff --git a/builtin/providers/nsone/resource_datafeed.go b/builtin/providers/nsone/resource_datafeed.go index 62b2fb2397ff..65117816e6b5 100644 --- a/builtin/providers/nsone/resource_datafeed.go +++ b/builtin/providers/nsone/resource_datafeed.go @@ -1,7 +1,7 @@ package nsone import ( - "github.com/bobtfish/go-nsone-api" + "github.com/ns1/ns1-go" "github.com/hashicorp/terraform/helper/schema" ) diff --git a/builtin/providers/nsone/resource_datafeed_test.go b/builtin/providers/nsone/resource_datafeed_test.go index fa06f3429df5..325cc07a0b83 100644 --- a/builtin/providers/nsone/resource_datafeed_test.go +++ b/builtin/providers/nsone/resource_datafeed_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/bobtfish/go-nsone-api" + "github.com/ns1/ns1-go" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) diff --git a/builtin/providers/nsone/resource_datasource.go b/builtin/providers/nsone/resource_datasource.go index fc77e809a03d..50ff27170dbc 100644 --- a/builtin/providers/nsone/resource_datasource.go +++ b/builtin/providers/nsone/resource_datasource.go @@ -1,7 +1,7 @@ package nsone import ( - "github.com/bobtfish/go-nsone-api" + "github.com/ns1/ns1-go" "github.com/hashicorp/terraform/helper/schema" ) diff --git a/builtin/providers/nsone/resource_datasource_test.go b/builtin/providers/nsone/resource_datasource_test.go index 15aa8bce1c77..8491803a20f0 100644 --- a/builtin/providers/nsone/resource_datasource_test.go +++ b/builtin/providers/nsone/resource_datasource_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/bobtfish/go-nsone-api" + "github.com/ns1/ns1-go" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) diff --git a/builtin/providers/nsone/resource_monitoringjob.go b/builtin/providers/nsone/resource_monitoringjob.go index 517b4b72d3b0..caba11381716 100644 --- a/builtin/providers/nsone/resource_monitoringjob.go +++ b/builtin/providers/nsone/resource_monitoringjob.go @@ -2,7 +2,7 @@ package nsone import ( "fmt" - "github.com/bobtfish/go-nsone-api" + "github.com/ns1/ns1-go" "github.com/hashicorp/terraform/helper/schema" "regexp" "strconv" diff --git a/builtin/providers/nsone/resource_monitoringjob_test.go b/builtin/providers/nsone/resource_monitoringjob_test.go index 70cb3cb4b35e..2a992b0f5110 100644 --- a/builtin/providers/nsone/resource_monitoringjob_test.go +++ b/builtin/providers/nsone/resource_monitoringjob_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/bobtfish/go-nsone-api" + "github.com/ns1/ns1-go" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) diff --git a/builtin/providers/nsone/resource_record.go b/builtin/providers/nsone/resource_record.go index 7626ddb96164..74ec2be6a9d6 100644 --- a/builtin/providers/nsone/resource_record.go +++ b/builtin/providers/nsone/resource_record.go @@ -4,7 +4,7 @@ import ( "bytes" "errors" "fmt" - "github.com/bobtfish/go-nsone-api" + "github.com/ns1/ns1-go" "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" "log" diff --git a/builtin/providers/nsone/resource_record_test.go b/builtin/providers/nsone/resource_record_test.go index 2cc3bc4623e5..f941324cbc3b 100644 --- a/builtin/providers/nsone/resource_record_test.go +++ b/builtin/providers/nsone/resource_record_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/bobtfish/go-nsone-api" + "github.com/ns1/ns1-go" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) diff --git a/builtin/providers/nsone/resource_team.go b/builtin/providers/nsone/resource_team.go index cfc2299438ed..e1fb4e9f259e 100644 --- a/builtin/providers/nsone/resource_team.go +++ b/builtin/providers/nsone/resource_team.go @@ -1,7 +1,7 @@ package nsone import ( - "github.com/bobtfish/go-nsone-api" + "github.com/ns1/ns1-go" "github.com/hashicorp/terraform/helper/schema" ) diff --git a/builtin/providers/nsone/resource_user.go b/builtin/providers/nsone/resource_user.go index 833fbf79b2a1..5fbd6ebf1cba 100644 --- a/builtin/providers/nsone/resource_user.go +++ b/builtin/providers/nsone/resource_user.go @@ -1,7 +1,7 @@ package nsone import ( - "github.com/bobtfish/go-nsone-api" + "github.com/ns1/ns1-go" "github.com/hashicorp/terraform/helper/schema" ) diff --git a/builtin/providers/nsone/resource_zone.go b/builtin/providers/nsone/resource_zone.go index d97461fd5234..3aea7f8472dc 100644 --- a/builtin/providers/nsone/resource_zone.go +++ b/builtin/providers/nsone/resource_zone.go @@ -3,7 +3,7 @@ package nsone import ( "strings" - "github.com/bobtfish/go-nsone-api" + "github.com/ns1/ns1-go" "github.com/hashicorp/terraform/helper/schema" ) diff --git a/builtin/providers/nsone/resource_zone_test.go b/builtin/providers/nsone/resource_zone_test.go index 43a9a23258f6..11ee097a69c1 100644 --- a/builtin/providers/nsone/resource_zone_test.go +++ b/builtin/providers/nsone/resource_zone_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/bobtfish/go-nsone-api" + "github.com/ns1/ns1-go" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) diff --git a/vendor/github.com/bobtfish/go-nsone-api/.gitignore b/vendor/github.com/ns1/ns1-go/.gitignore similarity index 100% rename from vendor/github.com/bobtfish/go-nsone-api/.gitignore rename to vendor/github.com/ns1/ns1-go/.gitignore diff --git a/vendor/github.com/ns1/ns1-go/.travis.yml b/vendor/github.com/ns1/ns1-go/.travis.yml new file mode 100644 index 000000000000..50f4b27eaf12 --- /dev/null +++ b/vendor/github.com/ns1/ns1-go/.travis.yml @@ -0,0 +1,5 @@ +language: go +go: +- 1.6.2 +script: script/test + diff --git a/vendor/github.com/bobtfish/go-nsone-api/LICENSE.txt b/vendor/github.com/ns1/ns1-go/LICENSE.txt similarity index 100% rename from vendor/github.com/bobtfish/go-nsone-api/LICENSE.txt rename to vendor/github.com/ns1/ns1-go/LICENSE.txt diff --git a/vendor/github.com/bobtfish/go-nsone-api/Makefile b/vendor/github.com/ns1/ns1-go/Makefile similarity index 100% rename from vendor/github.com/bobtfish/go-nsone-api/Makefile rename to vendor/github.com/ns1/ns1-go/Makefile diff --git a/vendor/github.com/bobtfish/go-nsone-api/README b/vendor/github.com/ns1/ns1-go/README.md similarity index 100% rename from vendor/github.com/bobtfish/go-nsone-api/README rename to vendor/github.com/ns1/ns1-go/README.md diff --git a/vendor/github.com/bobtfish/go-nsone-api/apikey.go b/vendor/github.com/ns1/ns1-go/apikey.go similarity index 87% rename from vendor/github.com/bobtfish/go-nsone-api/apikey.go rename to vendor/github.com/ns1/ns1-go/apikey.go index 5c18bfdd9f78..45124021a72e 100644 --- a/vendor/github.com/bobtfish/go-nsone-api/apikey.go +++ b/vendor/github.com/ns1/ns1-go/apikey.go @@ -1,5 +1,6 @@ package nsone +// Apikey wraps an NS1 /account/apikeys resource type Apikey struct { Id string `json:"id,omitempty"` Name string `json:"name"` diff --git a/vendor/github.com/bobtfish/go-nsone-api/datafeed.go b/vendor/github.com/ns1/ns1-go/datafeed.go similarity index 61% rename from vendor/github.com/bobtfish/go-nsone-api/datafeed.go rename to vendor/github.com/ns1/ns1-go/datafeed.go index 7b95c6bb41ae..dc5ada3a3401 100644 --- a/vendor/github.com/bobtfish/go-nsone-api/datafeed.go +++ b/vendor/github.com/ns1/ns1-go/datafeed.go @@ -1,5 +1,6 @@ package nsone +// DataFeed wraps an NS1 /data/feeds resource type DataFeed struct { SourceId string `json:"-"` Id string `json:"id,omitempty"` @@ -8,6 +9,7 @@ type DataFeed struct { Data map[string]interface{} `json:"data,omitempty"` } -func NewDataFeed(source_id string) *DataFeed { - return &DataFeed{SourceId: source_id} +// NewDataFeed takes a sourceID and creates a new *DataFeed +func NewDataFeed(sourceID string) *DataFeed { + return &DataFeed{SourceId: sourceID} } diff --git a/vendor/github.com/bobtfish/go-nsone-api/datasource.go b/vendor/github.com/ns1/ns1-go/datasource.go similarity index 56% rename from vendor/github.com/bobtfish/go-nsone-api/datasource.go rename to vendor/github.com/ns1/ns1-go/datasource.go index cd86684e6ff6..4c5bcb13a730 100644 --- a/vendor/github.com/bobtfish/go-nsone-api/datasource.go +++ b/vendor/github.com/ns1/ns1-go/datasource.go @@ -1,11 +1,13 @@ package nsone +// FeedDestination wraps an element of a DataSource's "destinations" attribute type FeedDestination struct { - Destid string `json"destif"` - Desttype string `json"desttype"` - Record string `json"record"` + Destid string `json:"destid"` + Desttype string `json:"desttype"` + Record string `json:"record"` } +// DataSource wraps an NS1 /data/sources resource type DataSource struct { Id string `json:"id,omitempty"` Name string `json:"name"` @@ -15,11 +17,12 @@ type DataSource struct { Destinations []FeedDestination `json:"destinations,omitempty"` } -func NewDataSource(name string, source_type string) *DataSource { +// NewDataSource takes a name and sourceType and creates a new *DataSource +func NewDataSource(name string, sourceType string) *DataSource { cf := make(map[string]string, 0) return &DataSource{ Name: name, - SourceType: source_type, + SourceType: sourceType, Config: cf, } } diff --git a/vendor/github.com/bobtfish/go-nsone-api/monitoring.go b/vendor/github.com/ns1/ns1-go/monitoring.go similarity index 76% rename from vendor/github.com/bobtfish/go-nsone-api/monitoring.go rename to vendor/github.com/ns1/ns1-go/monitoring.go index 28eadbe14936..0a967aa73d17 100644 --- a/vendor/github.com/bobtfish/go-nsone-api/monitoring.go +++ b/vendor/github.com/ns1/ns1-go/monitoring.go @@ -1,24 +1,36 @@ package nsone +// MonitoringJobTypes wraps an NS1 /monitoring/jobtypes resource type MonitoringJobTypes map[string]MonitoringJobType + +// MonitoringJobType wraps an element of MonitoringJobTypes type MonitoringJobType struct { ShortDesc string `json:"shortdesc"` Config MonitoringJobTypeConfig `json:"config"` Results MonitoringJobTypeResults `json:"results"` Desc string `json:"desc"` } + +// MonitoringJobTypeConfig wraps a MonitoringJobType's "config" attribute type MonitoringJobTypeConfig map[string]interface{} + +// MonitoringJobTypeResults wraps a MonitoringJobType's "results" attribute type MonitoringJobTypeResults map[string]MonitoringJobTypeResult + +// MonitoringJobTypeResult wraps an element of a MonitoringJobType's "results" attribute type MonitoringJobTypeResult struct { Comparators []string `json:"comparators"` Metric bool `json:"metric"` Validator string `json:"validator"` ShortDesc string `json:"shortdesc"` - Type string `json:type"` + Type string `json:"type"` Desc string `json:"desc"` } +// MonitoringJobs is just a MonitoringJob array type MonitoringJobs []MonitoringJob + +// MonitoringJob wraps an NS1 /monitoring/jobs resource type MonitoringJob struct { Id string `json:"id,omitempty"` Config map[string]interface{} `json:"config"` @@ -39,10 +51,14 @@ type MonitoringJob struct { NotifyRegional bool `json:"notidy_regional"` NotifyFailback bool `json:"notify_failback"` } + +// MonitoringJobStatus wraps an value of a MonitoringJob's "status" attribute type MonitoringJobStatus struct { Since int `json:"since"` Status string `json:"status"` } + +// MonitoringJobRule wraps an element of a MonitoringJob's "rules" attribute type MonitoringJobRule struct { Key string `json:"key"` Value interface{} `json:"value"` diff --git a/vendor/github.com/bobtfish/go-nsone-api/nsone.go b/vendor/github.com/ns1/ns1-go/nsone.go similarity index 64% rename from vendor/github.com/bobtfish/go-nsone-api/nsone.go rename to vendor/github.com/ns1/ns1-go/nsone.go index 79e19d8e5d1e..90da8e99d1ac 100644 --- a/vendor/github.com/bobtfish/go-nsone-api/nsone.go +++ b/vendor/github.com/ns1/ns1-go/nsone.go @@ -12,38 +12,45 @@ import ( "time" ) +// RateLimit stores X-Ratelimit-* headers type RateLimit struct { Limit int Remaining int Period int } +// PercentageLeft returns the ratio of Remaining to Limit as a percentage func (rl RateLimit) PercentageLeft() int { return rl.Remaining * 100 / rl.Limit } +// WaitTime returns the time.Duration ratio of Period to Limit func (rl RateLimit) WaitTime() time.Duration { return (time.Second * time.Duration(rl.Period)) / time.Duration(rl.Limit) } +// WaitTimeRemaining returns the time.Duration ratio of Period to Remaining func (rl RateLimit) WaitTimeRemaining() time.Duration { return (time.Second * time.Duration(rl.Period)) / time.Duration(rl.Remaining) } -func (a *APIClient) RateLimitStrategyNone() { - a.RateLimitFunc = defaultRateLimitFunc +// RateLimitStrategyNone sets RateLimitFunc to an empty func +func (c *APIClient) RateLimitStrategyNone() { + c.RateLimitFunc = defaultRateLimitFunc } -func (a *APIClient) RateLimitStrategySleep() { - a.RateLimitFunc = func(rl RateLimit) { +// RateLimitStrategySleep sets RateLimitFunc to sleep by WaitTimeRemaining +func (c *APIClient) RateLimitStrategySleep() { + c.RateLimitFunc = func(rl RateLimit) { remaining := rl.WaitTimeRemaining() - if a.debug { - log.Println("Rate limiting - Limit %d Remaining %d in period %d: Sleeping %dns", rl.Limit, rl.Remaining, rl.Period, remaining) + if c.debug { + log.Printf("Rate limiting - Limit %d Remaining %d in period %d: Sleeping %dns", rl.Limit, rl.Remaining, rl.Period, remaining) } time.Sleep(remaining) } } +// APIClient stores NS1 client state type APIClient struct { ApiKey string RateLimitFunc func(RateLimit) @@ -52,6 +59,7 @@ type APIClient struct { var defaultRateLimitFunc = func(rl RateLimit) {} +// New takes an API Key and creates an *APIClient func New(k string) *APIClient { return &APIClient{ ApiKey: k, @@ -60,6 +68,7 @@ func New(k string) *APIClient { } } +// Debug enables debug logging func (c *APIClient) Debug() { c.debug = true } @@ -67,7 +76,9 @@ func (c *APIClient) Debug() { func (c APIClient) doHTTP(method string, uri string, rbody []byte) ([]byte, int, error) { var body []byte r := bytes.NewReader(rbody) - log.Printf("[DEBUG] %s: %s (%s)", method, uri, string(rbody)) + if c.debug { + log.Printf("[DEBUG] %s: %s (%s)", method, uri, string(rbody)) + } req, err := http.NewRequest(method, uri, r) if err != nil { return body, 510, err @@ -78,7 +89,9 @@ func (c APIClient) doHTTP(method string, uri string, rbody []byte) ([]byte, int, if err != nil { return body, 510, err } - log.Println(resp) + if c.debug { + log.Println(resp) + } body, _ = ioutil.ReadAll(resp.Body) resp.Body.Close() if len(resp.Header["X-Ratelimit-Limit"]) > 0 { @@ -100,19 +113,21 @@ func (c APIClient) doHTTP(method string, uri string, rbody []byte) ([]byte, int, } } if resp.StatusCode != 200 { - return body, resp.StatusCode, errors.New(fmt.Sprintf("%s: %s", resp.Status, string(body))) + return body, resp.StatusCode, fmt.Errorf("%s: %s", resp.Status, string(body)) + } + if c.debug { + log.Println(fmt.Sprintf("Response body: %s", string(body))) } - log.Println(fmt.Sprintf("Response body: %s", string(body))) return body, resp.StatusCode, nil } -func (c APIClient) doHTTPUnmarshal(method string, uri string, rbody []byte, unpack_into interface{}) (int, error) { +func (c APIClient) doHTTPUnmarshal(method string, uri string, rbody []byte, unpackInto interface{}) (int, error) { body, status, err := c.doHTTP(method, uri, rbody) if err != nil { return status, err } - return status, json.Unmarshal(body, unpack_into) + return status, json.Unmarshal(body, unpackInto) } func (c APIClient) doHTTPBoth(method string, uri string, s interface{}) error { @@ -129,39 +144,41 @@ func (c APIClient) doHTTPDelete(uri string) error { return err } +// GetZones returns all active zones and basic zone configuration details for each func (c APIClient) GetZones() ([]Zone, error) { var zl []Zone _, err := c.doHTTPUnmarshal("GET", "https://api.nsone.net/v1/zones", nil, &zl) return zl, err } +// GetZone takes a zone and returns a single active zone and its basic configuration details func (c APIClient) GetZone(zone string) (*Zone, error) { z := NewZone(zone) - status, err := c.doHTTPUnmarshal("GET", fmt.Sprintf("https://api.nsone.net/v1/zones/%s", z.Zone), nil, z) - if status == 404 { - z.Id = "" - z.Zone = "" - return z, nil - } + _, err := c.doHTTPUnmarshal("GET", fmt.Sprintf("https://api.nsone.net/v1/zones/%s", z.Zone), nil, z) return z, err } +// DeleteZone takes a zone and destroys an existing DNS zone and all records in the zone func (c APIClient) DeleteZone(zone string) error { return c.doHTTPDelete(fmt.Sprintf("https://api.nsone.net/v1/zones/%s", zone)) } +// CreateZone takes a *Zone and creates a new DNS zone func (c APIClient) CreateZone(z *Zone) error { return c.doHTTPBoth("PUT", fmt.Sprintf("https://api.nsone.net/v1/zones/%s", z.Zone), z) } +// UpdateZone takes a *Zone and modifies basic details of a DNS zone func (c APIClient) UpdateZone(z *Zone) error { return c.doHTTPBoth("POST", fmt.Sprintf("https://api.nsone.net/v1/zones/%s", z.Zone), z) } +// CreateRecord takes a *Record and creates a new DNS record in the specified zone, for the specified domain, of the given record type func (c APIClient) CreateRecord(r *Record) error { return c.doHTTPBoth("PUT", fmt.Sprintf("https://api.nsone.net/v1/zones/%s/%s/%s", r.Zone, r.Domain, r.Type), r) } +// GetRecord takes a zone, domain and record type t and returns full configuration for a DNS record func (c APIClient) GetRecord(zone string, domain string, t string) (*Record, error) { r := NewRecord(zone, domain, t) status, err := c.doHTTPUnmarshal("GET", fmt.Sprintf("https://api.nsone.net/v1/zones/%s/%s/%s", r.Zone, r.Domain, r.Type), nil, r) @@ -175,38 +192,47 @@ func (c APIClient) GetRecord(zone string, domain string, t string) (*Record, err return r, err } +// DeleteRecord takes a zone, domain and record type t and removes an existing record and all associated answers and configuration details func (c APIClient) DeleteRecord(zone string, domain string, t string) error { return c.doHTTPDelete(fmt.Sprintf("https://api.nsone.net/v1/zones/%s/%s/%s", zone, domain, t)) } +// UpdateRecord takes a *Record and modifies configuration details for an existing DNS record func (c APIClient) UpdateRecord(r *Record) error { return c.doHTTPBoth("POST", fmt.Sprintf("https://api.nsone.net/v1/zones/%s/%s/%s", r.Zone, r.Domain, r.Type), r) } +// CreateDataSource takes a *DataSource and creates a new data source func (c APIClient) CreateDataSource(ds *DataSource) error { return c.doHTTPBoth("PUT", "https://api.nsone.net/v1/data/sources", ds) } +// GetDataSource takes an ID returns the details for a single data source func (c APIClient) GetDataSource(id string) (*DataSource, error) { ds := DataSource{} _, err := c.doHTTPUnmarshal("GET", fmt.Sprintf("https://api.nsone.net/v1/data/sources/%s", id), nil, &ds) return &ds, err } +// DeleteDataSource takes an ID and removes an existing data source and all connected feeds from the cource func (c APIClient) DeleteDataSource(id string) error { return c.doHTTPDelete(fmt.Sprintf("https://api.nsone.net/v1/data/sources/%s", id)) } +// UpdateDataSource takes a *DataSource modifies basic details of a data source func (c APIClient) UpdateDataSource(ds *DataSource) error { return c.doHTTPBoth("POST", fmt.Sprintf("https://api.nsone.net/v1/data/sources/%s", ds.Id), ds) } + +// CreateDataFeed takes a *DataFeed and connects a new data feed to an existing data source func (c APIClient) CreateDataFeed(df *DataFeed) error { return c.doHTTPBoth("PUT", fmt.Sprintf("https://api.nsone.net/v1/data/feeds/%s", df.SourceId), df) } -func (c APIClient) GetDataFeed(ds_id string, df_id string) (*DataFeed, error) { - df := NewDataFeed(ds_id) - status, err := c.doHTTPUnmarshal("GET", fmt.Sprintf("https://api.nsone.net/v1/data/feeds/%s/%s", ds_id, df_id), nil, df) +// GetDataFeed takes a data source ID and a data feed ID and returns the details of a single data feed +func (c APIClient) GetDataFeed(dsID string, dfID string) (*DataFeed, error) { + df := NewDataFeed(dsID) + status, err := c.doHTTPUnmarshal("GET", fmt.Sprintf("https://api.nsone.net/v1/data/feeds/%s/%s", dsID, dfID), nil, df) if status == 404 { df.SourceId = "" df.Id = "" @@ -216,49 +242,53 @@ func (c APIClient) GetDataFeed(ds_id string, df_id string) (*DataFeed, error) { return df, err } -func (c APIClient) DeleteDataFeed(ds_id string, df_id string) error { - return c.doHTTPDelete(fmt.Sprintf("https://api.nsone.net/v1/data/feeds/%s/%s", ds_id, df_id)) +// DeleteDataFeed takes a data source ID and a data feed ID and disconnects the feed from the data source and all attached destination metadata tables +func (c APIClient) DeleteDataFeed(dsID string, dfID string) error { + return c.doHTTPDelete(fmt.Sprintf("https://api.nsone.net/v1/data/feeds/%s/%s", dsID, dfID)) } +// UpdateDataFeed takes a *DataFeed and modifies and existing data feed func (c APIClient) UpdateDataFeed(df *DataFeed) error { return c.doHTTPBoth("POST", fmt.Sprintf("https://api.nsone.net/v1/data/feeds/%s/%s", df.SourceId, df.Id), df) } +// GetMonitoringJobTypes returns the list of all available monitoring job types func (c APIClient) GetMonitoringJobTypes() (MonitoringJobTypes, error) { var mjt MonitoringJobTypes _, err := c.doHTTPUnmarshal("GET", "https://api.nsone.net/v1/monitoring/jobtypes", nil, &mjt) return mjt, err } +// GetMonitoringJobs returns the list of all monitoring jobs for the account func (c APIClient) GetMonitoringJobs() (MonitoringJobs, error) { var mj MonitoringJobs _, err := c.doHTTPUnmarshal("GET", "https://api.nsone.net/v1/monitoring/jobs", nil, &mj) return mj, err } +// GetMonitoringJob takes an ID and returns details for a specific monitoring job func (c APIClient) GetMonitoringJob(id string) (MonitoringJob, error) { var mj MonitoringJob - status, err := c.doHTTPUnmarshal("GET", fmt.Sprintf("https://api.nsone.net/v1/monitoring/jobs/%s", id), nil, &mj) - if status == 404 { - mj.Id = "" - mj.Name = "" - return mj, nil - } + _, err := c.doHTTPUnmarshal("GET", fmt.Sprintf("https://api.nsone.net/v1/monitoring/jobs/%s", id), nil, &mj) return mj, err } +// CreateMonitoringJob takes a *MonitoringJob and creates a new monitoring job func (c APIClient) CreateMonitoringJob(mj *MonitoringJob) error { return c.doHTTPBoth("PUT", "https://api.nsone.net/v1/monitoring/jobs", mj) } +// DeleteMonitoringJob takes an ID and immediately terminates and deletes and existing monitoring job func (c APIClient) DeleteMonitoringJob(id string) error { return c.doHTTPDelete(fmt.Sprintf("https://api.nsone.net/v1/monitoring/jobs/%s", id)) } +// UpdateMonitoringJob takes a *MonitoringJob and change the configuration details of an existing monitoring job func (c APIClient) UpdateMonitoringJob(mj *MonitoringJob) error { return c.doHTTPBoth("POST", fmt.Sprintf("https://api.nsone.net/v1/monitoring/jobs/%s", mj.Id), mj) } +// GetQPSStats returns current queries per second (QPS) for the account func (c APIClient) GetQPSStats() (v float64, err error) { var s map[string]float64 _, err = c.doHTTPUnmarshal("GET", "https://api.nsone.net/v1/stats/qps", nil, &s) @@ -272,12 +302,14 @@ func (c APIClient) GetQPSStats() (v float64, err error) { return v, nil } +// GetUsers returns a list of all users with access to the account func (c APIClient) GetUsers() ([]User, error) { var users []User _, err := c.doHTTPUnmarshal("GET", "https://api.nsone.net/v1/account/users", nil, &users) return users, err } +// GetUser takes a username and returns the details for a single user func (c APIClient) GetUser(username string) (User, error) { var u User status, err := c.doHTTPUnmarshal("GET", fmt.Sprintf("https://api.nsone.net/v1/account/users/%s", username), nil, &u) @@ -289,24 +321,29 @@ func (c APIClient) GetUser(username string) (User, error) { return u, err } +// CreateUser takes a *User and creates a new user func (c APIClient) CreateUser(u *User) error { return c.doHTTPBoth("PUT", fmt.Sprintf("https://api.nsone.net/v1/account/users/%s", u.Username), &u) } +// DeleteUser takes a username and deletes a user from the account func (c APIClient) DeleteUser(username string) error { return c.doHTTPDelete(fmt.Sprintf("https://api.nsone.net/v1/account/users/%s", username)) } +// UpdateUser takes a *User and change contact details, notification settings or access rights for a user func (c APIClient) UpdateUser(user *User) error { return c.doHTTPBoth("POST", fmt.Sprintf("https://api.nsone.net/v1/account/users/%s", user.Username), user) } +// GetApikeys returns a list of all API keys under the account func (c APIClient) GetApikeys() ([]Apikey, error) { var apikeys []Apikey _, err := c.doHTTPUnmarshal("GET", "https://api.nsone.net/v1/account/apikeys", nil, &apikeys) return apikeys, err } +// GetApikey takes an ID and returns details, including permissions, for a single API key func (c APIClient) GetApikey(id string) (Apikey, error) { var k Apikey status, err := c.doHTTPUnmarshal("GET", fmt.Sprintf("https://api.nsone.net/v1/account/apikeys/%s", id), nil, &k) @@ -319,24 +356,29 @@ func (c APIClient) GetApikey(id string) (Apikey, error) { return k, err } +// CreateApikey takes an *Apikey and creates a new API key func (c APIClient) CreateApikey(k *Apikey) error { return c.doHTTPBoth("PUT", fmt.Sprintf("https://api.nsone.net/v1/account/apikeys/%s", k.Id), &k) } +// DeleteApikey takes an ID and deletes and API key func (c APIClient) DeleteApikey(id string) error { return c.doHTTPDelete(fmt.Sprintf("https://api.nsone.net/v1/account/apikeys/%s", id)) } +// UpdateApikey takes an *Apikey and change name or access rights for an API key func (c APIClient) UpdateApikey(k *Apikey) error { return c.doHTTPBoth("POST", fmt.Sprintf("https://api.nsone.net/v1/account/apikeys/%s", k.Id), k) } +// GetTeams returns a list of all teams under the account func (c APIClient) GetTeams() ([]Team, error) { var teams []Team _, err := c.doHTTPUnmarshal("GET", "https://api.nsone.net/v1/account/teams", nil, &teams) return teams, err } +// GetTeam takes an ID and returns details, including permissions, for a single team func (c APIClient) GetTeam(id string) (Team, error) { var t Team status, err := c.doHTTPUnmarshal("GET", fmt.Sprintf("https://api.nsone.net/v1/account/teams/%s", id), nil, &t) @@ -348,14 +390,17 @@ func (c APIClient) GetTeam(id string) (Team, error) { return t, err } +// CreateTeam takes a *Team and creates a new team func (c APIClient) CreateTeam(t *Team) error { return c.doHTTPBoth("PUT", "https://api.nsone.net/v1/account/teams", &t) } +// DeleteTeam takes an ID and deletes a team. Any users of API keys that belong to the team will be removed from the team. func (c APIClient) DeleteTeam(id string) error { return c.doHTTPDelete(fmt.Sprintf("https://api.nsone.net/v1/account/teams/%s", id)) } +// UpdateTeam takes a *Team and change name or access rights for a team func (c APIClient) UpdateTeam(t *Team) error { return c.doHTTPBoth("POST", fmt.Sprintf("https://api.nsone.net/v1/account/teams/%s", t.Id), t) } diff --git a/vendor/github.com/bobtfish/go-nsone-api/record.go b/vendor/github.com/ns1/ns1-go/record.go similarity index 69% rename from vendor/github.com/bobtfish/go-nsone-api/record.go rename to vendor/github.com/ns1/ns1-go/record.go index bae8e2913650..be62dcf843e8 100644 --- a/vendor/github.com/bobtfish/go-nsone-api/record.go +++ b/vendor/github.com/ns1/ns1-go/record.go @@ -1,17 +1,20 @@ package nsone +// Answer wraps the values of a Record's "filters" attribute type Answer struct { Region string `json:"region,omitempty"` Answer []string `json:"answer,omitempty"` Meta map[string]interface{} `json:"meta,omitempty"` } +// Filter wraps the values of a Record's "filters" attribute type Filter struct { Filter string `json:"filter"` Disabled bool `json:"disabled,omitempty"` Config map[string]interface{} `json:"config"` } +// Record wraps an NS1 /zone/{zone}/{domain}/{type} resource type Record struct { Id string `json:"id,omitempty"` Zone string `json:"zone,omitempty"` @@ -26,10 +29,12 @@ type Record struct { Regions map[string]Region `json:"regions,omitempty"` } +// Region wraps the values of a Record's "regions" attribute type Region struct { Meta RegionMeta `json:"meta"` } +// RegionMeta wraps the values of a Record's "regions.*.meta" attribute type RegionMeta struct { GeoRegion []string `json:"georegion,omitempty"` Country []string `json:"country,omitempty"` @@ -37,12 +42,15 @@ type RegionMeta struct { Up bool `json:"up,omitempty"` } +// MetaFeed wraps an Answer.Metadata element which points to a feed type MetaFeed struct { Feed string `json:"feed"` } +// MetaStatic wraps an Answer.Metadata element which just wraps a string type MetaStatic string +// NewRecord takes a zone, domain and record type t and creates a *Record with UseClientSubnet: true & empty Answers func NewRecord(zone string, domain string, t string) *Record { return &Record{ Zone: zone, @@ -53,18 +61,21 @@ func NewRecord(zone string, domain string, t string) *Record { } } +// NewAnswer creates an empty Answer func NewAnswer() Answer { return Answer{ Meta: make(map[string]interface{}), } } -func NewMetaFeed(feed_id string) MetaFeed { +// NewMetaFeed takes a feed_id and creates a MetaFeed +func NewMetaFeed(feedID string) MetaFeed { return MetaFeed{ - Feed: feed_id, + Feed: feedID, } } +// LinkTo sets a Record Link to an FQDN and ensures no other record configuration is specified func (r *Record) LinkTo(to string) { r.Meta = nil r.Answers = make([]Answer, 0) diff --git a/vendor/github.com/bobtfish/go-nsone-api/team.go b/vendor/github.com/ns1/ns1-go/team.go similarity index 79% rename from vendor/github.com/bobtfish/go-nsone-api/team.go rename to vendor/github.com/ns1/ns1-go/team.go index a4ecb3499a95..8956ce3eb900 100644 --- a/vendor/github.com/bobtfish/go-nsone-api/team.go +++ b/vendor/github.com/ns1/ns1-go/team.go @@ -1,5 +1,6 @@ package nsone +// Team wraps an NS1 /accounts/teams resource type Team struct { Id string `json:"id,omitempty"` Name string `json:"name"` diff --git a/vendor/github.com/bobtfish/go-nsone-api/user.go b/vendor/github.com/ns1/ns1-go/user.go similarity index 80% rename from vendor/github.com/bobtfish/go-nsone-api/user.go rename to vendor/github.com/ns1/ns1-go/user.go index 19e6e3e4df6e..b612801c54c8 100644 --- a/vendor/github.com/bobtfish/go-nsone-api/user.go +++ b/vendor/github.com/ns1/ns1-go/user.go @@ -1,5 +1,6 @@ package nsone +// User wraps an NS1 /account/users resource type User struct { Name string `json:"name"` Username string `json:"username"` @@ -10,10 +11,12 @@ type User struct { Permissions PermissionsMap `json:"permissions"` } +// NotificationSettings wraps a User's "notify" attribute type NotificationSettings struct { Billing bool `json:"billing"` } +// PermissionsMap wraps a User's "permissions" attribute type PermissionsMap struct { Dns PermissionsDns `json:"dns"` Data PermissionsData `json:"data"` @@ -21,6 +24,7 @@ type PermissionsMap struct { Monitoring PermissionsMonitoring `json:"monitoring"` } +// PermissionsDns wraps a User's "permissions.dns" attribute type PermissionsDns struct { ViewZones bool `json:"view_zones"` ManageZones bool `json:"manage_zones"` @@ -29,12 +33,14 @@ type PermissionsDns struct { ZonesAllow []string `json:"zones_allow"` } +// PermissionsData wraps a User's "permissions.data" attribute type PermissionsData struct { PushToDatafeeds bool `json:"push_to_datafeeds"` ManageDatasources bool `json:"manage_datasources"` ManageDatafeeds bool `json:"manage_datafeeds"` } +// PermissionsAccount wraps a User's "permissions.account" attribute type PermissionsAccount struct { ManageUsers bool `json:"manage_users"` ManagePaymentMethods bool `json:"manage_payment_methods"` @@ -45,6 +51,8 @@ type PermissionsAccount struct { ViewActivityLog bool `json:"view_activity_log"` ViewInvoices bool `json:"view_invoices"` } + +// PermissionsMonitoring wraps a User's "permissions.monitoring" attribute type PermissionsMonitoring struct { ManageLists bool `json:"manage_lists"` ManageJobs bool `json:"manage_jobs"` diff --git a/vendor/github.com/bobtfish/go-nsone-api/zone.go b/vendor/github.com/ns1/ns1-go/zone.go similarity index 67% rename from vendor/github.com/bobtfish/go-nsone-api/zone.go rename to vendor/github.com/ns1/ns1-go/zone.go index 6f5dd2120f38..85571a3add20 100644 --- a/vendor/github.com/bobtfish/go-nsone-api/zone.go +++ b/vendor/github.com/ns1/ns1-go/zone.go @@ -1,16 +1,19 @@ package nsone +// ZoneSecondaryServer wraps elements of a Zone's "primary.secondary" attribute type ZoneSecondaryServer struct { Ip string `json:"ip"` Port int `json:"port,omitempty"` Notify bool `json:"notify"` } +// ZonePrimary wraps a Zone's "primary" attribute type ZonePrimary struct { Enabled bool `json:"enabled"` Secondaries []ZoneSecondaryServer `json:"secondaries"` } +// ZoneSecondary wraps a Zone's "secondary" attribute type ZoneSecondary struct { Status string `json:"status,omitempty"` Last_xfr int `json:"last_xfr,omitempty"` @@ -20,6 +23,18 @@ type ZoneSecondary struct { Expired bool `json:"expired,omitempty"` } +// ZoneRecord wraps Zone's "records" attribute +type ZoneRecord struct { + Domain string `json:"Domain,omitempty"` + Id string `json:"id,omitempty"` + Link string `json:"link,omitempty"` + ShortAns []string `json:"short_answers,omitempty"` + Tier int `json:"tier,omitempty"` + Ttl int `json:"ttl,omitempty"` + Type string `json:"type,omitempty"` +} + +// Zone wraps an NS1 /zone resource type Zone struct { Id string `json:"id,omitempty"` Ttl int `json:"ttl,omitempty"` @@ -37,8 +52,11 @@ type Zone struct { Meta map[string]string `json:"meta,omitempty"` Secondary *ZoneSecondary `json:"secondary,omitempty"` Link string `json:"link,omitempty"` + Records []ZoneRecord `json:"records,omitempty"` + Serial int `json:"serial,omitempty"` } +// NewZone takes a zone domain name and creates a new primary *Zone func NewZone(zone string) *Zone { z := Zone{ Zone: zone, @@ -47,6 +65,7 @@ func NewZone(zone string) *Zone { return &z } +// MakePrimary enables Primary, disables Secondary, and sets primary's Secondaries to all provided ZoneSecondaryServers func (z *Zone) MakePrimary(secondaries ...ZoneSecondaryServer) { z.Secondary = nil z.Primary = &ZonePrimary{ @@ -58,19 +77,20 @@ func (z *Zone) MakePrimary(secondaries ...ZoneSecondaryServer) { } } +// MakeSecondary enables Secondary, disables Primary, and sets secondary's Primary_ip to provided ip func (z *Zone) MakeSecondary(ip string) { z.Secondary = &ZoneSecondary{ Enabled: true, Primary_ip: ip, Primary_port: 53, } - s := make([]ZoneSecondaryServer, 0) z.Primary = &ZonePrimary{ Enabled: false, - Secondaries: s, + Secondaries: make([]ZoneSecondaryServer, 0), } } +// LinkTo sets Link to a target zone domain name and unsets all other configuration properties func (z *Zone) LinkTo(to string) { z.Meta = nil z.Ttl = 0 From 32f4e655c3c9b9aa40c2c1a89265bd7ea1ec19ce Mon Sep 17 00:00:00 2001 From: Alejandro Figueroa Date: Fri, 2 Sep 2016 17:43:29 -0400 Subject: [PATCH 2/2] nsone: fix ns1-go test bugs - Clarify testAccCheckMonitoringJobDestroy error message when Monitoring Job still exists - Clarify testAccCheckZoneDestroy error message when Zone still exists - Fix testAccRecordBasic fixture to use correct zone dependency Fixes #TF-54 --- builtin/providers/nsone/resource_monitoringjob_test.go | 4 ++-- builtin/providers/nsone/resource_record_test.go | 2 +- builtin/providers/nsone/resource_zone_test.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/builtin/providers/nsone/resource_monitoringjob_test.go b/builtin/providers/nsone/resource_monitoringjob_test.go index 2a992b0f5110..1f19dbf23533 100644 --- a/builtin/providers/nsone/resource_monitoringjob_test.go +++ b/builtin/providers/nsone/resource_monitoringjob_test.go @@ -116,10 +116,10 @@ func testAccCheckMonitoringJobDestroy(s *terraform.State) error { continue } - _, err := client.GetMonitoringJob(rs.Primary.Attributes["id"]) + mj, err := client.GetMonitoringJob(rs.Primary.Attributes["id"]) if err == nil { - return fmt.Errorf("Record still exists") + return fmt.Errorf("Monitoring Job still exists %#v: %#v", err, mj) } } diff --git a/builtin/providers/nsone/resource_record_test.go b/builtin/providers/nsone/resource_record_test.go index f941324cbc3b..d7653276461b 100644 --- a/builtin/providers/nsone/resource_record_test.go +++ b/builtin/providers/nsone/resource_record_test.go @@ -195,7 +195,7 @@ func testAccCheckRecordAttributesUpdated(record *nsone.Record) resource.TestChec const testAccRecordBasic = ` resource "nsone_record" "foobar" { - zone = "terraform.io" + zone = "${nsone_zone.test.zone}" domain = "test.terraform.io" type = "CNAME" ttl = 60 diff --git a/builtin/providers/nsone/resource_zone_test.go b/builtin/providers/nsone/resource_zone_test.go index 11ee097a69c1..69ec8e2cd20d 100644 --- a/builtin/providers/nsone/resource_zone_test.go +++ b/builtin/providers/nsone/resource_zone_test.go @@ -116,10 +116,10 @@ func testAccCheckZoneDestroy(s *terraform.State) error { continue } - _, err := client.GetZone(rs.Primary.Attributes["zone"]) + zone, err := client.GetZone(rs.Primary.Attributes["zone"]) if err == nil { - return fmt.Errorf("Record still exists") + return fmt.Errorf("Record still exists: %#v: %#v", err, zone) } }