@@ -9,30 +9,29 @@ import (
9
9
"encoding/json"
10
10
"fmt"
11
11
"io"
12
- "io/ioutil"
13
12
"net/http"
14
13
"os"
15
14
"strings"
16
15
"time"
17
16
)
18
17
19
- // IntelOwlError represents an error that has occurred when communicating with IntelOwl.
20
- type IntelOwlError struct {
18
+ // Error represents an error that has occurred when communicating with IntelOwl.
19
+ type Error struct {
21
20
StatusCode int
22
21
Message string
23
22
Response * http.Response
24
23
}
25
24
26
25
// Error lets you implement the error interface.
27
26
// This is used for making custom go errors.
28
- func (intelOwlError * IntelOwlError ) Error () string {
27
+ func (intelOwlError * Error ) Error () string {
29
28
errorMessage := fmt .Sprintf ("Status Code: %d \n Error: %s" , intelOwlError .StatusCode , intelOwlError .Message )
30
29
return errorMessage
31
30
}
32
31
33
- // newIntelOwlError lets you easily create new IntelOwlErrors .
34
- func newIntelOwlError (statusCode int , message string , response * http.Response ) * IntelOwlError {
35
- return & IntelOwlError {
32
+ // newError lets you easily create new Errors .
33
+ func newError (statusCode int , message string , response * http.Response ) * Error {
34
+ return & Error {
36
35
StatusCode : statusCode ,
37
36
Message : message ,
38
37
Response : response ,
@@ -44,8 +43,8 @@ type successResponse struct {
44
43
Data []byte
45
44
}
46
45
47
- // IntelOwlClientOptions represents the fields needed to configure and use the IntelOwlClient
48
- type IntelOwlClientOptions struct {
46
+ // ClientOptions represents the fields needed to configure and use the Client
47
+ type ClientOptions struct {
49
48
Url string `json:"url"`
50
49
Token string `json:"token"`
51
50
// Certificate represents your SSL cert: path to the cert file!
@@ -54,16 +53,16 @@ type IntelOwlClientOptions struct {
54
53
Timeout uint64 `json:"timeout"`
55
54
}
56
55
57
- // IntelOwlClient handles all the communication with your IntelOwl instance.
58
- type IntelOwlClient struct {
59
- options * IntelOwlClientOptions
56
+ // Client handles all the communication with your IntelOwl instance.
57
+ type Client struct {
58
+ options * ClientOptions
60
59
client * http.Client
61
60
TagService * TagService
62
61
JobService * JobService
63
62
AnalyzerService * AnalyzerService
64
63
ConnectorService * ConnectorService
65
64
UserService * UserService
66
- Logger * IntelOwlLogger
65
+ Logger * Logger
67
66
}
68
67
69
68
// TLP represents an enum for the TLP attribute used in IntelOwl's REST API.
@@ -113,7 +112,7 @@ func ParseTLP(s string) TLP {
113
112
}
114
113
115
114
// Implementing the MarshalJSON interface to make our custom Marshal for the enum
116
- func (tlp TLP ) MarshalJSON () ([]byte , error ) {
115
+ func (tlp * TLP ) MarshalJSON () ([]byte , error ) {
117
116
return json .Marshal (tlp .String ())
118
117
}
119
118
@@ -129,8 +128,8 @@ func (tlp *TLP) UnmarshalJSON(data []byte) (err error) {
129
128
return nil
130
129
}
131
130
132
- // NewIntelOwlClient lets you easily create a new IntelOwlClient by providing IntelOwlClientOptions , http.Clients, and LoggerParams.
133
- func NewIntelOwlClient (options * IntelOwlClientOptions , httpClient * http.Client , loggerParams * LoggerParams ) IntelOwlClient {
131
+ // NewClient lets you easily create a new Client by providing ClientOptions , http.Clients, and LoggerParams.
132
+ func NewClient (options * ClientOptions , httpClient * http.Client , loggerParams * LoggerParams ) Client {
134
133
135
134
var timeout time.Duration
136
135
@@ -148,7 +147,7 @@ func NewIntelOwlClient(options *IntelOwlClientOptions, httpClient *http.Client,
148
147
}
149
148
150
149
// configuring the client
151
- client := IntelOwlClient {
150
+ client := Client {
152
151
options : options ,
153
152
client : httpClient ,
154
153
}
@@ -171,33 +170,33 @@ func NewIntelOwlClient(options *IntelOwlClientOptions, httpClient *http.Client,
171
170
}
172
171
173
172
// configuring the logger!
174
- client .Logger = & IntelOwlLogger {}
173
+ client .Logger = & Logger {}
175
174
client .Logger .Init (loggerParams )
176
175
177
176
return client
178
177
}
179
178
180
- // NewIntelOwlClientThroughJsonFile lets you create a new IntelOwlClient through a JSON file that contains your IntelOwlClientOptions
181
- func NewIntelOwlClientThroughJsonFile (filePath string , httpClient * http.Client , loggerParams * LoggerParams ) (* IntelOwlClient , error ) {
179
+ // NewClientFromJsonFile lets you create a new Client through a JSON file that contains your ClientOptions
180
+ func NewClientFromJsonFile (filePath string , httpClient * http.Client , loggerParams * LoggerParams ) (* Client , error ) {
182
181
optionsBytes , err := os .ReadFile (filePath )
183
182
if err != nil {
184
183
errorMessage := fmt .Sprintf ("Could not read %s" , filePath )
185
- intelOwlError := newIntelOwlError (400 , errorMessage , nil )
184
+ intelOwlError := newError (400 , errorMessage , nil )
186
185
return nil , intelOwlError
187
186
}
188
187
189
- intelOwlClientOptions := & IntelOwlClientOptions {}
188
+ intelOwlClientOptions := & ClientOptions {}
190
189
if unmarshalError := json .Unmarshal (optionsBytes , & intelOwlClientOptions ); unmarshalError != nil {
191
190
return nil , unmarshalError
192
191
}
193
192
194
- intelOwlClient := NewIntelOwlClient (intelOwlClientOptions , httpClient , loggerParams )
193
+ intelOwlClient := NewClient (intelOwlClientOptions , httpClient , loggerParams )
195
194
196
195
return & intelOwlClient , nil
197
196
}
198
197
199
198
// buildRequest is used for building requests.
200
- func (client * IntelOwlClient ) buildRequest (ctx context.Context , method string , contentType string , body io.Reader , url string ) (* http.Request , error ) {
199
+ func (client * Client ) buildRequest (ctx context.Context , method string , contentType string , body io.Reader , url string ) (* http.Request , error ) {
201
200
request , err := http .NewRequestWithContext (ctx , method , url , body )
202
201
if err != nil {
203
202
return nil , err
@@ -211,7 +210,7 @@ func (client *IntelOwlClient) buildRequest(ctx context.Context, method string, c
211
210
}
212
211
213
212
// newRequest is used for making requests.
214
- func (client * IntelOwlClient ) newRequest (ctx context.Context , request * http.Request ) (* successResponse , error ) {
213
+ func (client * Client ) newRequest (ctx context.Context , request * http.Request ) (* successResponse , error ) {
215
214
response , err := client .client .Do (request )
216
215
217
216
// Checking for context errors such as reaching the deadline and/or Timeout
@@ -226,17 +225,17 @@ func (client *IntelOwlClient) newRequest(ctx context.Context, request *http.Requ
226
225
227
226
defer response .Body .Close ()
228
227
229
- msgBytes , err := ioutil .ReadAll (response .Body )
228
+ msgBytes , err := io .ReadAll (response .Body )
230
229
statusCode := response .StatusCode
231
230
if err != nil {
232
231
errorMessage := fmt .Sprintf ("Could not convert JSON response. Status code: %d" , statusCode )
233
- intelOwlError := newIntelOwlError (statusCode , errorMessage , response )
232
+ intelOwlError := newError (statusCode , errorMessage , response )
234
233
return nil , intelOwlError
235
234
}
236
235
237
236
if statusCode < http .StatusOK || statusCode >= http .StatusBadRequest {
238
237
errorMessage := string (msgBytes )
239
- intelOwlError := newIntelOwlError (statusCode , errorMessage , response )
238
+ intelOwlError := newError (statusCode , errorMessage , response )
240
239
return nil , intelOwlError
241
240
}
242
241
0 commit comments