Skip to content

Commit

Permalink
Do not fail GCP auth when GOOGLE_APPLICATION_CREDENTIALS is not found
Browse files Browse the repository at this point in the history
Auth could have been set up using the Google Cloud CLI:

- `gcloud init`
- `gcloud auth application-default login`
  • Loading branch information
pablomh authored Oct 4, 2024
1 parent 3c207ab commit de48c49
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion krkn/scenario_plugins/node_actions/gcp_node_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit de48c49

Please sign in to comment.