perf: 优化 ops task

This commit is contained in:
ibuler
2024-03-18 14:19:15 +08:00
committed by 老广
parent 90d4914280
commit e9f591b33b
4 changed files with 46 additions and 33 deletions

View File

@@ -52,26 +52,26 @@ class PlaybookViewSet(OrgBulkModelViewSet):
if 'multipart/form-data' in self.request.headers['Content-Type']:
src_path = safe_join(settings.MEDIA_ROOT, instance.path.name)
dest_path = safe_join(settings.DATA_DIR, "ops", "playbook", instance.id.__str__())
try:
unzip_playbook(src_path, dest_path)
except RuntimeError as e:
except RuntimeError:
raise JMSException(code='invalid_playbook_file', detail={"msg": "Unzip failed"})
if 'main.yml' not in os.listdir(dest_path):
raise PlaybookNoValidEntry
else:
if instance.create_method == 'blank':
dest_path = safe_join(settings.DATA_DIR, "ops", "playbook", instance.id.__str__())
os.makedirs(dest_path)
with open(safe_join(dest_path, 'main.yml'), 'w') as f:
f.write('## write your playbook here')
elif instance.create_method == 'blank':
dest_path = safe_join(settings.DATA_DIR, "ops", "playbook", instance.id.__str__())
os.makedirs(dest_path)
with open(safe_join(dest_path, 'main.yml'), 'w') as f:
f.write('## write your playbook here')
class PlaybookFileBrowserAPIView(APIView):
permission_classes = (RBACPermission,)
rbac_perms = {
'GET': 'ops.change_playbook',
'GET': 'ops.view_playbook',
'POST': 'ops.change_playbook',
'DELETE': 'ops.change_playbook',
'PATCH': 'ops.change_playbook',