forked from kolide/fleet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'get hosts' command to fleetctl (kolide#1977)
This commit: - adds a new sub-command for fetching hosts to `fleetctl get` command. Why? - this allows for listing of all hosts via the fleetctl interface. There may be additional attributes of the host that we'd like to display, but this should be a good start. Closes kolide#1962
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package service | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
// GetHosts retrieves the list of all Hosts | ||
func (c *Client) GetHosts() ([]hostResponse, error) { | ||
response, err := c.AuthenticatedDo("GET", "/api/v1/kolide/hosts", nil) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "GET /api/v1/kolide/hosts") | ||
} | ||
defer response.Body.Close() | ||
|
||
if response.StatusCode != http.StatusOK { | ||
return nil, errors.Errorf( | ||
"get hosts received status %d %s", | ||
response.StatusCode, | ||
extractServerErrorText(response.Body), | ||
) | ||
} | ||
var responseBody listHostsResponse | ||
err = json.NewDecoder(response.Body).Decode(&responseBody) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "decode list hosts response") | ||
} | ||
if responseBody.Err != nil { | ||
return nil, errors.Errorf("list hosts: %s", responseBody.Err) | ||
} | ||
|
||
return responseBody.Hosts, nil | ||
} |