Skip to content

Commit c6cc817

Browse files
committed
feat(playground): add default expiration date to one year
1 parent f7f103e commit c6cc817

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

playground/app/features/keys/state.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,23 @@ def keys(self) -> list[Key]:
3333
"""Get keys list with correct typing for Reflex."""
3434
return self.entities
3535

36+
def _default_expiry_date(self) -> str:
37+
"""Default expiry date: today + 1 year, capped at the configured maximum if any."""
38+
default = dt.datetime.now() + dt.timedelta(days=365)
39+
if configuration.settings.auth_key_max_expiration_days is not None:
40+
max_date = dt.datetime.now() + dt.timedelta(days=configuration.settings.auth_key_max_expiration_days - 1)
41+
default = min(default, max_date)
42+
return default.strftime("%Y-%m-%d")
43+
3644
@rx.event
3745
async def load_entities(self):
3846
"""Load entities."""
3947
if not self.is_authenticated or not self.api_key:
4048
return
4149

50+
if not self.entity_to_create.expires:
51+
self.entity_to_create.expires = self._default_expiry_date()
52+
4253
self.entities_loading = True
4354
yield
4455

@@ -193,6 +204,9 @@ async def create_entity(self):
193204
self.created_key = data.get("key", "")
194205
self.is_created_dialog_open = True
195206

207+
# Reset the create form, keeping the default 1-year expiry
208+
self.entity_to_create = Key(expires=self._default_expiry_date())
209+
196210
yield rx.toast.success("Key created successfully", position="bottom-right")
197211
async for _ in self.load_entities():
198212
yield

0 commit comments

Comments
 (0)