fence-agents/fence_gce-google-auth-oauthlib-support.patch

44 lines
1.8 KiB
Diff
Raw Normal View History

From a06a83566e11b0bdf197b16beb022b4cece11d5f Mon Sep 17 00:00:00 2001
From: Oyvind Albrigtsen <oalbrigt@redhat.com>
Date: Wed, 10 Feb 2021 15:37:27 +0100
Subject: [PATCH] fence_gce: support google-auth and oauthlib and fallback to
deprecated libs when not available
oauth2client deprecated info: https://pypi.org/project/oauth2client/
---
agents/gce/fence_gce.py | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/agents/gce/fence_gce.py b/agents/gce/fence_gce.py
index d69acf4e..04318744 100644
--- a/agents/gce/fence_gce.py
+++ b/agents/gce/fence_gce.py
@@ -29,8 +29,12 @@
from fencing import fail_usage, run_delay, all_opt, atexit_handler, check_input, process_input, show_docs, fence_action
try:
import googleapiclient.discovery
- from oauth2client.client import GoogleCredentials
- from oauth2client.service_account import ServiceAccountCredentials
+ try:
+ from google.oauth2.credentials import Credentials as GoogleCredentials
+ from google.oauth2.service_account import Credentials as ServiceAccountCredentials
+ except:
+ from oauth2client.client import GoogleCredentials
+ from oauth2client.service_account import ServiceAccountCredentials
except:
pass
@@ -380,7 +384,11 @@ def main():
credentials = ServiceAccountCredentials.from_json_keyfile_name(options.get("--serviceaccount"))
logging.debug("using credentials from service account")
else:
- credentials = GoogleCredentials.get_application_default()
+ try:
+ from googleapiclient import _auth
+ credentials = _auth.default_credentials();
+ except:
+ credentials = GoogleCredentials.get_application_default()
logging.debug("using application default credentials")
conn = googleapiclient.discovery.build(
'compute', 'v1', credentials=credentials, cache_discovery=False)