Skip to content
This repository was archived by the owner on Apr 20, 2022. It is now read-only.

Commit ee225ff

Browse files
committed
fix java agent download bug
1 parent 76662bf commit ee225ff

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

apiserver/views/agent_download.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ def __init__(self, user_id):
3333
self.agent_file = "iast-agent.jar"
3434
self.original_agent_path = f'/tmp/iast_cache/package'
3535
self.original_agent_file = f'/tmp/iast_cache/package/{self.agent_file}'
36-
self.target_path = f'/tmp/{os.getpid()}-{t.ident}-{user_id}'
36+
self.user_target_path = f'/tmp/{os.getpid()}-{t.ident}-{user_id}'
37+
self.target_path = f'/tmp/{os.getpid()}-{t.ident}-{user_id}/iast_cache/package'
3738
self.remote_agent_file = BUCKET_NAME_BASE_URL + 'java/iast-agent.jar'
38-
if not os.path.exists(f"{self.target_path}/iast_cache/package"):
39-
os.makedirs(f"{self.target_path}/iast_cache/package")
39+
if not os.path.exists(f"{self.target_path}"):
40+
os.makedirs(f"{self.target_path}")
4041
if not os.path.exists(self.original_agent_path):
4142
os.makedirs(self.original_agent_path)
4243

@@ -50,12 +51,12 @@ def download_agent(self):
5051

5152
def create_config(self, base_url, agent_token, auth_token, project_name):
5253
try:
53-
user_file = f"{self.target_path}/iast_cache/package/{self.agent_file}"
54+
user_file = f"{self.target_path}/{self.agent_file}"
5455
if not os.path.exists(user_file):
5556
shutil.copyfile(self.original_agent_file, user_file)
5657

5758
data = "iast.response.name=DongTai Iast\niast.server.url={url}\niast.server.token={token}\niast.allhook.enable=false\niast.dump.class.enable=false\niast.dump.class.path=/tmp/iast-class-dump/\niast.service.report.interval=30000\napp.name=DongTai\nengine.status=start\nengine.name={agent_token}\njdk.version={jdk_level}\nproject.name={project_name}\niast.proxy.enable=false\niast.proxy.host=\niast.proxy.port=\niast.server.mode=local\n"
58-
with open(f'{self.target_path}/iast.properties', 'w') as config_file:
59+
with open(f'{self.user_target_path}/iast.properties', 'w') as config_file:
5960
config_file.write(
6061
data.format(url=base_url, token=auth_token, agent_token=agent_token, jdk_level=1,
6162
project_name=project_name)
@@ -66,10 +67,10 @@ def create_config(self, base_url, agent_token, auth_token, project_name):
6667
return False
6768

6869
def replace_config(self):
69-
user_file = f"{self.target_path}/iast_cache/package/{self.agent_file}"
70+
user_file = f"{self.target_path}/{self.agent_file}"
7071
# 执行jar -uvf {JavaAgentDownload.LOCAL_AGENT_FILE} iast.properties更新jar包的文件
7172
import os
72-
os.system(f'cd {self.target_path};jar -uvf {user_file} iast.properties')
73+
os.system(f'cd {self.user_target_path};jar -uvf {user_file} iast.properties')
7374

7475

7576
class PythonAgentDownload():

0 commit comments

Comments
 (0)