-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindicators.go
180 lines (133 loc) · 4.36 KB
/
indicators.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package trustar
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/url"
)
// Reference: https://docs.trustar.co/api/v13/indicators/index.html
// SearchIndicators Searches for all indicators that contain the given search term. Also allows filtering by date, enclave, and tags.
//
// Endpoint: GET /1.3/indicators/search
func (c *Client) SearchIndicators(v url.Values) (SearchIndicatorReponse, error) {
var sir SearchIndicatorReponse
url := fmt.Sprintf("%s%s", c.APIBase, fmt.Sprintf("indicators/search?%s", v.Encode()))
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return sir, err
}
if err = c.SendWithAuth(req, &sir); err != nil {
return sir, err
}
return sir, nil
}
// FindRelatedIndicators Search all TruSTAR incident reports for provided indicators and return all correlated indicators from search results. Two indicators are considered “correlated” if they can be found in a common report.
//
// Endpoint: GET /1.3/indicators/related
func (c *Client) FindRelatedIndicators(v url.Values) (RelatedIndicatorsResponse, error) {
var rir RelatedIndicatorsResponse
url := fmt.Sprintf("%s%s", c.APIBase, fmt.Sprintf("indicators/related?%s", v.Encode()))
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return rir, err
}
if err = c.SendWithAuth(req, &rir); err != nil {
return rir, err
}
return rir, nil
}
// WhitelistIndicators Whitelist a list of indicator values for the user’s company.
//
// Endpoint: POST /1.3/whitelist
func (c *Client) WhitelistIndicators(indicators []string) error {
var wr interface{}
i, _ := json.Marshal(indicators)
url := fmt.Sprintf("%s%s", c.APIBase, "whitelist")
req, err := http.NewRequest("POST", url, bytes.NewReader(i))
if err != nil {
return err
}
return c.SendWithAuth(req, &wr)
}
// GetWhitelist Get a paginated list of the indicators that have been whitelisted by the user’s company.
//
// Endpoint: GET /1.3/whitelist
func (c *Client) GetWhitelist(v url.Values) (WhitelistIndicatorsResponse, error) {
var wir WhitelistIndicatorsResponse
url := fmt.Sprintf("%s%s", c.APIBase, fmt.Sprintf("whitelist?%s", v.Encode()))
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return wir, err
}
if err = c.SendWithAuth(req, &wir); err != nil {
return wir, err
}
return wir, nil
}
// DeleteFromWhitelist Delete an indicator from the user’s company whitelist.
//
// Endpoint: DELETE /1.3/whitelist
func (c *Client) DeleteFromWhitelist(v url.Values) error {
var wr interface{}
url := fmt.Sprintf("%s%s", c.APIBase, fmt.Sprintf("whitelist?%s", v.Encode()))
req, err := http.NewRequest("DELETE", url, nil)
if err != nil {
return err
}
if err = c.SendWithAuth(req, &wr); err != nil {
// this endpoint returns no content so ignore EOF errors
if err.Error() != "EOF" {
return err
}
}
return nil
}
// GetIndicatorMetadata Provide metadata associated with an indicator
//
// Endpoint: POST /1.3/indicators/metadata
func (c *Client) GetIndicatorMetadata(indicators []Indicator) (IndicatorMetadataResponse, error) {
var imr IndicatorMetadataResponse
i, _ := json.Marshal(indicators)
url := fmt.Sprintf("%s%s", c.APIBase, "indicators/metadata")
req, err := http.NewRequest("POST", url, bytes.NewReader(i))
if err != nil {
return nil, err
}
if err = c.SendWithAuth(req, &imr); err != nil {
return nil, err
}
return imr, nil
}
// GetTrendingIndicators Returns the 10 indicators that have recently appeared in the most community reports.
//
// Endpoint: GET /1.3/indicators/community-trending
func (c *Client) GetTrendingIndicators(v url.Values) (TrendingIndicators, error) {
var ti TrendingIndicators
url := fmt.Sprintf("%s%s", c.APIBase, fmt.Sprintf("indicators/community-trending?%s", v.Encode()))
req, err := http.NewRequest("GET", url, nil)
fmt.Println(req.URL)
if err != nil {
return nil, err
}
if err = c.SendWithAuth(req, &ti); err != nil {
// this endpoint returns no content so ignore EOF errors
if err.Error() != "EOF" {
return nil, err
}
}
return ti, nil
}
// SubmitIndicators Submit Indicators
//
// Endpoint: POST /1.3/indicators
func (c *Client) SubmitIndicators(indicators IndicatorSubmission) error {
var imr interface{}
i, _ := json.Marshal(indicators)
url := fmt.Sprintf("%s%s", c.APIBase, "indicators")
req, err := http.NewRequest("POST", url, bytes.NewReader(i))
if err != nil {
return err
}
return c.SendWithAuth(req, &imr)
}