check owner of vm after ensuring that vm exists

This commit is contained in:
ahmadbilalkhalid 2019-07-20 15:19:39 +05:00
parent cdf3c741ee
commit 715128a138

View file

@ -196,9 +196,9 @@ class StartVM(Resource):
if check_otp(name, realm, token) == 200:
vm = client.get(f"/v1/vm/{vm_uuid}", value_in_json=True)
if vm:
if vm.value["owner"] != name:
return {"message": "Invalid User"}
if vm:
vm.value["status"] = "REQUESTED_START"
client.put(vm.key, json.dumps(vm.value))
return {"message": f"VM Start Queued"}
@ -215,9 +215,9 @@ class SuspendVM(Resource):
if check_otp(name, realm, token) == 200:
vm = client.get(f"/v1/vm/{vm_uuid}", value_in_json=True)
if vm:
if vm.value["owner"] != name:
return {"message": "Invalid User"}
if vm:
vm.value["status"] = "REQUESTED_SUSPEND"
client.put(vm.key, json.dumps(vm.value))
return {"message": f"VM Suspension Queued"}
@ -234,9 +234,9 @@ class ResumeVM(Resource):
if check_otp(name, realm, token) == 200:
vm = client.get(f"/v1/vm/{vm_uuid}", value_in_json=True)
if vm:
if vm.value["owner"] != name:
return {"message": "Invalid User"}
if vm:
vm.value["status"] = "REQUESTED_RESUME"
client.put(vm.key, json.dumps(vm.value))
return {"message": f"VM Resume Queued"}
@ -253,10 +253,10 @@ class ShutdownVM(Resource):
if check_otp(name, realm, token) == 200:
vm = client.get(f"/v1/vm/{vm_uuid}", value_in_json=True)
if vm:
if vm.value["owner"] != name:
return {"message": "Invalid User"}
if vm:
vm.value["status"] = "REQUESTED_SHUTDOWN"
client.put(vm.key, json.dumps(vm.value))
return {"message": f"VM Shutdown Queued"}