Skip to content

Commit 19ea5dc

Browse files
committed
fix(vefaas): fix request app_id and app_name
1 parent 4780e78 commit 19ea5dc

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

veadk/integrations/ve_faas/ve_faas.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,25 @@ def _get_application_status(self, app_id: str):
219219
)
220220
return response["Result"]["Status"], response
221221

222-
def _list_application(self, app_name: str = None):
222+
def _list_application(self, app_id: str = None, app_name: str = None):
223+
# firt match app_id. if app_id is None,then match app_name and remove app_id
224+
request_body = {
225+
"OrderBy": {"Key": "CreateTime", "Ascend": False},
226+
"FunctionId": app_id if app_id else None,
227+
"Filters": [{"Item": {"Key": "Name", "Value": [app_name]}}]
228+
if app_name and not app_id
229+
else None,
230+
}
231+
# remove None
232+
request_body = {k: v for k, v in request_body.items() if v is not None}
233+
223234
page_size = 50
224235
page_number = 1
225236
all_items = []
226237
total_page = None
227238
while True:
228239
try:
229-
request_body = {
230-
"PageNumber": page_number,
231-
"PageSize": page_size,
232-
"Filters": [{"Item": {"Key": "Name", "Value": [app_name]}}],
233-
"OrderBy": {"Key": "CreateTime", "Ascend": False},
234-
}
240+
request_body.update({"PageNumber": page_number, "PageSize": page_size})
235241
response = ve_request(
236242
request_body=request_body,
237243
action="ListApplications",
@@ -255,7 +261,7 @@ def _list_application(self, app_name: str = None):
255261
page_number += 1
256262
except Exception as e:
257263
raise ValueError(
258-
f"List application failed. Response: {response}. Error: {str(e)}"
264+
f"List application failed. Error: {str(e)}. Response: {response}."
259265
)
260266
return all_items
261267

@@ -333,7 +339,7 @@ def _update_function_code(
333339
def get_application_details(self, app_id: str = None, app_name: str = None):
334340
if not app_id and not app_name:
335341
raise ValueError("app_id and app_name cannot be both empty.")
336-
apps = self._list_application(app_name=app_name)
342+
apps = self._list_application(app_id=app_id, app_name=app_name)
337343
if app_id:
338344
for app in apps:
339345
if app["Id"] == app_id:

0 commit comments

Comments
 (0)