From 7a03a9504dc3cf42a8e942c51ba234a674423d08 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Wed, 12 May 2021 16:33:52 +0300 Subject: [PATCH] Removed the `relative_key_path` parameter from GCPHandler class because it's unused and has a misleading name. --- .../blackbox/utils/gcp_machine_handlers.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/envs/monkey_zoo/blackbox/utils/gcp_machine_handlers.py b/envs/monkey_zoo/blackbox/utils/gcp_machine_handlers.py index 89018bde1..dd72112ba 100644 --- a/envs/monkey_zoo/blackbox/utils/gcp_machine_handlers.py +++ b/envs/monkey_zoo/blackbox/utils/gcp_machine_handlers.py @@ -12,18 +12,17 @@ class GCPHandler(object): MACHINE_STOPPING_COMMAND = "gcloud compute instances stop %s --zone=%s" # Key path location relative to this file - DEFAULT_RELATIVE_KEY_PATH = "../../gcp_keys/gcp_key.json" + RELATIVE_KEY_PATH = "../../gcp_keys/gcp_key.json" DEFAULT_ZONE = "europe-west3-a" DEFAULT_PROJECT = "guardicore-22050661" def __init__( self, - relative_key_path=DEFAULT_RELATIVE_KEY_PATH, zone=DEFAULT_ZONE, project_id=DEFAULT_PROJECT, ): self.zone = zone - abs_key_path = GCPHandler.get_absolute_key_path(relative_key_path) + abs_key_path = GCPHandler.get_absolute_key_path() subprocess.call(GCPHandler.get_auth_command(abs_key_path), shell=True) # noqa: DUO116 LOGGER.info("GCP Handler passed key") @@ -33,15 +32,15 @@ class GCPHandler(object): LOGGER.info("GCP Handler initialized successfully") @staticmethod - def get_absolute_key_path(relative_key_path: str) -> str: - file_dir = os.path.dirname(os.path.realpath(__file__)) - absolute_key_path = os.path.join(file_dir, relative_key_path) + def get_absolute_key_path() -> str: + absolute_key_path = os.path.join(__file__, GCPHandler.RELATIVE_KEY_PATH) + absolute_key_path = os.path.realpath(absolute_key_path) if not os.path.isfile(absolute_key_path): raise FileNotFoundError( "GCP key not found. " "Add a service key to envs/monkey_zoo/gcp_keys/gcp_key.json" ) - return os.path.normpath(absolute_key_path) + return absolute_key_path def start_machines(self, machine_list): """