Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add error logging for file upload and download operations #41

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/spaceone/file_manager/interface/rest/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ async def upload_file(self, metadata, params, file) :
file_conn_mgr = FileConnectorManager()
await run_in_threadpool(file_conn_mgr.upload_file, resource_group, file_id, await file.read())
except Exception as e:
_LOGGER.error(f'[upload_file] Error: {e}')
file_svc.delete({"file_id":file_id})
raise ERROR_FILE_UPLOAD_FAILED(name=file_info["name"])

Expand All @@ -188,6 +189,7 @@ async def download_file(self, metadata, params) -> StreamingResponse:
raise ERROR_FILE_DOWNLOAD_FAILED(name=file_info["name"])

except Exception as e:
_LOGGER.error(f'[download_file] Error: {e}')
raise ERROR_FILE_DOWNLOAD_FAILED(name=file_info["name"])


Expand Down
26 changes: 1 addition & 25 deletions src/spaceone/file_manager/service/file_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def delete(self, params: FileDeleteRequest) -> None:
"WORKSPACE_MEMBER",
],
)

@convert_model
def get(self, params: FileGetRequest) -> Union[FileResponse, dict]:
"""Get file
Expand All @@ -194,31 +195,6 @@ def get(self, params: FileGetRequest) -> Union[FileResponse, dict]:
FileResponse:
"""

role_type = self.transaction.get_meta("authorization.role_type")

if role_type == "SYSTEM_ADMIN":
resource_group = "SYSTEM"
elif role_type == "DOMAIN_ADMIN":
resource_group = "DOMAIN"
elif role_type == "WORKSPACE_OWNER" or role_type == "WORKSPACE_MEMBER":
resource_group = "WORKSPACE"
else:
raise ERROR_PERMISSION_DENIED()

if resource_group == "SYSTEM":
params.domain_id = "*"
params.workspace_id = "*"
elif resource_group == "DOMAIN":
params.workspace_id = "*"
elif resource_group == "WORKSPACE" :
self.identity_mgr.check_workspace(params.workspace_id, params.domain_id)
params.project_id = "*"
elif resource_group == "PROJECT":
if not params.project_id:
params.project_id = "*"
else :
self.identity_mgr.get_project(params.project_id, params.domain_id)

file_vo = self.file_mgr.get_file(
params.file_id,
params.domain_id,
Expand Down
Loading