diff --git a/src/gmv/credential_utils.py b/src/gmv/credential_utils.py index b11184b4..ad1633fb 100755 --- a/src/gmv/credential_utils.py +++ b/src/gmv/credential_utils.py @@ -110,11 +110,7 @@ def store_oauth2_credentials(cls, email, access_token, refresh_token, validity, """ store oauth_credentials """ - oauth_file = '%s/%s.oauth2' % (gmvault_utils.get_home_dir_path(), email) - - # Open a file - fdesc = os.open(oauth_file, os.O_RDWR|os.O_CREAT ) - fobj = os.fdopen(fdesc, "w+") + oauth_file_path = '%s/%s.oauth2' % (gmvault_utils.get_home_dir_path(), email) the_obj = { "access_token" : access_token, "refresh_token" : refresh_token, @@ -122,9 +118,8 @@ def store_oauth2_credentials(cls, email, access_token, refresh_token, validity, "access_creation" : gmvault_utils.get_utcnow_epoch(), "type" : type} - json.dump(the_obj, fobj) - - fobj.close() + with open(oauth_file_path, 'w') as oauth_file: + json.dump(the_obj, oauth_file) @classmethod def read_oauth2_tok_sec(cls, email):