-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.go
40 lines (37 loc) · 1.02 KB
/
search.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package hwapi
import (
"encoding/json"
"fmt"
"strconv"
)
// SearchResult Full text search for entities tied to an account
//Path /api/v1/accounts/{account_hash}/search
type SearchResult struct {
Hosts []*HostName `json:"hosts"`
Hostnames []*HostName `json:"hostnames"`
Origins []*Origin `json:"origins"`
HcsTenants []*map[string]string `json:"hcsTenants"` //HCS is outof support
Accounts []*Account `json:"accounts"`
Users []*User `json:"users"`
}
// Search accounts? hosts? origins? certificates
func (api *HWApi) Search(accountHash string, search string, maxResults int) (*SearchResult, error) {
if maxResults == 0 {
maxResults = 5
}
r, e := api.Request(
&Request{
Method: GET,
URL: fmt.Sprintf("/api/v1/accounts/%s/search", accountHash),
Query: map[string]string{
"search": search,
"maxResult": strconv.Itoa(maxResults),
},
},
)
if e != nil {
return nil, e
}
al := &SearchResult{}
return al, json.Unmarshal(r.body, al)
}