Skip to content

Commit c946177

Browse files
Improving constants (#59)
* revamping the constants and adding them into the unit tests as well integrating them into the me endpoints * Fixing spelling mistake in README * Fixing the README * Fixing an example
1 parent 598ed60 commit c946177

15 files changed

+140
-100
lines changed

README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ go-intelowl is a client library/SDK that allows developers to easily automate an
1414
- [Usage](#usage)
1515
- [Examples](#examples)
1616
- [Contribute](#contribute)
17-
- [Liscence](#liscence)
17+
- [License](#liscence)
1818
- [Links](#links)
1919
- [FAQ](#faq)
2020
- [Generate API key](#generate-api-key)
@@ -95,8 +95,8 @@ func main(){
9595
intelowlOptions := gointelowl.IntelOwlClientOptions{
9696
Url: "your-cool-url-goes-here",
9797
Token: "your-super-secret-token-goes-here",
98-
}
9998
Certificate: "your-optional-certificate-goes-here",
99+
}
100100

101101
client := gointelowl.NewIntelOwlClient(
102102
&intelowlOptions,
@@ -120,14 +120,16 @@ func main(){
120120
For complete usage of go-intelowl, see the full [package docs](https://pkg.go.dev/github.com/intelowlproject/go-intelowl).
121121

122122
# Contribute
123-
See our [contributor page]() for details how to contribute. If you want to follow the updates, discuss, or just chat then please join our [slack](https://honeynetpublic.slack.com/archives/C01KVGMAKL6) channel we'd love to hear your feedback!
123+
If you want to follow the updates, discuss, contribute, or just chat then please join our [slack](https://honeynetpublic.slack.com/archives/C01KVGMAKL6) channel we'd love to hear your feedback!
124124

125-
# Liscence
125+
# License
126126
Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE.
127127

128128
# Links
129129
- [Intelowl](https://github.com/intelowlproject/IntelOwl)
130-
- [Documentation]()
130+
- [Documentation](https://intelowl.readthedocs.io/en/latest/)
131+
- [API documentation](https://intelowl.readthedocs.io/en/latest/Redoc.html)
132+
- [Examples](./examples/)
131133

132134
# FAQ
133135
## Generate API key

constants/constants.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package constants
2+
3+
// These represent tag endpoints URL
4+
const (
5+
BASE_TAG_URL = "/api/tags"
6+
SPECIFIC_TAG_URL = BASE_TAG_URL + "/%d"
7+
)
8+
9+
// These represent job endpoints URL
10+
const (
11+
BASE_JOB_URL = "/api/jobs"
12+
SPECIFIC_JOB_URL = BASE_JOB_URL + "/%d"
13+
DOWNLOAD_SAMPLE_JOB_URL = SPECIFIC_JOB_URL + "/download_sample"
14+
KILL_JOB_URL = SPECIFIC_JOB_URL + "/kill"
15+
KILL_ANALYZER_JOB_URL = SPECIFIC_JOB_URL + "/analyzer/%s/kill"
16+
RETRY_ANALYZER_JOB_URL = SPECIFIC_JOB_URL + "/analyzer/%s/retry"
17+
KILL_CONNECTOR_JOB_URL = SPECIFIC_JOB_URL + "/connector/%s/kill"
18+
RETRY_CONNECTOR_JOB_URL = SPECIFIC_JOB_URL + "/connector/%s/retry"
19+
)
20+
21+
// These represent analyzer endpoints URL
22+
const (
23+
ANALYZER_CONFIG_URL = "/api/get_analyzer_configs"
24+
ANALYZER_HEALTHCHECK_URL = "/api/analyzer/%s/healthcheck"
25+
)
26+
27+
// These represent connector endpoints URL
28+
const (
29+
CONNECTOR_CONFIG_URL = "/api/get_connector_configs"
30+
CONNECTOR_HEALTHCHECK_URL = "/api/connector/%s/healthcheck"
31+
)
32+
33+
// These represent analyze endpoints URL
34+
const (
35+
ANALYZE_OBSERVABLE_URL = "/api/analyze_observable"
36+
ANALYZE_MULTIPLE_OBSERVABLES_URL = "/api/analyze_multiple_observables"
37+
ANALYZE_FILE_URL = "/api/analyze_file"
38+
ANALYZE_MULTIPLE_FILES_URL = "/api/analyze_multiple_files"
39+
)
40+
41+
// These represent me endpoints URL
42+
43+
const (
44+
BASE_ME_URL = "/api/me"
45+
USER_DETAILS_URL = BASE_ME_URL + "/access"
46+
ORGANIZATION_URL = BASE_ME_URL + "/organization"
47+
INVITE_TO_ORGANIZATION_URL = ORGANIZATION_URL + "/invite"
48+
REMOVE_MEMBER_FROM_ORGANIZATION_URL = ORGANIZATION_URL + "/remove_member"
49+
)

gointelowl/analysis.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7-
"fmt"
87
"io"
98
"mime/multipart"
109
"os"
1110
"path/filepath"
11+
12+
"github.com/intelowlproject/go-intelowl/constants"
1213
)
1314

1415
// BasicAnalysisParams represents the common fields in an Observable and a File analysis
@@ -67,7 +68,7 @@ type MultipleAnalysisResponse struct {
6768
//
6869
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/analyze_observable
6970
func (client *IntelOwlClient) CreateObservableAnalysis(ctx context.Context, params *ObservableAnalysisParams) (*AnalysisResponse, error) {
70-
requestUrl := fmt.Sprintf(ANALYZE_OBSERVABLE_URL, client.options.Url)
71+
requestUrl := client.options.Url + constants.ANALYZE_OBSERVABLE_URL
7172
method := "POST"
7273
contentType := "application/json"
7374
jsonData, _ := json.Marshal(params)
@@ -96,8 +97,7 @@ func (client *IntelOwlClient) CreateObservableAnalysis(ctx context.Context, para
9697
//
9798
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/analyze_multiple_observables
9899
func (client *IntelOwlClient) CreateMultipleObservableAnalysis(ctx context.Context, params *MultipleObservableAnalysisParams) (*MultipleAnalysisResponse, error) {
99-
requestUrl := fmt.Sprintf(ANALYZE_MULTIPLE_OBSERVABLES_URL, client.options.Url)
100-
100+
requestUrl := client.options.Url + constants.ANALYZE_MULTIPLE_OBSERVABLES_URL
101101
method := "POST"
102102
contentType := "application/json"
103103
jsonData, _ := json.Marshal(params)
@@ -125,7 +125,7 @@ func (client *IntelOwlClient) CreateMultipleObservableAnalysis(ctx context.Conte
125125
//
126126
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/analyze_file
127127
func (client *IntelOwlClient) CreateFileAnalysis(ctx context.Context, fileAnalysisParams *FileAnalysisParams) (*AnalysisResponse, error) {
128-
requestUrl := fmt.Sprintf(ANALYZE_FILE_URL, client.options.Url)
128+
requestUrl := client.options.Url + constants.ANALYZE_FILE_URL
129129
// * Making the multiform data
130130
body := &bytes.Buffer{}
131131
writer := multipart.NewWriter(body)
@@ -203,7 +203,7 @@ func (client *IntelOwlClient) CreateFileAnalysis(ctx context.Context, fileAnalys
203203
//
204204
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/analyze_multiple_files
205205
func (client *IntelOwlClient) CreateMultipleFileAnalysis(ctx context.Context, fileAnalysisParams *MultipleFileAnalysisParams) (*MultipleAnalysisResponse, error) {
206-
requestUrl := fmt.Sprintf(ANALYZE_MULTIPLE_FILES_URL, client.options.Url)
206+
requestUrl := client.options.Url + constants.ANALYZE_MULTIPLE_FILES_URL
207207
// * Making the multiform data
208208
body := &bytes.Buffer{}
209209
writer := multipart.NewWriter(body)

gointelowl/analyzer.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"encoding/json"
66
"fmt"
77
"sort"
8+
9+
"github.com/intelowlproject/go-intelowl/constants"
810
)
911

1012
// AnalyzerConfig represents how an analyzer is configured in IntelOwl.
@@ -36,7 +38,7 @@ type AnalyzerService struct {
3638
//
3739
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/get_analyzer_configs
3840
func (analyzerService *AnalyzerService) GetConfigs(ctx context.Context) (*[]AnalyzerConfig, error) {
39-
requestUrl := fmt.Sprintf(ANALYZER_CONFIG_URL, analyzerService.client.options.Url)
41+
requestUrl := analyzerService.client.options.Url + constants.ANALYZER_CONFIG_URL
4042
contentType := "application/json"
4143
method := "GET"
4244
request, err := analyzerService.client.buildRequest(ctx, method, contentType, nil, requestUrl)
@@ -74,7 +76,8 @@ func (analyzerService *AnalyzerService) GetConfigs(ctx context.Context) (*[]Anal
7476
//
7577
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/analyzer/operation/analyzer_healthcheck_retrieve
7678
func (analyzerService *AnalyzerService) HealthCheck(ctx context.Context, analyzerName string) (bool, error) {
77-
requestUrl := fmt.Sprintf(ANALYZER_HEALTHCHECK_URL, analyzerService.client.options.Url, analyzerName)
79+
route := analyzerService.client.options.Url + constants.ANALYZER_HEALTHCHECK_URL
80+
requestUrl := fmt.Sprintf(route, analyzerName)
7881
contentType := "application/json"
7982
method := "GET"
8083
request, err := analyzerService.client.buildRequest(ctx, method, contentType, nil, requestUrl)

gointelowl/connector.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"encoding/json"
66
"fmt"
77
"sort"
8+
9+
"github.com/intelowlproject/go-intelowl/constants"
810
)
911

1012
// ConnectorConfig represents how a connector is configured in IntelOwl.
@@ -28,7 +30,7 @@ type ConnectorService struct {
2830
//
2931
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/get_connector_configs
3032
func (connectorService *ConnectorService) GetConfigs(ctx context.Context) (*[]ConnectorConfig, error) {
31-
requestUrl := fmt.Sprintf(CONNECTOR_CONFIG_URL, connectorService.client.options.Url)
33+
requestUrl := connectorService.client.options.Url + constants.CONNECTOR_CONFIG_URL
3234
contentType := "application/json"
3335
method := "GET"
3436
request, err := connectorService.client.buildRequest(ctx, method, contentType, nil, requestUrl)
@@ -66,7 +68,8 @@ func (connectorService *ConnectorService) GetConfigs(ctx context.Context) (*[]Co
6668
//
6769
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/connector/operation/connector_healthcheck_retrieve
6870
func (connectorService *ConnectorService) HealthCheck(ctx context.Context, connectorName string) (bool, error) {
69-
requestUrl := fmt.Sprintf(CONNECTOR_HEALTHCHECK_URL, connectorService.client.options.Url, connectorName)
71+
route := connectorService.client.options.Url + constants.CONNECTOR_HEALTHCHECK_URL
72+
requestUrl := fmt.Sprintf(route, connectorName)
7073
contentType := "application/json"
7174
method := "GET"
7275
request, err := connectorService.client.buildRequest(ctx, method, contentType, nil, requestUrl)

gointelowl/constants.go

-39
This file was deleted.

gointelowl/job.go

+19-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"fmt"
77
"net/http"
88
"time"
9+
10+
"github.com/intelowlproject/go-intelowl/constants"
911
)
1012

1113
// UserDetails represents user details in an IntelOwl job.
@@ -81,7 +83,7 @@ type JobService struct {
8183
//
8284
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_list
8385
func (jobService *JobService) List(ctx context.Context) (*JobListResponse, error) {
84-
requestUrl := fmt.Sprintf(BASE_JOB_URL, jobService.client.options.Url)
86+
requestUrl := jobService.client.options.Url + constants.BASE_JOB_URL
8587
contentType := "application/json"
8688
method := "GET"
8789
request, err := jobService.client.buildRequest(ctx, method, contentType, nil, requestUrl)
@@ -107,7 +109,8 @@ func (jobService *JobService) List(ctx context.Context) (*JobListResponse, error
107109
//
108110
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_retrieve
109111
func (jobService *JobService) Get(ctx context.Context, jobId uint64) (*Job, error) {
110-
requestUrl := fmt.Sprintf(SPECIFIC_JOB_URL, jobService.client.options.Url, jobId)
112+
route := jobService.client.options.Url + constants.SPECIFIC_JOB_URL
113+
requestUrl := fmt.Sprintf(route, jobId)
111114
contentType := "application/json"
112115
method := "GET"
113116
request, err := jobService.client.buildRequest(ctx, method, contentType, nil, requestUrl)
@@ -132,7 +135,8 @@ func (jobService *JobService) Get(ctx context.Context, jobId uint64) (*Job, erro
132135
//
133136
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_download_sample_retrieve
134137
func (jobService *JobService) DownloadSample(ctx context.Context, jobId uint64) ([]byte, error) {
135-
requestUrl := fmt.Sprintf(DOWNLOAD_SAMPLE_JOB_URL, jobService.client.options.Url, jobId)
138+
route := jobService.client.options.Url + constants.DOWNLOAD_SAMPLE_JOB_URL
139+
requestUrl := fmt.Sprintf(route, jobId)
136140
contentType := "application/json"
137141
method := "GET"
138142
request, err := jobService.client.buildRequest(ctx, method, contentType, nil, requestUrl)
@@ -152,7 +156,8 @@ func (jobService *JobService) DownloadSample(ctx context.Context, jobId uint64)
152156
//
153157
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_destroy
154158
func (jobService *JobService) Delete(ctx context.Context, jobId uint64) (bool, error) {
155-
requestUrl := fmt.Sprintf(SPECIFIC_JOB_URL, jobService.client.options.Url, jobId)
159+
route := jobService.client.options.Url + constants.SPECIFIC_JOB_URL
160+
requestUrl := fmt.Sprintf(route, jobId)
156161
contentType := "application/json"
157162
method := "DELETE"
158163
request, err := jobService.client.buildRequest(ctx, method, contentType, nil, requestUrl)
@@ -175,7 +180,8 @@ func (jobService *JobService) Delete(ctx context.Context, jobId uint64) (bool, e
175180
//
176181
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_kill_partial_update
177182
func (jobService *JobService) Kill(ctx context.Context, jobId uint64) (bool, error) {
178-
requestUrl := fmt.Sprintf(KILL_JOB_URL, jobService.client.options.Url, jobId)
183+
route := jobService.client.options.Url + constants.KILL_JOB_URL
184+
requestUrl := fmt.Sprintf(route, jobId)
179185
contentType := "application/json"
180186
method := "PATCH"
181187
request, err := jobService.client.buildRequest(ctx, method, contentType, nil, requestUrl)
@@ -198,7 +204,8 @@ func (jobService *JobService) Kill(ctx context.Context, jobId uint64) (bool, err
198204
//
199205
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_analyzer_kill_partial_update
200206
func (jobService *JobService) KillAnalyzer(ctx context.Context, jobId uint64, analyzerName string) (bool, error) {
201-
requestUrl := fmt.Sprintf(KILL_ANALYZER_JOB_URL, jobService.client.options.Url, jobId, analyzerName)
207+
route := jobService.client.options.Url + constants.KILL_ANALYZER_JOB_URL
208+
requestUrl := fmt.Sprintf(route, jobId, analyzerName)
202209
contentType := "application/json"
203210
method := "PATCH"
204211
request, err := jobService.client.buildRequest(ctx, method, contentType, nil, requestUrl)
@@ -221,7 +228,8 @@ func (jobService *JobService) KillAnalyzer(ctx context.Context, jobId uint64, an
221228
//
222229
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_analyzer_retry_partial_update
223230
func (jobService *JobService) RetryAnalyzer(ctx context.Context, jobId uint64, analyzerName string) (bool, error) {
224-
requestUrl := fmt.Sprintf(RETRY_ANALYZER_JOB_URL, jobService.client.options.Url, jobId, analyzerName)
231+
route := jobService.client.options.Url + constants.RETRY_ANALYZER_JOB_URL
232+
requestUrl := fmt.Sprintf(route, jobId, analyzerName)
225233
contentType := "application/json"
226234
method := "PATCH"
227235
request, err := jobService.client.buildRequest(ctx, method, contentType, nil, requestUrl)
@@ -244,7 +252,8 @@ func (jobService *JobService) RetryAnalyzer(ctx context.Context, jobId uint64, a
244252
//
245253
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_connector_kill_partial_update
246254
func (jobService *JobService) KillConnector(ctx context.Context, jobId uint64, connectorName string) (bool, error) {
247-
requestUrl := fmt.Sprintf(KILL_CONNECTOR_JOB_URL, jobService.client.options.Url, jobId, connectorName)
255+
route := jobService.client.options.Url + constants.KILL_CONNECTOR_JOB_URL
256+
requestUrl := fmt.Sprintf(route, jobId, connectorName)
248257
contentType := "application/json"
249258
method := "PATCH"
250259
request, err := jobService.client.buildRequest(ctx, method, contentType, nil, requestUrl)
@@ -267,7 +276,8 @@ func (jobService *JobService) KillConnector(ctx context.Context, jobId uint64, c
267276
//
268277
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_connector_retry_partial_update
269278
func (jobService *JobService) RetryConnector(ctx context.Context, jobId uint64, connectorName string) (bool, error) {
270-
requestUrl := fmt.Sprintf(RETRY_CONNECTOR_JOB_URL, jobService.client.options.Url, jobId, connectorName)
279+
route := jobService.client.options.Url + constants.RETRY_CONNECTOR_JOB_URL
280+
requestUrl := fmt.Sprintf(route, jobId, connectorName)
271281
contentType := "application/json"
272282
method := "PATCH"
273283
request, err := jobService.client.buildRequest(ctx, method, contentType, nil, requestUrl)

gointelowl/me.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import (
44
"bytes"
55
"context"
66
"encoding/json"
7-
"fmt"
87
"net/http"
98
"time"
9+
10+
"github.com/intelowlproject/go-intelowl/constants"
1011
)
1112

1213
type Details struct {
@@ -75,7 +76,7 @@ type InvitationParams struct {
7576
//
7677
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/me/operation/me_access_retrieve
7778
func (userService *UserService) Access(ctx context.Context) (*User, error) {
78-
requestUrl := fmt.Sprintf("%s/api/me/access", userService.client.options.Url)
79+
requestUrl := userService.client.options.Url + constants.USER_DETAILS_URL
7980
contentType := "application/json"
8081
method := "GET"
8182
request, err := userService.client.buildRequest(ctx, method, contentType, nil, requestUrl)
@@ -99,7 +100,7 @@ func (userService *UserService) Access(ctx context.Context) (*User, error) {
99100
//
100101
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/me/operation/me_organization_list
101102
func (userService *UserService) Organization(ctx context.Context) (*Organization, error) {
102-
requestUrl := fmt.Sprintf("%s/api/me/organization", userService.client.options.Url)
103+
requestUrl := userService.client.options.Url + constants.ORGANIZATION_URL
103104
contentType := "application/json"
104105
method := "GET"
105106
request, err := userService.client.buildRequest(ctx, method, contentType, nil, requestUrl)
@@ -124,7 +125,7 @@ func (userService *UserService) Organization(ctx context.Context) (*Organization
124125
//
125126
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/me/operation/me_organization_create
126127
func (userService *UserService) CreateOrganization(ctx context.Context, organizationParams *OrganizationParams) (*Organization, error) {
127-
requestUrl := fmt.Sprintf("%s/api/me/organization", userService.client.options.Url)
128+
requestUrl := userService.client.options.Url + constants.ORGANIZATION_URL
128129
// Getting the relevant JSON data
129130
orgJson, err := json.Marshal(organizationParams)
130131
if err != nil {
@@ -156,7 +157,7 @@ func (userService *UserService) CreateOrganization(ctx context.Context, organiza
156157
//
157158
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/me/operation/me_organization_invite_create
158159
func (userService *UserService) InviteToOrganization(ctx context.Context, memberParams *MemberParams) (*Invite, error) {
159-
requestUrl := fmt.Sprintf("%s/api/me/organization/invite", userService.client.options.Url)
160+
requestUrl := userService.client.options.Url + constants.INVITE_TO_ORGANIZATION_URL
160161
// Getting the relevant JSON data
161162
memberJson, err := json.Marshal(memberParams)
162163
if err != nil {
@@ -188,7 +189,7 @@ func (userService *UserService) InviteToOrganization(ctx context.Context, member
188189
//
189190
// IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/me/operation/me_organization_create
190191
func (userService *UserService) RemoveMemberFromOrganization(ctx context.Context, memberParams *MemberParams) (bool, error) {
191-
requestUrl := fmt.Sprintf("%s/api/me/organization/remove_member", userService.client.options.Url)
192+
requestUrl := userService.client.options.Url + constants.REMOVE_MEMBER_FROM_ORGANIZATION_URL
192193
// Getting the relevant JSON data
193194
memberJson, err := json.Marshal(memberParams)
194195
if err != nil {

0 commit comments

Comments
 (0)