-
Notifications
You must be signed in to change notification settings - Fork 30
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
v2: added support for DevicesResource #90
Conversation
for _, pathElement := range pathElements { | ||
elem = append(elem, fmt.Sprint(pathElement)) | ||
} | ||
return c.BaseURL.JoinPath(elem...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does JoinPath
handle URL encoding / escaping the strings under the hood? e.g, if we end up with an /tailnet/mario@example.com/
URL does the @
get properly escaped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that was my reason for using it.
v2/devices.go
Outdated
|
||
// List lists the devices in a tailnet. | ||
func (dr *DevicesResource) List(ctx context.Context) ([]Device, error) { | ||
req, err := dr.buildRequest(ctx, http.MethodGet, dr.buildURL("api", "v2", "tailnet", dr.Tailnet, "devices")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: could maybe have a buildV2URL
helper or something similar that prefixes with /api/v2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, I can just make that part of buildURL
, as I suspect all of our URLs will be api/v2
v2/devices.go
Outdated
return nil, err | ||
} | ||
|
||
return &device, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have also seen us do something more similar to the following format:
var device Device
return &device, dr.performRequest(req, &device)
Not sure if we have a preference between the two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, we can do even better, hang on ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you like it now?
v2/devices_test.go
Outdated
assert.Equal(t, server.ResponseBody, routes) | ||
} | ||
|
||
func TestClient_AuthorizeDevice(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we can likely drop this test since it looks like we've removed AuthorizeDevice
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
554f9f4
to
cd64779
Compare
v2/client.go
Outdated
@@ -224,12 +236,13 @@ func (c *Client) performRequest(req *http.Request, out interface{}) error { | |||
} | |||
} | |||
|
|||
return json.Unmarshal(body, out) | |||
err = json.Unmarshal(body, out) | |||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
return err | |
return json.Unmarshal(body, out) |
} | ||
|
||
if res.StatusCode != http.StatusOK && res.StatusCode != http.StatusCreated { | ||
var apiErr APIError | ||
if err = json.Unmarshal(body, &apiErr); err != nil { | ||
if err := json.Unmarshal(body, &apiErr); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit x 2 if the above is accepted to bring it back to how it was:
if err := json.Unmarshal(body, &apiErr); err != nil { | |
if err = json.Unmarshal(body, &apiErr); err != nil { |
Updates tailscale/corp#21867 Signed-off-by: Percy Wegmann <percy@tailscale.com>
cd64779
to
2f341f3
Compare
Updates tailscale/corp#21867
Depends on #89