From 674f69eb03474fd12a1c982b3e7210dd086d63cb Mon Sep 17 00:00:00 2001 From: Himadri Bhattacharjee Date: Fri, 14 Jul 2023 07:32:04 +0530 Subject: [PATCH] refactor: simplify conditional statement for formatting OTX provider URL --- pkg/providers/otx/otx.go | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pkg/providers/otx/otx.go b/pkg/providers/otx/otx.go index 6a32359..3d5c909 100644 --- a/pkg/providers/otx/otx.go +++ b/pkg/providers/otx/otx.go @@ -78,19 +78,17 @@ paginate: } func (c *Client) formatURL(domain string, page int) string { + category := "hostname" if !domainutil.HasSubdomain(domain) { - return fmt.Sprintf(_BaseURL+"api/v1/indicators/domain/%s/url_list?limit=100&page=%d", - domain, page, - ) - } else if domainutil.HasSubdomain(domain) && c.config.IncludeSubdomains { - return fmt.Sprintf(_BaseURL+"api/v1/indicators/domain/%s/url_list?limit=100&page=%d", - domainutil.Domain(domain), page, - ) - } else { - return fmt.Sprintf(_BaseURL+"api/v1/indicators/hostname/%s/url_list?limit=100&page=%d", - domain, page, - ) + category = "domain" } + if domainutil.HasSubdomain(domain) && c.config.IncludeSubdomains { + domain = domainutil.Domain(domain) + category = "domain" + } + + return fmt.Sprintf("%sapi/v1/indicators/%s/%s/url_list?limit=100&page=%d", _BaseURL, category, domain, page) + } var _BaseURL = "https://otx.alienvault.com/"