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

Commit 7eb7ad5

Browse files
authored
Merge pull request #191 from Bidaya0/feature/issue-190
#190 add go agent download
2 parents ae38e90 + a1d7d4c commit 7eb7ad5

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

apiserver/views/agent_download.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,35 @@ def replace_config(self):
215215
logger.error(f'replace config error: {e}')
216216
return False
217217

218+
class GoAgentDownload():
219+
220+
def __init__(self, user_id):
221+
t = threading.currentThread()
222+
self.user_id = user_id
223+
self.agent_file = "dongtai-go-agent-config.yaml"
224+
self.original_agent_file = f'/tmp/{self.agent_file}'
225+
self.target_path = f'/tmp/{os.getpid()}-{t.ident}-{user_id}'
226+
self.target_source_path = f'/tmp/{os.getpid()}-{t.ident}-{user_id}/php-agent'
227+
self.remote_agent_file = BUCKET_NAME_BASE_URL + 'php/php-agent.tar.gz'
228+
if not os.path.exists(self.target_path):
229+
os.makedirs(self.target_path)
230+
if not os.path.exists(self.target_source_path):
231+
os.makedirs(self.target_source_path)
232+
233+
def download_agent(self):
234+
return True
235+
236+
def create_config(self, base_url, agent_token, auth_token, project_name):
237+
with open(f"{self.target_path}/{self.agent_file}", "w") as fp:
238+
configs = [
239+
f'DongtaiGoOpenapi: "{base_url}"',
240+
f'DongtaiGoToken: "{auth_token}"'
241+
]
242+
fp.writelines([config + "\n" for config in configs])
243+
return True
244+
def replace_config(self):
245+
return True
246+
218247

219248
class AgentDownload(OpenApiEndPoint):
220249
"""
@@ -244,6 +273,8 @@ def make_download_handler(self, language, user_id):
244273
return JavaAgentDownload(user_id)
245274
if language == 'php':
246275
return PhpAgentDownload(user_id)
276+
if language == 'go':
277+
return GoAgentDownload(user_id)
247278
return
248279

249280
@extend_schema(
@@ -273,9 +304,11 @@ def get(self, request):
273304
if handler.create_config(base_url=base_url, agent_token=agent_token, auth_token=token.key,
274305
project_name=project_name):
275306
handler.replace_config()
276-
response = FileResponse(open(f"{handler.target_path}/{handler.agent_file}", "rb"))
307+
response = FileResponse(
308+
open(f"{handler.target_path}/{handler.agent_file}", "rb"))
277309
response['content_type'] = 'application/octet-stream'
278-
response['Content-Disposition'] = "attachment; filename=agent.jar"
310+
response[
311+
'Content-Disposition'] = f"attachment; filename={handler.agent_file}"
279312
return response
280313
else:
281314
return R.failure(msg="agent file not exit.")

0 commit comments

Comments
 (0)