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

[wip] update ns1/ns1-go to v2 #30

Open
wants to merge 3 commits into
base: v0.6.16-ens
Choose a base branch
from

Conversation

josephholsten
Copy link

we changed a bunch, so this will probably take a bit

client := meta.(*nsone.APIClient)
mj := nsone.Apikey{}
client := meta.(*nsone.Client)
mj := account.APIKey{}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think mj is short for monitoring job. not a big deal at all, but maybe this should be a or ak for apikey. but again, nbd

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

client := meta.(*nsone.APIClient)
mj, err := client.GetApikey(d.Id())
client := meta.(*nsone.Client)
mj, _, err := client.APIKeys.Get(d.Id())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here regarding mj

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolved

@@ -264,17 +269,25 @@ func recordToResourceData(d *schema.ResourceData, r *nsone.Record) error {
for regionName, region := range r.Regions {
newRegion := make(map[string]interface{})
newRegion["name"] = regionName
if len(region.Meta.GeoRegion) > 0 {
newRegion["georegion"] = region.Meta.GeoRegion[0]
// TODO: support as FeedPtr
Copy link

@pashap pashap Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do a switch on region.Meta.Georegion.(type) and check if either data.FeedPtr or []string?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems nasty to have to do to every metadata field tho...

but im not sure of a cleaner way

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's exactly what I'm working on now

n.RateLimitStrategySleep()
httpClient := &http.Client{}
n := nsone.NewClient(httpClient, nsone.SetAPIKey(d.Get("apikey").(string)))
// FIXME: n.Debug()
Copy link

@pashap pashap Sep 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wasnt sure what to do here either. v1 prints requests and responses when debug is enabled.

we can add a logger that logs every request with the following if that is what users would want.

    // Adds logging to each http request.
    doer := nsone.Decorate(httpClient, nsone.Logging(log.New(os.Stdout, "", log.LstdFlags)))
    client := nsone.NewClient(doer, nsone.SetAPIKey(k))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should also be tied to terraform's debug state

Copy link

@pashap pashap Sep 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, trying to find docs on terraform debug state now. We can add whatever logs to the requests/responses that we want with the decorator. my guess is that it should be logging both requests and responses. is their any documentation on the debug state?

httpClient := &http.Client{}
n := nsone.NewClient(httpClient, nsone.SetAPIKey(d.Get("apikey").(string)))
// FIXME: n.Debug()
// n.RateLimitStrategySleep()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still be applicable for v2. if users would like to have it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a divide by zero panic that I haven't had a change to investigate. I absolutely want to re-enable it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, im going to check that out now

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josephholsten I made a PR for the fix: ns1/ns1-go#24

The client was applying the rate limit func before checking the actual response code. I was able to reproduce divide by zero when i didnt set the apikey as an env var and received a 401(without rate limiting headers).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i merged in the rate limiting fix, so this should work now

df.Name = d.Get("name").(string)
config := make(map[string]string)
func resourceDataToDataFeed(d *schema.ResourceData) *data.Feed {
config := make(data.Config)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • investigate using the data.NewFeed() constructor

@josephholsten josephholsten force-pushed the update-ns1-to-v2 branch 2 times, most recently from 1ce7797 to 43aa452 Compare September 23, 2016 18:52
@josephholsten josephholsten force-pushed the update-ns1-to-v2 branch 4 times, most recently from a9afb26 to 7125f20 Compare November 1, 2016 20:28
@josephholsten
Copy link
Author

OK, all tests are passing again

Limits blocks only have the "name" attribute as their primary key, so
hashLimits() needn't use a buffer to concatenate.
Notable changes:
- update to import gopkg.in/ns1/ns1-go.v2/rest
- update to use rest.NewClient()
- update to use rest.*Service types for CRUD calls
- update to use gopkg.in/ns1/ns1-go.v2/rest/model/* packages for structs
- dramatic rewriting to support data.Meta
Copy link

@jmasseo jmasseo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"LGTM"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants