Skip to content

Commit 6824ed6

Browse files
committed
Merge branch 'main' into feat-email
2 parents 42459de + 2489b7d commit 6824ed6

File tree

9 files changed

+105
-21
lines changed

9 files changed

+105
-21
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ enigma.log
1919
# Dependency directories
2020
node_modules/
2121

22+
#Access Modules
23+
Access/access_modules
24+
2225
# Folders created by Docker Compose
2326
mounts/
2427
public/

Access/admin.py

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
'''
2+
Models to configure diplay, search and filtering for models on admin panel
3+
'''
4+
15
from django.contrib import admin
26

37
from Access.models import (
@@ -14,17 +18,61 @@
1418

1519

1620
class UserAdmin(admin.ModelAdmin):
21+
'''Class to describe how to display User model on admin panel'''
1722
ordering = ("name", "email")
1823
search_fields = ("name", "email")
1924
list_display = ("name", "email")
2025

2126

27+
class MembershipV2AdminPanel(admin.ModelAdmin):
28+
'''Class to describe how to display MembershipV2 on admin panel'''
29+
ordering = ("membership_id", "user__name", "group__name")
30+
search_fields = ("membership_id", "user__name", "group__name")
31+
list_display = ("membership_id", "user", "group")
32+
33+
34+
class AccessV2AdminPanel(admin.ModelAdmin):
35+
'''Class to describe how to display AccessV2 model on admin panel'''
36+
search_fields = ("access_tag", "access_label")
37+
list_display = ("access_tag", "access_label")
38+
sortable_by = ("access_tag",)
39+
40+
41+
class UserIdentityAdminPanel(admin.ModelAdmin):
42+
'''Class to describe how to display User Identity on admin panel'''
43+
search_fields = ("access_tag", "user__name", "status")
44+
list_display = ("access_tag", "user", "identity", "status")
45+
46+
47+
class UserAccessMappingAdminPanel(admin.ModelAdmin):
48+
'''Class to describe how to display UserAccessMapping on admin panel'''
49+
search_fields = (
50+
"request_id",
51+
"user_identity__user__name",
52+
"access__access_tag",
53+
"access__access_label",
54+
"status"
55+
)
56+
list_display = (
57+
"request_id",
58+
"get_user_name",
59+
"access",
60+
"status",
61+
)
62+
ordering = (
63+
"request_id",
64+
"user_identity__user__name",
65+
"access",
66+
"status"
67+
)
68+
69+
2270
admin.site.register(User, UserAdmin)
2371
admin.site.register(Permission)
24-
admin.site.register(UserAccessMapping)
72+
admin.site.register(UserAccessMapping, UserAccessMappingAdminPanel)
2573
admin.site.register(Role)
26-
admin.site.register(AccessV2)
74+
admin.site.register(AccessV2, AccessV2AdminPanel)
2775
admin.site.register(GroupV2)
28-
admin.site.register(MembershipV2)
76+
admin.site.register(MembershipV2, MembershipV2AdminPanel)
2977
admin.site.register(GroupAccessMapping)
30-
admin.site.register(UserIdentity)
78+
admin.site.register(UserIdentity, UserIdentityAdminPanel)

Access/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,9 @@ def create(
940940
mapping.save()
941941
return mapping
942942

943+
def get_user_name(self):
944+
return self.user_identity.user.name
945+
943946

944947
class GroupAccessMapping(models.Model):
945948
"""

config.json.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"access_modules": {
1010
"git_urls": [
1111
"https://github.com/browserstack/enigma-public-access-modules.git"
12-
]
12+
],
13+
"RETRY_LIMIT": 5
1314
},
1415
"enigmaGroup": {
1516
"MAIL_APPROVER_GROUPS": [

docker-compose.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,15 @@ services:
5656
- redis
5757
- web
5858
command: >
59-
bash -c "
60-
echo Starting celery;
61-
python3 -m celery -A EnigmaAutomation worker -n worker1 -l DEBUG"
59+
/bin/bash -c "
60+
while ! nc -z redis 6379;
61+
do
62+
echo sleeping;
63+
sleep 1;
64+
done;
65+
echo Connected!;
66+
echo Starting celery;
67+
python3 -m celery -A EnigmaAutomation worker -n worker1 -l DEBUG"
6268
test:
6369
container_name: test
6470
build:

schema.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,16 @@
6969
"access_modules": {
7070
"description": "List of access modules attached to this tool",
7171
"type": "object",
72-
"additionalProperties": false,
72+
"additionalProperties": true,
7373
"properties": {
7474
"git_urls": {
7575
"description": "List of git URLs of access modules",
7676
"type": "array"
77+
},
78+
"RETRY_LIMIT": {
79+
"description": "Number of retries before raising cloning failure exception",
80+
"type": "integer",
81+
"minimum": 1
7782
}
7883
}
7984
},

scripts/clone_access_modules.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import json
22
import sys
33
import shutil
4-
from git import Repo
4+
from git import Repo, GitCommandError
5+
import time
56
import os
67

78
print("Starting cloning setup")
89
try:
910
f = open("./config.json", "r")
1011
config = json.load(f)
12+
RETRY_LIMIT = config["access_modules"]["RETRY_LIMIT"]
1113
urls = config["access_modules"]["git_urls"]
1214

1315
for each_access_module in os.listdir('Access/access_modules'):
@@ -33,10 +35,26 @@
3335
folder_name = url.split("/").pop()[:-4]
3436
folder_path = "./Access/access_modules/" + folder_name
3537
try:
36-
if specified_branch:
37-
Repo.clone_from(url, folder_path, branch=specified_branch)
38-
else:
39-
Repo.clone_from(url, folder_path)
38+
retry_exception = None
39+
for i in range(1, RETRY_LIMIT + 1):
40+
try:
41+
if specified_branch:
42+
Repo.clone_from(url, folder_path, branch=specified_branch)
43+
else:
44+
Repo.clone_from(url, folder_path)
45+
except (GitCommandError, Exception) as ex:
46+
print("error occurred: ", ex)
47+
print("retry:{1}/{2}".format(ex, i, RETRY_LIMIT))
48+
retry_exception = ex
49+
time.sleep(10 * i)
50+
print("retrying")
51+
else:
52+
retry_exception = None
53+
break
54+
if (retry_exception != None):
55+
print("max retry count reached")
56+
raise retry_exception
57+
4058
# move all folders, not files in the cloned repo to the access_modules
4159
# folder except the .git, .github and secrets folder
4260
for file in os.listdir(folder_path):
@@ -52,7 +70,7 @@
5270
)
5371
except:
5472
print("File is already present.")
55-
73+
5674
if(file == "requirements.txt"):
5775
current_requirements_file = folder_path + "/" + file
5876
#Read the requirements
@@ -64,12 +82,12 @@
6482

6583
# Merge the requirements
6684
merged_requirements = list(set(requirements1 + requirements2))
67-
85+
6886
#update the requirements.txt
6987
with open(requirements_file, 'w') as out_file:
7088
for requirement in sorted(merged_requirements):
7189
out_file.write(requirement)
72-
90+
7391
print("Cloning successful!")
7492
except Exception as e:
7593
print("error-->",e)
@@ -84,7 +102,7 @@
84102
except Exception as e:
85103
print(e)
86104
print("failed to remove " + folder_path + " folder.")
87-
105+
88106
except Exception as e:
89107
print("Access module cloning failed!")
90108
print(str(e))

scripts/validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
validate(instance=config, schema=schema)
2626
logger.info("Schema validation passed!")
2727
except Exception as e:
28-
logger.error("Schema validation failed! Error is: " + e)
28+
logger.error("Schema validation failed! Error is: %s", e)
2929
traceback.format_exc()
3030
sys.exit(1)

secrets/ops_app_celery.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
CELERY_BROKER_URL=redis://redis:6379/0
2-
CELERY_RESULT_BACKEND=redis://redis:6379/0
1+
CELERY_BROKER_URL=redis://host.docker.internal:6379
2+
CELERY_RESULT_BACKEND=redis://host.docker.internal:6379
33
C_FORCE_ROOT=true
44
MYSQL_ROOT_PASSWORD=testtest
55
MYSQL_DATABASE=enigma

0 commit comments

Comments
 (0)