From 1f4b2dae58079936b97b1763732f35000bc06248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20M=C3=A9ndez=20Hern=C3=A1ndez?= Date: Fri, 4 Oct 2024 17:51:36 +0200 Subject: [PATCH 1/2] Do not fail GCP auth when GOOGLE_APPLICATION_CREDENTIALS is not found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Auth could have been set up using the Google Cloud CLI: - `gcloud init` - `gcloud auth application-default login` Signed-off-by: Pablo Méndez Hernández --- krkn/scenario_plugins/node_actions/gcp_node_scenarios.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/krkn/scenario_plugins/node_actions/gcp_node_scenarios.py b/krkn/scenario_plugins/node_actions/gcp_node_scenarios.py index 437a9181..b5d76f70 100644 --- a/krkn/scenario_plugins/node_actions/gcp_node_scenarios.py +++ b/krkn/scenario_plugins/node_actions/gcp_node_scenarios.py @@ -14,13 +14,15 @@ class GCP: def __init__(self): - try: + if "GOOGLE_APPLICATION_CREDENTIALS" in os.environ: gapp_creds = os.getenv("GOOGLE_APPLICATION_CREDENTIALS") with open(gapp_creds, "r") as f: f_str = f.read() self.project = json.loads(f_str)["project_id"] # self.project = runcommand.invoke("gcloud config get-value project").split("/n")[0].strip() logging.info("project " + str(self.project) + "!") + + try: credentials = GoogleCredentials.get_application_default() self.client = discovery.build( "compute", "v1", credentials=credentials, cache_discovery=False From 1e9f08c71121b52217d8300c1921d3ea57a1b816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20M=C3=A9ndez=20Hern=C3=A1ndez?= Date: Mon, 7 Oct 2024 18:00:30 +0200 Subject: [PATCH 2/2] Remove commented-out leftover code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pablo Méndez Hernández --- krkn/scenario_plugins/node_actions/gcp_node_scenarios.py | 1 - 1 file changed, 1 deletion(-) diff --git a/krkn/scenario_plugins/node_actions/gcp_node_scenarios.py b/krkn/scenario_plugins/node_actions/gcp_node_scenarios.py index b5d76f70..310ee79e 100644 --- a/krkn/scenario_plugins/node_actions/gcp_node_scenarios.py +++ b/krkn/scenario_plugins/node_actions/gcp_node_scenarios.py @@ -19,7 +19,6 @@ def __init__(self): with open(gapp_creds, "r") as f: f_str = f.read() self.project = json.loads(f_str)["project_id"] - # self.project = runcommand.invoke("gcloud config get-value project").split("/n")[0].strip() logging.info("project " + str(self.project) + "!") try: