Skip to content

Commit f347dde

Browse files
fix case where the storage provider did not encapsulate access to storage. (#16)
Co-authored-by: Carl Alexander Adams <[email protected]>
1 parent a2f593c commit f347dde

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/planet_auth/storage_utils.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ def obj_exists(self, key: ObjectStorageProvider_KeyType) -> bool:
6363
Check whether a given object exists in storage.
6464
"""
6565

66+
@abstractmethod
67+
def mtime(self, key: ObjectStorageProvider_KeyType) -> float:
68+
"""
69+
Return the last modified time in seconds since the epoc for the object.
70+
If the object does not exist, an exception should be raised.
71+
"""
72+
6673
@abstractmethod
6774
def obj_rename(self, src: ObjectStorageProvider_KeyType, dst: ObjectStorageProvider_KeyType) -> None:
6875
"""
@@ -181,6 +188,10 @@ def obj_exists(self, key: ObjectStorageProvider_KeyType) -> bool:
181188
obj_filepath = self._obj_filepath(key)
182189
return obj_filepath.exists()
183190

191+
def mtime(self, key: ObjectStorageProvider_KeyType) -> float:
192+
obj_filepath = self._obj_filepath(key)
193+
return obj_filepath.stat().st_mtime
194+
184195
def obj_rename(self, src: ObjectStorageProvider_KeyType, dst: ObjectStorageProvider_KeyType) -> None:
185196
src_filepath = self._obj_filepath(src)
186197
dst_filepath = self._obj_filepath(dst)
@@ -493,7 +504,7 @@ def lazy_reload(self):
493504
# Have data. No path. Continue with in memory value.
494505
return
495506

496-
if int(self._file_path.stat().st_mtime) > self._load_time:
507+
if self._object_storage_provider.mtime(self._file_path) > self._load_time:
497508
self.load()
498509

499510
def lazy_get(self, field):

tests/test_planet_auth/unit/auth/util.py

+4
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,10 @@ def save_obj(self, key: ObjectStorageProvider_KeyType, data: dict) -> None:
455455
def obj_exists(self, key: ObjectStorageProvider_KeyType) -> bool:
456456
return key in self._mock_storage
457457

458+
def mtime(self, key: ObjectStorageProvider_KeyType) -> float:
459+
# Fake storage provider. We don't know when objects were last modified.
460+
return 0.0
461+
458462
def obj_rename(self, src: ObjectStorageProvider_KeyType, dst: ObjectStorageProvider_KeyType) -> None:
459463
if self._mock_storage[src] is not None:
460464
self._mock_storage[dst] = self._mock_storage[src]

0 commit comments

Comments
 (0)