From 4d4af37e742e1a9b2d946d1b94c4947d7925883a Mon Sep 17 00:00:00 2001 From: Kurochkin Dmitriy Vadimovich Date: Fri, 20 Dec 2024 14:22:25 +0300 Subject: [PATCH] Add settings: * DD_SEARCH_SCM_TYPE - flag to enable/disable scm_type search * DD_DEFAULT_SCM_TYPE - default value for scm_type * DD_JIRA_CONNECT_METHOD - import path for jira connect method --- dojo/models.py | 4 ++-- dojo/settings/settings.dist.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/dojo/models.py b/dojo/models.py index 99074a9cf3b..fc4d51b836a 100644 --- a/dojo/models.py +++ b/dojo/models.py @@ -3191,13 +3191,13 @@ def get_file_path_with_link(self): def get_scm_type(self): # extract scm type from product custom field 'scm-type' - if hasattr(self.test.engagement, "product"): + if settings.SEARCH_SCM_TYPE and hasattr(self.test.engagement, "product"): dojo_meta = DojoMeta.objects.filter(product=self.test.engagement.product, name="scm-type").first() if dojo_meta: st = dojo_meta.value.strip() if st: return st.lower() - return "" + return settings.DEFAULT_SCM_TYPE def scm_public_prepare_base_link(self, uri): # scm public (https://scm-domain.org) url template for browse is: diff --git a/dojo/settings/settings.dist.py b/dojo/settings/settings.dist.py index 1d33fe8dfda..f8d05ad6cfb 100644 --- a/dojo/settings/settings.dist.py +++ b/dojo/settings/settings.dist.py @@ -304,6 +304,12 @@ # For HTTP requests, how long connection is open before timeout # This settings apply only on requests performed by "requests" lib used in Dojo code (if some included lib is using "requests" as well, this does not apply there) DD_REQUESTS_TIMEOUT=(int, 30), + # When set to True, searches for scm-type in DojoMeta + DD_SEARCH_SCM_TYPE=(bool, True), + # When scm-type is not found for a product or DD_SEARCH_SCM_TYPE is False returns the specified value + DD_DEFAULT_SCM_TYPE=(str, ""), + # When set, use this method for connect to jira + DD_JIRA_CONNECT_METHOD=(str, ""), ) @@ -1802,6 +1808,19 @@ def saml2_attrib_map_format(dict): # ------------------------------------------------------------------------------ REQUESTS_TIMEOUT = env("DD_REQUESTS_TIMEOUT") +SEARCH_SCM_TYPE = env("DD_SEARCH_SCM_TYPE") + +if env("DD_DEFAULT_SCM_TYPE") in ["github", "gitlab", "gitea", "codeberg", "bitbucket", "bitbucket-standalone"]: + DEFAULT_SCM_TYPE = env("DD_DEFAULT_SCM_TYPE") +else: + DEFAULT_SCM_TYPE = "" + +# Example: +# For file /app/dojo/jira_link/helper_jira.py with method connect_to_jira_by_token(jira_server, _, jira_token) +# DD_JIRA_CONNECT_METHOD = dojo.jira_link.helper_jira.connect_to_jira_by_token +if env("DD_JIRA_CONNECT_METHOD"): + JIRA_CONNECT_METHOD = env("DD_JIRA_CONNECT_METHOD") + # ------------------------------------------------------------------------------ # Ignored Warnings # ------------------------------------------------------------------------------