From 3a5e6bad645ca8d3d20f3187069cd6e66515e850 Mon Sep 17 00:00:00 2001 From: NeilSmithDLS Date: Mon, 27 Apr 2026 09:18:55 +0100 Subject: [PATCH 1/4] fix: create blueapi cache folder on login --- src/blueapi/service/authentication.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/blueapi/service/authentication.py b/src/blueapi/service/authentication.py index c0a32b26f4..488fdf26c1 100644 --- a/src/blueapi/service/authentication.py +++ b/src/blueapi/service/authentication.py @@ -52,6 +52,8 @@ def save_cache(self, cache: Cache) -> None: os.chmod(self._file_path, 0o600) def load_cache(self) -> Cache: + Path(self._file_path).mkdir(parents=True, exist_ok=True) + os.chmod(self._file_path, 0o600) with open(self._file_path, "rb") as cache_file: return TypeAdapter(Cache).validate_json( base64.b64decode(cache_file.read()).decode("utf-8") From 99955a7c4483ed8536da946319f38b61df177127 Mon Sep 17 00:00:00 2001 From: NeilSmithDLS Date: Thu, 30 Apr 2026 09:36:38 +0100 Subject: [PATCH 2/4] creating folder correctly --- src/blueapi/service/authentication.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/blueapi/service/authentication.py b/src/blueapi/service/authentication.py index 488fdf26c1..d5e7747b6e 100644 --- a/src/blueapi/service/authentication.py +++ b/src/blueapi/service/authentication.py @@ -47,13 +47,13 @@ def _file_path(self) -> str: def save_cache(self, cache: Cache) -> None: self.delete_cache() + self._create_parent_folder_if_necessary() with open(self._file_path, "xb") as token_file: token_file.write(base64.b64encode(cache.model_dump_json().encode("utf-8"))) os.chmod(self._file_path, 0o600) def load_cache(self) -> Cache: - Path(self._file_path).mkdir(parents=True, exist_ok=True) - os.chmod(self._file_path, 0o600) + self._create_parent_folder_if_necessary() with open(self._file_path, "rb") as cache_file: return TypeAdapter(Cache).validate_json( base64.b64decode(cache_file.read()).decode("utf-8") @@ -73,6 +73,7 @@ def _default_token_cache_path() -> Path: def can_access_cache(self) -> bool: assert self._token_path try: + self._create_parent_folder_if_necessary() self._token_path.write_text("") except IsADirectoryError: print("Invalid path: a directory path was provided instead of a file path") @@ -82,6 +83,9 @@ def can_access_cache(self) -> bool: return False return True + def _create_parent_folder_if_necessary(self): + Path(self._token_path.parent).mkdir(mode=0o777, parents=True, exist_ok=True) + class SessionManager: def __init__(self, server_config: OIDCConfig, cache_manager: CacheManager) -> None: From e31add20ce8e01f999fc6ae9d3a76bed3e24d5e6 Mon Sep 17 00:00:00 2001 From: NeilSmithDLS Date: Thu, 30 Apr 2026 12:46:32 +0100 Subject: [PATCH 3/4] removing mode as using default --- src/blueapi/service/authentication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blueapi/service/authentication.py b/src/blueapi/service/authentication.py index d5e7747b6e..e21efeb2f2 100644 --- a/src/blueapi/service/authentication.py +++ b/src/blueapi/service/authentication.py @@ -84,7 +84,7 @@ def can_access_cache(self) -> bool: return True def _create_parent_folder_if_necessary(self): - Path(self._token_path.parent).mkdir(mode=0o777, parents=True, exist_ok=True) + Path(self._token_path.parent).mkdir(parents=True, exist_ok=True) class SessionManager: From d4b4d286fae2d415646b93d93131401535beebd5 Mon Sep 17 00:00:00 2001 From: NeilSmithDLS <118457264+NeilSmithDLS@users.noreply.github.com> Date: Wed, 6 May 2026 13:59:48 +0100 Subject: [PATCH 4/4] Update src/blueapi/service/authentication.py Co-authored-by: Peter Holloway --- src/blueapi/service/authentication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blueapi/service/authentication.py b/src/blueapi/service/authentication.py index e21efeb2f2..b107f7b2b2 100644 --- a/src/blueapi/service/authentication.py +++ b/src/blueapi/service/authentication.py @@ -84,7 +84,7 @@ def can_access_cache(self) -> bool: return True def _create_parent_folder_if_necessary(self): - Path(self._token_path.parent).mkdir(parents=True, exist_ok=True) + self._token_path.parent.mkdir(parents=True, exist_ok=True) class SessionManager: