Skip to content

Commit 42ec064

Browse files
Gitlab projects tag_list and web_url reflected in products. Fix DefectDojo#4489 (DefectDojo#4582)
* add Gitlab project min_access_level in settings * Update settings.dist.py * Update pipeline.py * Update pipeline.py * Update settings.dist.py * Update pipeline.py * Update pipeline.py * Update pipeline.py * Update pipeline.py * Update pipeline.py * Update pipeline.py * Update pipeline.py
1 parent 764f355 commit 42ec064

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

dojo/pipeline.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,27 @@ def update_product_access(backend, uid, user=None, social=None, *args, **kwargs)
8080
# Create product_type if necessary
8181
product_type, created = Product_Type.objects.get_or_create(name='Gitlab Import')
8282
# For each project: create a new product or update product's authorized_users
83-
for project_name in project_names:
84-
if project_name not in user_product_names:
83+
for project in projects:
84+
if project.path_with_namespace not in user_product_names:
8585
# Create new product
86-
product, created = Product.objects.get_or_create(name=project_name, prod_type=product_type)
86+
product, created = Product.objects.get_or_create(name=project.path_with_namespace, prod_type=product_type)
8787
if not settings.FEATURE_AUTHORIZATION_V2:
8888
product.authorized_users.add(user)
8989
product.save()
9090
else:
9191
product_member, created = Product_Member.objects.get_or_create(product=product, user=user, defaults={'role': Role.objects.get(id=Roles.Owner)})
92+
# Import tags and/orl URL if necessary
93+
if settings.GITLAB_PROJECT_IMPORT_TAGS:
94+
if hasattr(project, 'topics'):
95+
if len(project.topics) > 0:
96+
product.tags = ",".join(project.topics)
97+
elif hasattr(project, 'tag_list') and len(project.tag_list) > 0:
98+
product.tags = ",".join(project.tag_list)
99+
if settings.GITLAB_PROJECT_IMPORT_URL:
100+
if hasattr(project, 'web_url') and len(project.web_url) > 0:
101+
product.description = "[" + project.web_url + "](" + project.web_url + ")"
102+
if settings.GITLAB_PROJECT_IMPORT_TAGS or settings.GITLAB_PROJECT_IMPORT_URL:
103+
product.save()
92104

93105
# For each product: if user is not project member any more, remove him from product's authorized users
94106
for product_name in user_product_names:

dojo/settings/settings.dist.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
DD_SOCIAL_AUTH_AZUREAD_TENANT_OAUTH2_RESOURCE=(str, 'https://graph.microsoft.com/'),
103103
DD_SOCIAL_AUTH_GITLAB_OAUTH2_ENABLED=(bool, False),
104104
DD_SOCIAL_AUTH_GITLAB_PROJECT_AUTO_IMPORT=(bool, False),
105+
DD_SOCIAL_AUTH_GITLAB_PROJECT_IMPORT_TAGS=(bool, False),
106+
DD_SOCIAL_AUTH_GITLAB_PROJECT_IMPORT_URL=(bool, False),
105107
DD_SOCIAL_AUTH_GITLAB_PROJECT_MIN_ACCESS_LEVEL=(int, 20),
106108
DD_SOCIAL_AUTH_GITLAB_KEY=(str, ''),
107109
DD_SOCIAL_AUTH_GITLAB_SECRET=(str, ''),
@@ -429,6 +431,8 @@ def generate_url(scheme, double_slashes, user, password, host, port, path, param
429431

430432
GITLAB_OAUTH2_ENABLED = env('DD_SOCIAL_AUTH_GITLAB_OAUTH2_ENABLED')
431433
GITLAB_PROJECT_AUTO_IMPORT = env('DD_SOCIAL_AUTH_GITLAB_PROJECT_AUTO_IMPORT')
434+
GITLAB_PROJECT_IMPORT_TAGS = env('DD_SOCIAL_AUTH_GITLAB_PROJECT_IMPORT_TAGS')
435+
GITLAB_PROJECT_IMPORT_URL = env('DD_SOCIAL_AUTH_GITLAB_PROJECT_IMPORT_URL')
432436
GITLAB_PROJECT_MIN_ACCESS_LEVEL = env('DD_SOCIAL_AUTH_GITLAB_PROJECT_MIN_ACCESS_LEVEL')
433437
SOCIAL_AUTH_GITLAB_KEY = env('DD_SOCIAL_AUTH_GITLAB_KEY')
434438
SOCIAL_AUTH_GITLAB_SECRET = env('DD_SOCIAL_AUTH_GITLAB_SECRET')

0 commit comments

Comments
 (0)