diff --git a/src/gam/__init__.py b/src/gam/__init__.py index e0e8de38..ebb89d81 100755 --- a/src/gam/__init__.py +++ b/src/gam/__init__.py @@ -1086,9 +1086,10 @@ def getService(api, httpObj): controlflow.invalid_json_exit(disc_file) -def buildGAPIObject(api): +def buildGAPIObject(api, credentials=None): GM_Globals[GM_CURRENT_API_USER] = None - credentials = getValidOauth2TxtCredentials(api=getAPIVersion(api)[0]) + if not credentials: + credentials = getValidOauth2TxtCredentials(api=getAPIVersion(api)[0]) credentials.user_agent = GAM_INFO httpObj = transport.AuthorizedHttp( credentials, transport.create_http(cache=GM_Globals[GM_CACHE_DIR])) diff --git a/src/gam/auth/signjwt.py b/src/gam/auth/signjwt.py index cb324f32..cde0142e 100644 --- a/src/gam/auth/signjwt.py +++ b/src/gam/auth/signjwt.py @@ -5,10 +5,12 @@ import json import google.auth from google.auth._helpers import datetime_to_secs, scopes_to_string, utcnow import google.oauth2.service_account -from googleapiclient.discovery import build +import gam from gam import controlflow from gam import gapi +from gam import transport +from gam.var import GM_Globals, GM_CACHE_DIR _DEFAULT_TOKEN_LIFETIME_SECS = 3600 # 1 hour in seconds _GOOGLE_OAUTH2_TOKEN_ENDPOINT = "https://oauth2.googleapis.com/token" @@ -75,7 +77,10 @@ class SignJwt(google.auth.crypt.Signer): credentials, _ = google.auth.default() except google.auth.exceptions.DefaultCredentialsError as e: controlflow.system_error_exit(2, e) - iamc = build('iamcredentials', 'v1', credentials=credentials) + httpObj = transport.AuthorizedHttp( + credentials, + transport.create_http(cache=GM_Globals[GM_CACHE_DIR])) + iamc = gam.getService('iamcredentials', httpObj) response = gapi.call(iamc.projects().serviceAccounts(), 'signJwt', name=self.name,