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

fix ls path validation #179

Merged
merged 1 commit into from
Jun 26, 2017
Merged
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
19 changes: 10 additions & 9 deletions paddlecloud/paddlejob/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,16 +374,17 @@ def get(self, request, format=None):
# validate list path must be under user's dir
path_parts = file_path.split(os.path.sep)
msg = ""
if len(path_parts) <= 1:
msg = "path must start with /pfs"
if len(path_parts) >= 2 and path_parts[1] != "pfs":
msg = "path must start with /pfs"
if len(path_parts) >= 3 and path_parts[2] not in settings.DATACENTERS.keys():
msg = "no datacenter "+path_parts[2]
if len(path_parts) >= 4 and path_parts[3] != "home":
msg = "path must like /pfs/[dc]/home/[user]"
if len(path_parts) >= 5 and path_parts[4] != request.user.username:
if len(path_parts) < 5:
msg = "path must like /pfs/[dc]/home/[user]"
else:
if path_parts[1] != "pfs":
msg = "path must start with /pfs"
if path_parts[2] not in settings.DATACENTERS.keys():
msg = "no datacenter "+path_parts[2]
if path_parts[3] != "home":
msg = "path must like /pfs/[dc]/home/[user]"
if path_parts[4] != request.user.username:
msg = "not a valid user: " + path_parts[4]
if msg:
return Response({"msg": msg})

Expand Down