mirror of
https://github.com/GAM-team/GAM.git
synced 2026-06-28 18:01:36 +00:00
file locking for oauth2.txt
This commit is contained in:
12
src/gam.py
12
src/gam.py
@@ -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()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
python-dateutil
|
||||
distro; sys_platform == 'linux'
|
||||
filelock
|
||||
google-api-python-client>=1.7.10
|
||||
google-auth
|
||||
google-auth-httplib2
|
||||
|
||||
Reference in New Issue
Block a user