@@ -29,6 +29,23 @@ def _maybe_nfs_exception(exception):
2929 )
3030
3131
32+ def get_token_dir ():
33+ return os .path .join (os .path .expanduser ("~" ), ".sumo" )
34+
35+
36+ def get_token_path (resource_id , suffix , case_uuid = None ):
37+ if case_uuid is not None :
38+ return os .path .join (
39+ os .path .expanduser ("~" ),
40+ ".sumo" ,
41+ str (resource_id ) + "+" + str (case_uuid ) + suffix ,
42+ )
43+ else :
44+ return os .path .join (
45+ os .path .expanduser ("~" ), ".sumo" , str (resource_id ) + suffix
46+ )
47+
48+
3249class AuthProvider :
3350 def __init__ (self , resource_id ):
3451 self ._resource_id = resource_id
@@ -67,11 +84,13 @@ def get_authorization(self):
6784 return {"Authorization" : "Bearer " + token }
6885
6986 def store_shared_access_key_for_case (self , case_uuid , token ):
87+ os .makedirs (get_token_dir (), mode = 0o700 , exist_ok = True )
7088 with open (
7189 get_token_path (self ._resource_id , ".sharedkey" , case_uuid ),
7290 "w" ,
7391 ) as f :
7492 f .write (token )
93+ protect_token_cache (self ._resource_id , ".sharedkey" , case_uuid )
7594
7695 pass
7796
@@ -118,19 +137,6 @@ def __init__(self, refresh_token, client_id, authority, resource_id):
118137 pass
119138
120139
121- def get_token_path (resource_id , suffix , case_uuid = None ):
122- if case_uuid is not None :
123- return os .path .join (
124- os .path .expanduser ("~" ),
125- ".sumo" ,
126- str (resource_id ) + "+" + str (case_uuid ) + suffix ,
127- )
128- else :
129- return os .path .join (
130- os .path .expanduser ("~" ), ".sumo" , str (resource_id ) + suffix
131- )
132-
133-
134140@tn .retry (
135141 retry = tn .retry_if_exception (_maybe_nfs_exception ),
136142 stop = tn .stop_after_attempt (6 ),
0 commit comments