login before checking status

the status enpoint requires auth, at least in my Cloud Key Firmware 2.X
(UniFi OS) setup.
Presumably there are benefits to checking status before logging in; in
which case I expect this PR will need to be edited.
This commit is contained in:
Patrick Collins
2021-01-29 19:34:08 -08:00
committed by Paul Tyng
parent b5c55d88f4
commit c55b43115b

View File

@@ -147,12 +147,6 @@ func (c *Client) Login(ctx context.Context, user, pass string) error {
} `json:"meta"`
}
err = c.do(ctx, "GET", c.statusPath, nil, &status)
if err != nil {
return err
}
c.version = status.Meta.ServerVersion
err = c.do(ctx, "POST", c.loginPath, &struct {
Username string `json:"username"`
Password string `json:"password"`
@@ -164,6 +158,12 @@ func (c *Client) Login(ctx context.Context, user, pass string) error {
return err
}
err = c.do(ctx, "GET", c.statusPath, nil, &status)
if err != nil {
return err
}
c.version = status.Meta.ServerVersion
return nil
}