file locking for oauth2.txt

This commit is contained in:
Jay Lee
2019-09-30 16:18:24 -04:00
parent 2d0396da21
commit 1884e1a111
2 changed files with 11 additions and 2 deletions

View File

@@ -28,6 +28,7 @@ import csv
import datetime
import difflib
from email import message_from_string
from filelock import FileLock
import hashlib
import io
import json
@@ -1287,7 +1288,11 @@ def readDiscoveryFile(api_version):
invalidJSONExit(disc_file)
def getOauth2TxtStorageCredentials():
oauth_string = readFile(GC_Values[GC_OAUTH2_TXT], continueOnError=True, displayError=False)
lock_file = '%s.lock' % GC_Values[GC_OAUTH2_TXT]
lock = FileLock(lock_file, timeout=10)
# wait for write before read of oauth2.txt so creds are fresh
with lock:
oauth_string = readFile(GC_Values[GC_OAUTH2_TXT], continueOnError=True, displayError=False)
if not oauth_string:
return
oauth_data = json.loads(oauth_string)
@@ -13417,7 +13422,10 @@ def writeCredentials(creds):
systemErrorExit(13, 'Wrong OAuth 2.0 credentials issuer. Got %s, expected one of %s' % (_getValueFromOAuth('iss', creds), ', '.join(expected_iss)))
creds_data['decoded_id_token'] = GC_Values[GC_DECODED_ID_TOKEN]
data = json.dumps(creds_data, indent=2, sort_keys=True)
writeFile(GC_Values[GC_OAUTH2_TXT], data)
lock_file = '%s.lock' %GC_Values[GC_OAUTH2_TXT]
lock = FileLock(lock_file, timeout=10)
with lock:
writeFile(GC_Values[GC_OAUTH2_TXT], data)
def doRequestOAuth(login_hint=None):
credentials = getOauth2TxtStorageCredentials()

View File

@@ -1,5 +1,6 @@
python-dateutil
distro; sys_platform == 'linux'
filelock
google-api-python-client>=1.7.10
google-auth
google-auth-httplib2