From c946177b98777878fef72622ab7f68bb1801ad48 Mon Sep 17 00:00:00 2001 From: Reaper Date: Mon, 5 Sep 2022 23:17:40 +0500 Subject: [PATCH] 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 --- README.md | 12 +++++---- constants/constants.go | 49 ++++++++++++++++++++++++++++++++++ gointelowl/analysis.go | 12 ++++----- gointelowl/analyzer.go | 7 +++-- gointelowl/connector.go | 7 +++-- gointelowl/constants.go | 39 --------------------------- gointelowl/job.go | 28 ++++++++++++------- gointelowl/me.go | 13 ++++----- gointelowl/tag.go | 15 +++++++---- tests/analysisService_test.go | 9 ++++--- tests/analyzerService_test.go | 5 ++-- tests/connectorService_test.go | 5 ++-- tests/jobService_test.go | 19 ++++++------- tests/tagService_test.go | 11 ++++---- tests/userService_test.go | 9 ++++--- 15 files changed, 140 insertions(+), 100 deletions(-) create mode 100644 constants/constants.go delete mode 100644 gointelowl/constants.go diff --git a/README.md b/README.md index fb4ae59..02ccae7 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ go-intelowl is a client library/SDK that allows developers to easily automate an - [Usage](#usage) - [Examples](#examples) - [Contribute](#contribute) -- [Liscence](#liscence) +- [License](#liscence) - [Links](#links) - [FAQ](#faq) - [Generate API key](#generate-api-key) @@ -95,8 +95,8 @@ func main(){ intelowlOptions := gointelowl.IntelOwlClientOptions{ Url: "your-cool-url-goes-here", Token: "your-super-secret-token-goes-here", - } Certificate: "your-optional-certificate-goes-here", + } client := gointelowl.NewIntelOwlClient( &intelowlOptions, @@ -120,14 +120,16 @@ func main(){ For complete usage of go-intelowl, see the full [package docs](https://pkg.go.dev/github.com/intelowlproject/go-intelowl). # Contribute -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! +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! -# Liscence +# License Licensed under the GNU AFFERO GENERAL PUBLIC LICENSE. # Links - [Intelowl](https://github.com/intelowlproject/IntelOwl) -- [Documentation]() +- [Documentation](https://intelowl.readthedocs.io/en/latest/) +- [API documentation](https://intelowl.readthedocs.io/en/latest/Redoc.html) +- [Examples](./examples/) # FAQ ## Generate API key diff --git a/constants/constants.go b/constants/constants.go new file mode 100644 index 0000000..74d0a50 --- /dev/null +++ b/constants/constants.go @@ -0,0 +1,49 @@ +package constants + +// These represent tag endpoints URL +const ( + BASE_TAG_URL = "/api/tags" + SPECIFIC_TAG_URL = BASE_TAG_URL + "/%d" +) + +// These represent job endpoints URL +const ( + BASE_JOB_URL = "/api/jobs" + SPECIFIC_JOB_URL = BASE_JOB_URL + "/%d" + DOWNLOAD_SAMPLE_JOB_URL = SPECIFIC_JOB_URL + "/download_sample" + KILL_JOB_URL = SPECIFIC_JOB_URL + "/kill" + KILL_ANALYZER_JOB_URL = SPECIFIC_JOB_URL + "/analyzer/%s/kill" + RETRY_ANALYZER_JOB_URL = SPECIFIC_JOB_URL + "/analyzer/%s/retry" + KILL_CONNECTOR_JOB_URL = SPECIFIC_JOB_URL + "/connector/%s/kill" + RETRY_CONNECTOR_JOB_URL = SPECIFIC_JOB_URL + "/connector/%s/retry" +) + +// These represent analyzer endpoints URL +const ( + ANALYZER_CONFIG_URL = "/api/get_analyzer_configs" + ANALYZER_HEALTHCHECK_URL = "/api/analyzer/%s/healthcheck" +) + +// These represent connector endpoints URL +const ( + CONNECTOR_CONFIG_URL = "/api/get_connector_configs" + CONNECTOR_HEALTHCHECK_URL = "/api/connector/%s/healthcheck" +) + +// These represent analyze endpoints URL +const ( + ANALYZE_OBSERVABLE_URL = "/api/analyze_observable" + ANALYZE_MULTIPLE_OBSERVABLES_URL = "/api/analyze_multiple_observables" + ANALYZE_FILE_URL = "/api/analyze_file" + ANALYZE_MULTIPLE_FILES_URL = "/api/analyze_multiple_files" +) + +// These represent me endpoints URL + +const ( + BASE_ME_URL = "/api/me" + USER_DETAILS_URL = BASE_ME_URL + "/access" + ORGANIZATION_URL = BASE_ME_URL + "/organization" + INVITE_TO_ORGANIZATION_URL = ORGANIZATION_URL + "/invite" + REMOVE_MEMBER_FROM_ORGANIZATION_URL = ORGANIZATION_URL + "/remove_member" +) diff --git a/gointelowl/analysis.go b/gointelowl/analysis.go index 6bd0b71..af266bd 100644 --- a/gointelowl/analysis.go +++ b/gointelowl/analysis.go @@ -4,11 +4,12 @@ import ( "bytes" "context" "encoding/json" - "fmt" "io" "mime/multipart" "os" "path/filepath" + + "github.com/intelowlproject/go-intelowl/constants" ) // BasicAnalysisParams represents the common fields in an Observable and a File analysis @@ -67,7 +68,7 @@ type MultipleAnalysisResponse struct { // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/analyze_observable func (client *IntelOwlClient) CreateObservableAnalysis(ctx context.Context, params *ObservableAnalysisParams) (*AnalysisResponse, error) { - requestUrl := fmt.Sprintf(ANALYZE_OBSERVABLE_URL, client.options.Url) + requestUrl := client.options.Url + constants.ANALYZE_OBSERVABLE_URL method := "POST" contentType := "application/json" jsonData, _ := json.Marshal(params) @@ -96,8 +97,7 @@ func (client *IntelOwlClient) CreateObservableAnalysis(ctx context.Context, para // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/analyze_multiple_observables func (client *IntelOwlClient) CreateMultipleObservableAnalysis(ctx context.Context, params *MultipleObservableAnalysisParams) (*MultipleAnalysisResponse, error) { - requestUrl := fmt.Sprintf(ANALYZE_MULTIPLE_OBSERVABLES_URL, client.options.Url) - + requestUrl := client.options.Url + constants.ANALYZE_MULTIPLE_OBSERVABLES_URL method := "POST" contentType := "application/json" jsonData, _ := json.Marshal(params) @@ -125,7 +125,7 @@ func (client *IntelOwlClient) CreateMultipleObservableAnalysis(ctx context.Conte // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/analyze_file func (client *IntelOwlClient) CreateFileAnalysis(ctx context.Context, fileAnalysisParams *FileAnalysisParams) (*AnalysisResponse, error) { - requestUrl := fmt.Sprintf(ANALYZE_FILE_URL, client.options.Url) + requestUrl := client.options.Url + constants.ANALYZE_FILE_URL // * Making the multiform data body := &bytes.Buffer{} writer := multipart.NewWriter(body) @@ -203,7 +203,7 @@ func (client *IntelOwlClient) CreateFileAnalysis(ctx context.Context, fileAnalys // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/analyze_multiple_files func (client *IntelOwlClient) CreateMultipleFileAnalysis(ctx context.Context, fileAnalysisParams *MultipleFileAnalysisParams) (*MultipleAnalysisResponse, error) { - requestUrl := fmt.Sprintf(ANALYZE_MULTIPLE_FILES_URL, client.options.Url) + requestUrl := client.options.Url + constants.ANALYZE_MULTIPLE_FILES_URL // * Making the multiform data body := &bytes.Buffer{} writer := multipart.NewWriter(body) diff --git a/gointelowl/analyzer.go b/gointelowl/analyzer.go index f005976..041fd25 100644 --- a/gointelowl/analyzer.go +++ b/gointelowl/analyzer.go @@ -5,6 +5,8 @@ import ( "encoding/json" "fmt" "sort" + + "github.com/intelowlproject/go-intelowl/constants" ) // AnalyzerConfig represents how an analyzer is configured in IntelOwl. @@ -36,7 +38,7 @@ type AnalyzerService struct { // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/get_analyzer_configs func (analyzerService *AnalyzerService) GetConfigs(ctx context.Context) (*[]AnalyzerConfig, error) { - requestUrl := fmt.Sprintf(ANALYZER_CONFIG_URL, analyzerService.client.options.Url) + requestUrl := analyzerService.client.options.Url + constants.ANALYZER_CONFIG_URL contentType := "application/json" method := "GET" request, err := analyzerService.client.buildRequest(ctx, method, contentType, nil, requestUrl) @@ -74,7 +76,8 @@ func (analyzerService *AnalyzerService) GetConfigs(ctx context.Context) (*[]Anal // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/analyzer/operation/analyzer_healthcheck_retrieve func (analyzerService *AnalyzerService) HealthCheck(ctx context.Context, analyzerName string) (bool, error) { - requestUrl := fmt.Sprintf(ANALYZER_HEALTHCHECK_URL, analyzerService.client.options.Url, analyzerName) + route := analyzerService.client.options.Url + constants.ANALYZER_HEALTHCHECK_URL + requestUrl := fmt.Sprintf(route, analyzerName) contentType := "application/json" method := "GET" request, err := analyzerService.client.buildRequest(ctx, method, contentType, nil, requestUrl) diff --git a/gointelowl/connector.go b/gointelowl/connector.go index 55dfe1b..49ba3fd 100644 --- a/gointelowl/connector.go +++ b/gointelowl/connector.go @@ -5,6 +5,8 @@ import ( "encoding/json" "fmt" "sort" + + "github.com/intelowlproject/go-intelowl/constants" ) // ConnectorConfig represents how a connector is configured in IntelOwl. @@ -28,7 +30,7 @@ type ConnectorService struct { // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/get_connector_configs func (connectorService *ConnectorService) GetConfigs(ctx context.Context) (*[]ConnectorConfig, error) { - requestUrl := fmt.Sprintf(CONNECTOR_CONFIG_URL, connectorService.client.options.Url) + requestUrl := connectorService.client.options.Url + constants.CONNECTOR_CONFIG_URL contentType := "application/json" method := "GET" request, err := connectorService.client.buildRequest(ctx, method, contentType, nil, requestUrl) @@ -66,7 +68,8 @@ func (connectorService *ConnectorService) GetConfigs(ctx context.Context) (*[]Co // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/connector/operation/connector_healthcheck_retrieve func (connectorService *ConnectorService) HealthCheck(ctx context.Context, connectorName string) (bool, error) { - requestUrl := fmt.Sprintf(CONNECTOR_HEALTHCHECK_URL, connectorService.client.options.Url, connectorName) + route := connectorService.client.options.Url + constants.CONNECTOR_HEALTHCHECK_URL + requestUrl := fmt.Sprintf(route, connectorName) contentType := "application/json" method := "GET" request, err := connectorService.client.buildRequest(ctx, method, contentType, nil, requestUrl) diff --git a/gointelowl/constants.go b/gointelowl/constants.go deleted file mode 100644 index 7adc142..0000000 --- a/gointelowl/constants.go +++ /dev/null @@ -1,39 +0,0 @@ -package gointelowl - -// These represent tag endpoints URL -const ( - BASE_TAG_URL = "%s/api/tags" - SPECIFIC_TAG_URL = BASE_TAG_URL + "/%d" -) - -// These represent job endpoints URL -const ( - BASE_JOB_URL = "%s/api/jobs" - SPECIFIC_JOB_URL = BASE_JOB_URL + "/%d" - DOWNLOAD_SAMPLE_JOB_URL = SPECIFIC_JOB_URL + "/download_sample" - KILL_JOB_URL = SPECIFIC_JOB_URL + "/kill" - KILL_ANALYZER_JOB_URL = SPECIFIC_JOB_URL + "/analyzer/%s/kill" - RETRY_ANALYZER_JOB_URL = SPECIFIC_JOB_URL + "/analyzer/%s/retry" - KILL_CONNECTOR_JOB_URL = SPECIFIC_JOB_URL + "/connector/%s/kill" - RETRY_CONNECTOR_JOB_URL = SPECIFIC_JOB_URL + "/connector/%s/retry" -) - -// These represent analyzer endpoints URL -const ( - ANALYZER_CONFIG_URL = "%s/api/get_analyzer_configs" - ANALYZER_HEALTHCHECK_URL = "%s/api/analyzer/%s/healthcheck" -) - -// These represent connector endpoints URL -const ( - CONNECTOR_CONFIG_URL = "%s/api/get_connector_configs" - CONNECTOR_HEALTHCHECK_URL = "%s/api/connector/%s/healthcheck" -) - -// These represent analyze endpoints URL -const ( - ANALYZE_OBSERVABLE_URL = "%s/api/analyze_observable" - ANALYZE_MULTIPLE_OBSERVABLES_URL = "%s/api/analyze_multiple_observables" - ANALYZE_FILE_URL = "%s/api/analyze_file" - ANALYZE_MULTIPLE_FILES_URL = "%s/api/analyze_multiple_files" -) diff --git a/gointelowl/job.go b/gointelowl/job.go index 42bde3b..8f5c7df 100644 --- a/gointelowl/job.go +++ b/gointelowl/job.go @@ -6,6 +6,8 @@ import ( "fmt" "net/http" "time" + + "github.com/intelowlproject/go-intelowl/constants" ) // UserDetails represents user details in an IntelOwl job. @@ -81,7 +83,7 @@ type JobService struct { // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_list func (jobService *JobService) List(ctx context.Context) (*JobListResponse, error) { - requestUrl := fmt.Sprintf(BASE_JOB_URL, jobService.client.options.Url) + requestUrl := jobService.client.options.Url + constants.BASE_JOB_URL contentType := "application/json" method := "GET" request, err := jobService.client.buildRequest(ctx, method, contentType, nil, requestUrl) @@ -107,7 +109,8 @@ func (jobService *JobService) List(ctx context.Context) (*JobListResponse, error // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_retrieve func (jobService *JobService) Get(ctx context.Context, jobId uint64) (*Job, error) { - requestUrl := fmt.Sprintf(SPECIFIC_JOB_URL, jobService.client.options.Url, jobId) + route := jobService.client.options.Url + constants.SPECIFIC_JOB_URL + requestUrl := fmt.Sprintf(route, jobId) contentType := "application/json" method := "GET" 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 // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_download_sample_retrieve func (jobService *JobService) DownloadSample(ctx context.Context, jobId uint64) ([]byte, error) { - requestUrl := fmt.Sprintf(DOWNLOAD_SAMPLE_JOB_URL, jobService.client.options.Url, jobId) + route := jobService.client.options.Url + constants.DOWNLOAD_SAMPLE_JOB_URL + requestUrl := fmt.Sprintf(route, jobId) contentType := "application/json" method := "GET" request, err := jobService.client.buildRequest(ctx, method, contentType, nil, requestUrl) @@ -152,7 +156,8 @@ func (jobService *JobService) DownloadSample(ctx context.Context, jobId uint64) // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_destroy func (jobService *JobService) Delete(ctx context.Context, jobId uint64) (bool, error) { - requestUrl := fmt.Sprintf(SPECIFIC_JOB_URL, jobService.client.options.Url, jobId) + route := jobService.client.options.Url + constants.SPECIFIC_JOB_URL + requestUrl := fmt.Sprintf(route, jobId) contentType := "application/json" method := "DELETE" 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 // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_kill_partial_update func (jobService *JobService) Kill(ctx context.Context, jobId uint64) (bool, error) { - requestUrl := fmt.Sprintf(KILL_JOB_URL, jobService.client.options.Url, jobId) + route := jobService.client.options.Url + constants.KILL_JOB_URL + requestUrl := fmt.Sprintf(route, jobId) contentType := "application/json" method := "PATCH" 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 // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_analyzer_kill_partial_update func (jobService *JobService) KillAnalyzer(ctx context.Context, jobId uint64, analyzerName string) (bool, error) { - requestUrl := fmt.Sprintf(KILL_ANALYZER_JOB_URL, jobService.client.options.Url, jobId, analyzerName) + route := jobService.client.options.Url + constants.KILL_ANALYZER_JOB_URL + requestUrl := fmt.Sprintf(route, jobId, analyzerName) contentType := "application/json" method := "PATCH" request, err := jobService.client.buildRequest(ctx, method, contentType, nil, requestUrl) @@ -221,7 +228,8 @@ func (jobService *JobService) KillAnalyzer(ctx context.Context, jobId uint64, an // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_analyzer_retry_partial_update func (jobService *JobService) RetryAnalyzer(ctx context.Context, jobId uint64, analyzerName string) (bool, error) { - requestUrl := fmt.Sprintf(RETRY_ANALYZER_JOB_URL, jobService.client.options.Url, jobId, analyzerName) + route := jobService.client.options.Url + constants.RETRY_ANALYZER_JOB_URL + requestUrl := fmt.Sprintf(route, jobId, analyzerName) contentType := "application/json" method := "PATCH" request, err := jobService.client.buildRequest(ctx, method, contentType, nil, requestUrl) @@ -244,7 +252,8 @@ func (jobService *JobService) RetryAnalyzer(ctx context.Context, jobId uint64, a // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_connector_kill_partial_update func (jobService *JobService) KillConnector(ctx context.Context, jobId uint64, connectorName string) (bool, error) { - requestUrl := fmt.Sprintf(KILL_CONNECTOR_JOB_URL, jobService.client.options.Url, jobId, connectorName) + route := jobService.client.options.Url + constants.KILL_CONNECTOR_JOB_URL + requestUrl := fmt.Sprintf(route, jobId, connectorName) contentType := "application/json" method := "PATCH" request, err := jobService.client.buildRequest(ctx, method, contentType, nil, requestUrl) @@ -267,7 +276,8 @@ func (jobService *JobService) KillConnector(ctx context.Context, jobId uint64, c // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/jobs/operation/jobs_connector_retry_partial_update func (jobService *JobService) RetryConnector(ctx context.Context, jobId uint64, connectorName string) (bool, error) { - requestUrl := fmt.Sprintf(RETRY_CONNECTOR_JOB_URL, jobService.client.options.Url, jobId, connectorName) + route := jobService.client.options.Url + constants.RETRY_CONNECTOR_JOB_URL + requestUrl := fmt.Sprintf(route, jobId, connectorName) contentType := "application/json" method := "PATCH" request, err := jobService.client.buildRequest(ctx, method, contentType, nil, requestUrl) diff --git a/gointelowl/me.go b/gointelowl/me.go index a958f6d..7c78768 100644 --- a/gointelowl/me.go +++ b/gointelowl/me.go @@ -4,9 +4,10 @@ import ( "bytes" "context" "encoding/json" - "fmt" "net/http" "time" + + "github.com/intelowlproject/go-intelowl/constants" ) type Details struct { @@ -75,7 +76,7 @@ type InvitationParams struct { // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/me/operation/me_access_retrieve func (userService *UserService) Access(ctx context.Context) (*User, error) { - requestUrl := fmt.Sprintf("%s/api/me/access", userService.client.options.Url) + requestUrl := userService.client.options.Url + constants.USER_DETAILS_URL contentType := "application/json" method := "GET" request, err := userService.client.buildRequest(ctx, method, contentType, nil, requestUrl) @@ -99,7 +100,7 @@ func (userService *UserService) Access(ctx context.Context) (*User, error) { // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/me/operation/me_organization_list func (userService *UserService) Organization(ctx context.Context) (*Organization, error) { - requestUrl := fmt.Sprintf("%s/api/me/organization", userService.client.options.Url) + requestUrl := userService.client.options.Url + constants.ORGANIZATION_URL contentType := "application/json" method := "GET" request, err := userService.client.buildRequest(ctx, method, contentType, nil, requestUrl) @@ -124,7 +125,7 @@ func (userService *UserService) Organization(ctx context.Context) (*Organization // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/me/operation/me_organization_create func (userService *UserService) CreateOrganization(ctx context.Context, organizationParams *OrganizationParams) (*Organization, error) { - requestUrl := fmt.Sprintf("%s/api/me/organization", userService.client.options.Url) + requestUrl := userService.client.options.Url + constants.ORGANIZATION_URL // Getting the relevant JSON data orgJson, err := json.Marshal(organizationParams) if err != nil { @@ -156,7 +157,7 @@ func (userService *UserService) CreateOrganization(ctx context.Context, organiza // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/me/operation/me_organization_invite_create func (userService *UserService) InviteToOrganization(ctx context.Context, memberParams *MemberParams) (*Invite, error) { - requestUrl := fmt.Sprintf("%s/api/me/organization/invite", userService.client.options.Url) + requestUrl := userService.client.options.Url + constants.INVITE_TO_ORGANIZATION_URL // Getting the relevant JSON data memberJson, err := json.Marshal(memberParams) if err != nil { @@ -188,7 +189,7 @@ func (userService *UserService) InviteToOrganization(ctx context.Context, member // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/me/operation/me_organization_create func (userService *UserService) RemoveMemberFromOrganization(ctx context.Context, memberParams *MemberParams) (bool, error) { - requestUrl := fmt.Sprintf("%s/api/me/organization/remove_member", userService.client.options.Url) + requestUrl := userService.client.options.Url + constants.REMOVE_MEMBER_FROM_ORGANIZATION_URL // Getting the relevant JSON data memberJson, err := json.Marshal(memberParams) if err != nil { diff --git a/gointelowl/tag.go b/gointelowl/tag.go index 46a5655..2594c26 100644 --- a/gointelowl/tag.go +++ b/gointelowl/tag.go @@ -7,6 +7,8 @@ import ( "errors" "fmt" "net/http" + + "github.com/intelowlproject/go-intelowl/constants" ) // TagParams represents the fields needed for creating and updating tags @@ -43,7 +45,7 @@ func checkTagID(id uint64) error { // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/tags/operation/tags_list func (tagService *TagService) List(ctx context.Context) (*[]Tag, error) { - requestUrl := fmt.Sprintf(BASE_TAG_URL, tagService.client.options.Url) + requestUrl := tagService.client.options.Url + constants.BASE_TAG_URL contentType := "application/json" method := "GET" request, err := tagService.client.buildRequest(ctx, method, contentType, nil, requestUrl) @@ -72,7 +74,8 @@ func (tagService *TagService) Get(ctx context.Context, tagId uint64) (*Tag, erro if err := checkTagID(tagId); err != nil { return nil, err } - requestUrl := fmt.Sprintf(SPECIFIC_TAG_URL, tagService.client.options.Url, tagId) + route := tagService.client.options.Url + constants.SPECIFIC_TAG_URL + requestUrl := fmt.Sprintf(route, tagId) contentType := "application/json" method := "GET" request, err := tagService.client.buildRequest(ctx, method, contentType, nil, requestUrl) @@ -97,7 +100,7 @@ func (tagService *TagService) Get(ctx context.Context, tagId uint64) (*Tag, erro // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/tags/operation/tags_create func (tagService *TagService) Create(ctx context.Context, tagParams *TagParams) (*Tag, error) { - requestUrl := fmt.Sprintf(BASE_TAG_URL, tagService.client.options.Url) + requestUrl := tagService.client.options.Url + constants.BASE_TAG_URL tagJson, err := json.Marshal(tagParams) if err != nil { return nil, err @@ -127,7 +130,8 @@ func (tagService *TagService) Create(ctx context.Context, tagParams *TagParams) // // IntelOwl REST API docs: https://intelowl.readthedocs.io/en/latest/Redoc.html#tag/tags/operation/tags_update func (tagService *TagService) Update(ctx context.Context, tagId uint64, tagParams *TagParams) (*Tag, error) { - requestUrl := fmt.Sprintf(SPECIFIC_TAG_URL, tagService.client.options.Url, tagId) + route := tagService.client.options.Url + constants.SPECIFIC_TAG_URL + requestUrl := fmt.Sprintf(route, tagId) // Getting the relevant JSON data tagJson, err := json.Marshal(tagParams) if err != nil { @@ -162,7 +166,8 @@ func (tagService *TagService) Delete(ctx context.Context, tagId uint64) (bool, e if err := checkTagID(tagId); err != nil { return false, err } - requestUrl := fmt.Sprintf(SPECIFIC_TAG_URL, tagService.client.options.Url, tagId) + route := tagService.client.options.Url + constants.SPECIFIC_TAG_URL + requestUrl := fmt.Sprintf(route, tagId) contentType := "application/json" method := "DELETE" request, err := tagService.client.buildRequest(ctx, method, contentType, nil, requestUrl) diff --git a/tests/analysisService_test.go b/tests/analysisService_test.go index 8919ff2..d7db5f1 100644 --- a/tests/analysisService_test.go +++ b/tests/analysisService_test.go @@ -8,6 +8,7 @@ import ( "path" "testing" + "github.com/intelowlproject/go-intelowl/constants" "github.com/intelowlproject/go-intelowl/gointelowl" ) @@ -41,7 +42,7 @@ func TestCreateObservableAnalysis(t *testing.T) { client, apiHandler, closeServer := setup() defer closeServer() ctx := context.Background() - apiHandler.Handle("/api/analyze_observable", serverHandler(t, testCase, "POST")) + apiHandler.Handle(constants.ANALYZE_OBSERVABLE_URL, serverHandler(t, testCase, "POST")) observableParams, ok := testCase.Input.(gointelowl.ObservableAnalysisParams) if ok { gottenAnalysisResponse, err := client.CreateObservableAnalysis(ctx, &observableParams) @@ -92,7 +93,7 @@ func TestCreateMultipleObservableAnalysis(t *testing.T) { t.Run(name, func(t *testing.T) { client, apiHandler, closeServer := setup() defer closeServer() - apiHandler.Handle("/api/analyze_multiple_observables", serverHandler(t, testCase, "POST")) + apiHandler.Handle(constants.ANALYZE_MULTIPLE_OBSERVABLES_URL, serverHandler(t, testCase, "POST")) ctx := context.Background() multipleObservableParams, ok := testCase.Input.(gointelowl.MultipleObservableAnalysisParams) if ok { @@ -142,7 +143,7 @@ func TestCreateFileAnalysis(t *testing.T) { t.Run(name, func(t *testing.T) { client, apiHandler, closeServer := setup() defer closeServer() - apiHandler.Handle("/api/analyze_file", serverHandler(t, testCase, "POST")) + apiHandler.Handle(constants.ANALYZE_FILE_URL, serverHandler(t, testCase, "POST")) ctx := context.Background() fileAnalysisParams, ok := testCase.Input.(gointelowl.FileAnalysisParams) if ok { @@ -198,7 +199,7 @@ func TestCreateMultipleFilesAnalysis(t *testing.T) { t.Run(name, func(t *testing.T) { client, apiHandler, closeServer := setup() defer closeServer() - apiHandler.Handle("/api/analyze_mutliple_files", serverHandler(t, testCase, "POST")) + apiHandler.Handle(constants.ANALYZE_MULTIPLE_FILES_URL, serverHandler(t, testCase, "POST")) ctx := context.Background() multipleFilesAnalysisParams, ok := testCase.Input.(gointelowl.MultipleFileAnalysisParams) if ok { diff --git a/tests/analyzerService_test.go b/tests/analyzerService_test.go index 1f2bcc8..2ce918d 100644 --- a/tests/analyzerService_test.go +++ b/tests/analyzerService_test.go @@ -7,6 +7,7 @@ import ( "net/http" "testing" + "github.com/intelowlproject/go-intelowl/constants" "github.com/intelowlproject/go-intelowl/gointelowl" ) @@ -85,7 +86,7 @@ func TestAnalyzerServiceGetConfigs(t *testing.T) { client, apiHandler, closeServer := setup() defer closeServer() ctx := context.Background() - apiHandler.Handle("/api/get_analyzer_configs", serverHandler(t, testCase, "GET")) + apiHandler.Handle(constants.ANALYZER_CONFIG_URL, serverHandler(t, testCase, "GET")) gottenAnalyzerConfigList, err := client.AnalyzerService.GetConfigs(ctx) if err != nil { testError(t, testCase, err) @@ -122,7 +123,7 @@ func TestAnalyzerServiceHealthCheck(t *testing.T) { ctx := context.Background() input, ok := testCase.Input.(string) if ok { - testUrl := fmt.Sprintf("/api/analyzer/%s/healthcheck", input) + testUrl := fmt.Sprintf(constants.ANALYZER_HEALTHCHECK_URL, input) apiHandler.Handle(testUrl, serverHandler(t, testCase, "GET")) status, err := client.AnalyzerService.HealthCheck(ctx, input) if err != nil { diff --git a/tests/connectorService_test.go b/tests/connectorService_test.go index c3047b2..e6cef8b 100644 --- a/tests/connectorService_test.go +++ b/tests/connectorService_test.go @@ -8,6 +8,7 @@ import ( "sort" "testing" + "github.com/intelowlproject/go-intelowl/constants" "github.com/intelowlproject/go-intelowl/gointelowl" ) @@ -43,7 +44,7 @@ func TestConnectorServiceGetConfigs(t *testing.T) { client, apiHandler, closeServer := setup() defer closeServer() ctx := context.Background() - apiHandler.Handle("/api/get_connector_configs", serverHandler(t, testCase, "GET")) + apiHandler.Handle(constants.CONNECTOR_CONFIG_URL, serverHandler(t, testCase, "GET")) gottenConnectorConfigList, err := client.ConnectorService.GetConfigs(ctx) if err != nil { testError(t, testCase, err) @@ -80,7 +81,7 @@ func TestConnectorServiceHealthCheck(t *testing.T) { ctx := context.Background() input, ok := testCase.Input.(string) if ok { - testUrl := fmt.Sprintf("/api/connector/%s/healthcheck", input) + testUrl := fmt.Sprintf(constants.CONNECTOR_HEALTHCHECK_URL, input) apiHandler.Handle(testUrl, serverHandler(t, testCase, "GET")) status, err := client.ConnectorService.HealthCheck(ctx, input) if err != nil { diff --git a/tests/jobService_test.go b/tests/jobService_test.go index 3e1c62c..9dfcda3 100644 --- a/tests/jobService_test.go +++ b/tests/jobService_test.go @@ -7,6 +7,7 @@ import ( "net/http" "testing" + "github.com/intelowlproject/go-intelowl/constants" "github.com/intelowlproject/go-intelowl/gointelowl" ) @@ -31,7 +32,7 @@ func TestJobServiceList(t *testing.T) { client, apiHandler, closeServer := setup() defer closeServer() ctx := context.Background() - apiHandler.Handle("/api/jobs", serverHandler(t, testCase, "GET")) + apiHandler.Handle(constants.BASE_JOB_URL, serverHandler(t, testCase, "GET")) gottenJobList, err := client.JobService.List(ctx) if err != nil { testError(t, testCase, err) @@ -77,7 +78,7 @@ func TestJobServiceGet(t *testing.T) { id, ok := testCase.Input.(int) if ok { jobId := uint64(id) - testUrl := fmt.Sprintf("/api/jobs/%d", jobId) + testUrl := fmt.Sprintf(constants.SPECIFIC_JOB_URL, jobId) apiHandler.Handle(testUrl, serverHandler(t, testCase, "GET")) gottenJob, err := client.JobService.Get(ctx, jobId) if err != nil { @@ -121,7 +122,7 @@ func TestJobServiceDownloadSample(t *testing.T) { id, ok := testCase.Input.(int) if ok { jobId := uint64(id) - testUrl := fmt.Sprintf("/api/jobs/%d/download_sample", jobId) + testUrl := fmt.Sprintf(constants.DOWNLOAD_SAMPLE_JOB_URL, jobId) apiHandler.Handle(testUrl, serverHandler(t, testCase, "GET")) gottenSample, err := client.JobService.DownloadSample(ctx, jobId) if err != nil { @@ -164,7 +165,7 @@ func TestJobServiceDelete(t *testing.T) { id, ok := testCase.Input.(int) if ok { jobId := uint64(id) - testUrl := fmt.Sprintf("/api/jobs/%d", jobId) + testUrl := fmt.Sprintf(constants.SPECIFIC_JOB_URL, jobId) apiHandler.Handle(testUrl, serverHandler(t, testCase, "DELETE")) isDeleted, err := client.JobService.Delete(ctx, jobId) if err != nil { @@ -213,7 +214,7 @@ func TestJobServiceKill(t *testing.T) { id, ok := testCase.Input.(int) if ok { jobId := uint64(id) - testUrl := fmt.Sprintf("/api/jobs/%d/kill", jobId) + testUrl := fmt.Sprintf(constants.KILL_JOB_URL, jobId) apiHandler.Handle(testUrl, serverHandler(t, testCase, "PATCH")) isDeleted, err := client.JobService.Kill(ctx, jobId) if err != nil { @@ -275,7 +276,7 @@ func TestJobServiceKillAnalyzer(t *testing.T) { ctx := context.Background() inputData, ok := testCase.Input.(input) if ok { - testUrl := fmt.Sprintf("/api/jobs/%d/analyzer/%s/kill", inputData.Id, inputData.Name) + testUrl := fmt.Sprintf(constants.KILL_ANALYZER_JOB_URL, inputData.Id, inputData.Name) apiHandler.Handle(testUrl, serverHandler(t, testCase, "PATCH")) isDeleted, err := client.JobService.KillAnalyzer(ctx, inputData.Id, inputData.Name) if err != nil { @@ -308,7 +309,7 @@ func TestJobServiceRetryAnalyzer(t *testing.T) { ctx := context.Background() inputData, ok := testCase.Input.(input) if ok { - testUrl := fmt.Sprintf("/api/jobs/%d/analyzer/%s/retry", inputData.Id, inputData.Name) + testUrl := fmt.Sprintf(constants.RETRY_ANALYZER_JOB_URL, inputData.Id, inputData.Name) apiHandler.Handle(testUrl, serverHandler(t, testCase, "PATCH")) retry, err := client.JobService.RetryAnalyzer(ctx, inputData.Id, inputData.Name) if err != nil { @@ -341,7 +342,7 @@ func TestJobServiceKillConnector(t *testing.T) { ctx := context.Background() inputData, ok := testCase.Input.(input) if ok { - testUrl := fmt.Sprintf("/api/jobs/%d/connector/%s/kill", inputData.Id, inputData.Name) + testUrl := fmt.Sprintf(constants.KILL_CONNECTOR_JOB_URL, inputData.Id, inputData.Name) apiHandler.Handle(testUrl, serverHandler(t, testCase, "PATCH")) isDeleted, err := client.JobService.KillConnector(ctx, inputData.Id, inputData.Name) if err != nil { @@ -374,7 +375,7 @@ func TestJobServiceRetryConnector(t *testing.T) { ctx := context.Background() inputData, ok := testCase.Input.(input) if ok { - testUrl := fmt.Sprintf("/api/jobs/%d/connector/%s/retry", inputData.Id, inputData.Name) + testUrl := fmt.Sprintf(constants.RETRY_CONNECTOR_JOB_URL, inputData.Id, inputData.Name) apiHandler.Handle(testUrl, serverHandler(t, testCase, "PATCH")) retry, err := client.JobService.RetryConnector(ctx, inputData.Id, inputData.Name) if err != nil { diff --git a/tests/tagService_test.go b/tests/tagService_test.go index eb3119d..671ac1f 100644 --- a/tests/tagService_test.go +++ b/tests/tagService_test.go @@ -6,6 +6,7 @@ import ( "net/http" "testing" + "github.com/intelowlproject/go-intelowl/constants" "github.com/intelowlproject/go-intelowl/gointelowl" ) @@ -44,7 +45,7 @@ func TestTagServiceList(t *testing.T) { t.Run(name, func(t *testing.T) { client, apiHandler, closeServer := setup() defer closeServer() - apiHandler.Handle("/api/tags", serverHandler(t, testCase, "GET")) + apiHandler.Handle(constants.BASE_TAG_URL, serverHandler(t, testCase, "GET")) ctx := context.Background() gottenTagList, err := client.TagService.List(ctx) if err != nil { @@ -86,7 +87,7 @@ func TestTagServiceGet(t *testing.T) { id, ok := testCase.Input.(int) if ok { tagId := uint64(id) - testUrl := fmt.Sprintf("/api/tags/%d", tagId) + testUrl := fmt.Sprintf(constants.SPECIFIC_TAG_URL, tagId) apiHandler.Handle(testUrl, serverHandler(t, testCase, "GET")) gottenTag, err := client.TagService.Get(ctx, tagId) // Helper test to check error @@ -137,7 +138,7 @@ func TestTagServiceCreate(t *testing.T) { client, apiHandler, closeServer := setup() defer closeServer() ctx := context.Background() - apiHandler.Handle("/api/tags", serverHandler(t, testCase, "POST")) + apiHandler.Handle(constants.BASE_TAG_URL, serverHandler(t, testCase, "POST")) tagParams, ok := testCase.Input.(gointelowl.TagParams) if ok { gottenTag, err := client.TagService.Create(ctx, &tagParams) @@ -178,7 +179,7 @@ func TestTagServiceUpdate(t *testing.T) { ctx := context.Background() tag, ok := testCase.Input.(gointelowl.Tag) if ok { - testUrl := fmt.Sprintf("/api/tags/%d", tag.ID) + testUrl := fmt.Sprintf(constants.SPECIFIC_TAG_URL, tag.ID) apiHandler.Handle(testUrl, serverHandler(t, testCase, "PUT")) gottenTag, err := client.TagService.Update(ctx, tag.ID, &gointelowl.TagParams{ Label: tag.Label, @@ -212,7 +213,7 @@ func TestTagServiceDelete(t *testing.T) { id, ok := testCase.Input.(int) if ok { tagId := uint64(id) - testUrl := fmt.Sprintf("/api/tags/%d", tagId) + testUrl := fmt.Sprintf(constants.SPECIFIC_TAG_URL, tagId) apiHandler.Handle(testUrl, serverHandler(t, testCase, "DELETE")) isDeleted, err := client.TagService.Delete(ctx, tagId) if err != nil { diff --git a/tests/userService_test.go b/tests/userService_test.go index 4bef65e..36c00cf 100644 --- a/tests/userService_test.go +++ b/tests/userService_test.go @@ -6,6 +6,7 @@ import ( "net/http" "testing" + "github.com/intelowlproject/go-intelowl/constants" "github.com/intelowlproject/go-intelowl/gointelowl" ) @@ -27,7 +28,7 @@ func TestUserServiceAccess(t *testing.T) { t.Run(name, func(t *testing.T) { client, apiHandler, closeServer := setup() defer closeServer() - apiHandler.Handle("/api/me/access", serverHandler(t, testCase, "GET")) + apiHandler.Handle(constants.USER_DETAILS_URL, serverHandler(t, testCase, "GET")) ctx := context.Background() gottenUserResponse, err := client.UserService.Access(ctx) if err != nil { @@ -57,7 +58,7 @@ func TestUserServiceOrganization(t *testing.T) { t.Run(name, func(t *testing.T) { client, apiHandler, closeServer := setup() defer closeServer() - apiHandler.Handle("/api/me/organization", serverHandler(t, testCase, "GET")) + apiHandler.Handle(constants.ORGANIZATION_URL, serverHandler(t, testCase, "GET")) ctx := context.Background() gottenUserResponse, err := client.UserService.Organization(ctx) if err != nil { @@ -90,7 +91,7 @@ func TestUserServiceCreateOrganization(t *testing.T) { client, apiHandler, closeServer := setup() defer closeServer() ctx := context.Background() - apiHandler.Handle("/api/me/organization", serverHandler(t, testCase, "POST")) + apiHandler.Handle(constants.ORGANIZATION_URL, serverHandler(t, testCase, "POST")) params, ok := testCase.Input.(gointelowl.OrganizationParams) if ok { gottenOrgResponse, err := client.UserService.CreateOrganization(ctx, ¶ms) @@ -120,7 +121,7 @@ func TestUserServiceRemoveMemberFromOrganization(t *testing.T) { client, apiHandler, closeServer := setup() defer closeServer() ctx := context.Background() - apiHandler.Handle("/api/me/organization/remove_member", serverHandler(t, testCase, "POST")) + apiHandler.Handle(constants.REMOVE_MEMBER_FROM_ORGANIZATION_URL, serverHandler(t, testCase, "POST")) params, ok := testCase.Input.(gointelowl.MemberParams) if ok { left, err := client.UserService.RemoveMemberFromOrganization(ctx, ¶ms)