Skip to content

Commit 73654f4

Browse files
committed
Simplify store_oauth2_credentials
1 parent 61a3f63 commit 73654f4

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

src/gmv/credential_utils.py

+2-13
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,15 @@ def store_oauth2_credentials(cls, email, access_token, refresh_token, validity,
112112
"""
113113
oauth_file = '%s/%s.oauth2' % (gmvault_utils.get_home_dir_path(), email)
114114

115-
# Open a file
116-
fdesc = os.open(oauth_file, os.O_RDWR|os.O_CREAT )
117-
118-
#write new content
119-
fobj = os.fdopen(fdesc, "w")
120-
121-
#empty file
122-
fobj.truncate()
123-
fobj.seek(0, os.SEEK_SET)
124-
125-
126115
the_obj = { "access_token" : access_token,
127116
"refresh_token" : refresh_token,
128117
"validity" : validity,
129118
"access_creation" : gmvault_utils.get_utcnow_epoch(),
130119
"type" : type}
131120

132-
json.dump(the_obj, fobj)
121+
with open(oauth_file, 'w') as f:
122+
json.dump(the_obj, f)
133123

134-
fobj.close()
135124

136125
@classmethod
137126
def read_oauth2_tok_sec(cls, email):

0 commit comments

Comments
 (0)