mirror of https://github.com/jumpserver/jumpserver
fix: 修复上传方式创建 playbook 内容为空的问题
parent
921d8f6a28
commit
403faf9663
|
@ -37,22 +37,19 @@ class PlaybookViewSet(OrgBulkModelViewSet):
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
def perform_create(self, serializer):
|
||||||
instance = serializer.save()
|
instance = serializer.save()
|
||||||
if instance.create_method == 'blank':
|
if 'multipart/form-data' in self.request.headers['Content-Type']:
|
||||||
dest_path = os.path.join(settings.DATA_DIR, "ops", "playbook", instance.id.__str__())
|
|
||||||
os.makedirs(dest_path)
|
|
||||||
with open(os.path.join(dest_path, 'main.yml'), 'w') as f:
|
|
||||||
f.write('## write your playbook here')
|
|
||||||
|
|
||||||
if instance.create_method == 'upload':
|
|
||||||
src_path = os.path.join(settings.MEDIA_ROOT, instance.path.name)
|
src_path = os.path.join(settings.MEDIA_ROOT, instance.path.name)
|
||||||
dest_path = os.path.join(settings.DATA_DIR, "ops", "playbook", instance.id.__str__())
|
dest_path = os.path.join(settings.DATA_DIR, "ops", "playbook", instance.id.__str__())
|
||||||
unzip_playbook(src_path, dest_path)
|
unzip_playbook(src_path, dest_path)
|
||||||
valid_entry = ('main.yml', 'main.yaml', 'main')
|
if 'main.yml' not in os.listdir(dest_path):
|
||||||
for f in os.listdir(dest_path):
|
raise PlaybookNoValidEntry
|
||||||
if f in valid_entry:
|
|
||||||
return
|
else:
|
||||||
os.remove(dest_path)
|
if instance.create_method == 'blank':
|
||||||
raise PlaybookNoValidEntry
|
dest_path = os.path.join(settings.DATA_DIR, "ops", "playbook", instance.id.__str__())
|
||||||
|
os.makedirs(dest_path)
|
||||||
|
with open(os.path.join(dest_path, 'main.yml'), 'w') as f:
|
||||||
|
f.write('## write your playbook here')
|
||||||
|
|
||||||
|
|
||||||
class PlaybookFileBrowserAPIView(APIView):
|
class PlaybookFileBrowserAPIView(APIView):
|
||||||
|
|
Loading…
Reference in New Issue