mirror of https://github.com/jumpserver/jumpserver
feat: ansible receptor 适配文件上传
parent
3f67b40975
commit
6a12bc39e9
|
@ -38,6 +38,7 @@ BASE_DIR = const.BASE_DIR
|
|||
PROJECT_DIR = const.PROJECT_DIR
|
||||
APPS_DIR = os.path.join(PROJECT_DIR, 'apps')
|
||||
DATA_DIR = os.path.join(PROJECT_DIR, 'data')
|
||||
SHARE_DIR = os.path.join(DATA_DIR, 'share')
|
||||
ANSIBLE_DIR = os.path.join(DATA_DIR, 'ansible')
|
||||
CERTS_DIR = os.path.join(DATA_DIR, 'certs')
|
||||
|
||||
|
@ -319,7 +320,6 @@ PRIVATE_STORAGE_AUTH_FUNCTION = 'jumpserver.rewriting.storage.permissions.allow_
|
|||
PRIVATE_STORAGE_INTERNAL_URL = '/private-media/'
|
||||
PRIVATE_STORAGE_SERVER = 'jumpserver.rewriting.storage.servers.StaticFileServer'
|
||||
|
||||
|
||||
# Use django-bootstrap-form to format template, input max width arg
|
||||
# BOOTSTRAP_COLUMN_COUNT = 11
|
||||
|
||||
|
|
|
@ -133,17 +133,19 @@ class SuperPlaybookRunner(PlaybookRunner):
|
|||
|
||||
|
||||
class UploadFileRunner:
|
||||
def __init__(self, inventory, job_id, dest_path, callback=None):
|
||||
def __init__(self, inventory, project_dir, job_id, dest_path, callback=None):
|
||||
self.id = uuid.uuid4()
|
||||
self.inventory = inventory
|
||||
self.project_dir = project_dir
|
||||
self.cb = DefaultCallback()
|
||||
upload_file_dir = safe_join(settings.DATA_DIR, 'job_upload_file')
|
||||
upload_file_dir = safe_join(settings.SHARE_DIR, 'job_upload_file')
|
||||
self.src_paths = safe_join(upload_file_dir, str(job_id))
|
||||
self.dest_path = safe_join("/tmp", dest_path)
|
||||
|
||||
def run(self, verbosity=0, **kwargs):
|
||||
verbosity = get_ansible_log_verbosity(verbosity)
|
||||
runner.run(
|
||||
private_data_dir=self.project_dir,
|
||||
host_pattern="*",
|
||||
inventory=self.inventory,
|
||||
module='copy',
|
||||
|
|
|
@ -178,7 +178,7 @@ class JobViewSet(OrgBulkModelViewSet):
|
|||
job = get_object_or_404(Job, pk=job_id, creator=request.user)
|
||||
job_args = json.loads(job.args)
|
||||
src_path_info = []
|
||||
upload_file_dir = safe_join(settings.DATA_DIR, 'job_upload_file', job_id)
|
||||
upload_file_dir = safe_join(settings.SHARE_DIR, 'job_upload_file', job_id)
|
||||
for uploaded_file in uploaded_files:
|
||||
filename = uploaded_file.name
|
||||
saved_path = safe_join(upload_file_dir, f'{filename}')
|
||||
|
|
|
@ -58,7 +58,7 @@ class JMSPermedInventory(JMSInventory):
|
|||
self.module = module
|
||||
self.assets_accounts_mapper = self.get_assets_accounts_mapper()
|
||||
|
||||
def make_account_vars(self, host, asset, account, automation, protocol, platform, gateway):
|
||||
def make_account_vars(self, host, asset, account, automation, protocol, platform, gateway, path_dir):
|
||||
if not account:
|
||||
host['error'] = _("No account available")
|
||||
return host
|
||||
|
@ -90,7 +90,7 @@ class JMSPermedInventory(JMSInventory):
|
|||
}
|
||||
host['jms_asset']['port'] = protocol.port
|
||||
return host
|
||||
return super().make_account_vars(host, asset, account, automation, protocol, platform, gateway)
|
||||
return super().make_account_vars(host, asset, account, automation, protocol, platform, gateway, path_dir)
|
||||
|
||||
def get_asset_sorted_accounts(self, asset):
|
||||
accounts = self.assets_accounts_mapper.get(asset.id, [])
|
||||
|
@ -347,7 +347,7 @@ class JobExecution(JMSOrgBaseModel):
|
|||
job_id = self.current_job.id
|
||||
args = json.loads(self.current_job.args)
|
||||
dst_path = args.get('dst_path', '/')
|
||||
runner = UploadFileRunner(self.inventory_path, job_id, dst_path)
|
||||
runner = UploadFileRunner(self.inventory_path, self.private_dir, job_id, dst_path)
|
||||
else:
|
||||
raise Exception("unsupported job type")
|
||||
return runner
|
||||
|
|
Loading…
Reference in New Issue