@@ -47,13 +47,13 @@ def _file_path(self) -> str:
4747
4848 def save_cache (self , cache : Cache ) -> None :
4949 self .delete_cache ()
50+ self ._create_parent_folder_if_necessary ()
5051 with open (self ._file_path , "xb" ) as token_file :
5152 token_file .write (base64 .b64encode (cache .model_dump_json ().encode ("utf-8" )))
5253 os .chmod (self ._file_path , 0o600 )
5354
5455 def load_cache (self ) -> Cache :
55- Path (self ._file_path ).mkdir (parents = True , exist_ok = True )
56- os .chmod (self ._file_path , 0o600 )
56+ self ._create_parent_folder_if_necessary ()
5757 with open (self ._file_path , "rb" ) as cache_file :
5858 return TypeAdapter (Cache ).validate_json (
5959 base64 .b64decode (cache_file .read ()).decode ("utf-8" )
@@ -73,6 +73,7 @@ def _default_token_cache_path() -> Path:
7373 def can_access_cache (self ) -> bool :
7474 assert self ._token_path
7575 try :
76+ self ._create_parent_folder_if_necessary ()
7677 self ._token_path .write_text ("" )
7778 except IsADirectoryError :
7879 print ("Invalid path: a directory path was provided instead of a file path" )
@@ -82,6 +83,9 @@ def can_access_cache(self) -> bool:
8283 return False
8384 return True
8485
86+ def _create_parent_folder_if_necessary (self ):
87+ Path (self ._token_path .parent ).mkdir (mode = 0o777 , parents = True , exist_ok = True )
88+
8589
8690class SessionManager :
8791 def __init__ (self , server_config : OIDCConfig , cache_manager : CacheManager ) -> None :
0 commit comments