From 715128a138a5db9129e6a9693a80f24bae7ce768 Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Khalid Date: Sat, 20 Jul 2019 15:19:39 +0500 Subject: [PATCH] check owner of vm after ensuring that vm exists --- main.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index f9dbdde..b4a9043 100644 --- a/main.py +++ b/main.py @@ -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.value["owner"] != name: - return {"message": "Invalid User"} if vm: + if vm.value["owner"] != name: + return {"message": "Invalid User"} 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.value["owner"] != name: - return {"message": "Invalid User"} if vm: + if vm.value["owner"] != name: + return {"message": "Invalid User"} 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.value["owner"] != name: - return {"message": "Invalid User"} if vm: + if vm.value["owner"] != name: + return {"message": "Invalid User"} 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.value["owner"] != name: - return {"message": "Invalid User"} - if vm: + if vm.value["owner"] != name: + return {"message": "Invalid User"} + vm.value["status"] = "REQUESTED_SHUTDOWN" client.put(vm.key, json.dumps(vm.value)) return {"message": f"VM Shutdown Queued"}