Removed the `relative_key_path` parameter from GCPHandler class because it's unused and has a misleading name.

This commit is contained in:
VakarisZ 2021-05-12 16:33:52 +03:00
parent c45de9dae7
commit 7a03a9504d
1 changed files with 6 additions and 7 deletions

View File

@ -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):
"""