-
Notifications
You must be signed in to change notification settings - Fork 1
chore: add configurable expiry for management API tokens #403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dan2k3k4
wants to merge
10
commits into
dev
Choose a base branch
from
add-expiry-for-api-management-tokens
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+540
−103
Open
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dd3bcd6
chore: add expiry for management api tokens
dan2k3k4 47ea0c7
chore: address PR review feedback for api token expiry feature
Copilot 9c6c853
chore: use idiomatic SQLAlchemy boolean filter for is_active
Copilot 1ebd7bc
Update app/api/auth.py
dan2k3k4 6799b8e
chore: fix
dan2k3k4 69b9881
chore: fix
dan2k3k4 c3b59a4
fix: use logger and re-raise exception in init_api_token_expiry_options
Copilot 58592af
Merge branch 'dev' into add-expiry-for-api-management-tokens
dan2k3k4 fba686f
style: Format code for improved readability and consistency
dspachos f712daf
Update app/db/models.py
dan2k3k4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
app/migrations/versions/20260408_125946_daf5bf0b03c2_add_api_token_expiry_options.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| """add_api_token_expiry_options | ||
|
|
||
| Revision ID: daf5bf0b03c2 | ||
| Revises: a1b2c3d4e5f6 | ||
| Create Date: 2026-04-08 12:59:46.600703+00:00 | ||
|
|
||
| """ | ||
|
|
||
| from typing import Sequence, Union | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "daf5bf0b03c2" | ||
|
dan2k3k4 marked this conversation as resolved.
Dismissed
|
||
| down_revision: Union[str, None] = "a1b2c3d4e5f6" | ||
|
dan2k3k4 marked this conversation as resolved.
Dismissed
|
||
| branch_labels: Union[str, Sequence[str], None] = None | ||
|
dan2k3k4 marked this conversation as resolved.
Dismissed
|
||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
dan2k3k4 marked this conversation as resolved.
Dismissed
|
||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| # Create api_token_expiry_options table | ||
| op.create_table( | ||
| "api_token_expiry_options", | ||
| sa.Column("id", sa.Integer(), nullable=False), | ||
| sa.Column("name", sa.String(), nullable=False), | ||
| sa.Column("slug", sa.String(), nullable=False), | ||
| sa.Column("days", sa.Integer(), nullable=True), | ||
| sa.Column("is_active", sa.Boolean(), nullable=False, server_default=sa.true()), | ||
| sa.PrimaryKeyConstraint("id"), | ||
| ) | ||
| op.create_index( | ||
|
dan2k3k4 marked this conversation as resolved.
|
||
| op.f("ix_api_token_expiry_options_id"), | ||
| "api_token_expiry_options", | ||
| ["id"], | ||
| unique=False, | ||
| ) | ||
| op.create_index( | ||
| op.f("ix_api_token_expiry_options_slug"), | ||
| "api_token_expiry_options", | ||
| ["slug"], | ||
| unique=True, | ||
| ) | ||
|
|
||
| # Seed default expiry options so the API is usable immediately after migration | ||
| expiry_options_table = sa.table( | ||
| "api_token_expiry_options", | ||
| sa.column("name", sa.String()), | ||
| sa.column("slug", sa.String()), | ||
| sa.column("days", sa.Integer()), | ||
| sa.column("is_active", sa.Boolean()), | ||
| ) | ||
| op.bulk_insert( | ||
| expiry_options_table, | ||
| [ | ||
| {"name": "1 day", "slug": "1_day", "days": 1, "is_active": True}, | ||
| {"name": "1 week", "slug": "1_week", "days": 7, "is_active": True}, | ||
| {"name": "1 month", "slug": "1_month", "days": 30, "is_active": True}, | ||
| {"name": "2 months", "slug": "2_months", "days": 60, "is_active": True}, | ||
| {"name": "3 months", "slug": "3_months", "days": 90, "is_active": True}, | ||
| {"name": "4 months", "slug": "4_months", "days": 120, "is_active": True}, | ||
| {"name": "5 months", "slug": "5_months", "days": 150, "is_active": True}, | ||
| {"name": "6 months", "slug": "6_months", "days": 180, "is_active": True}, | ||
| {"name": "7 months", "slug": "7_months", "days": 210, "is_active": True}, | ||
| {"name": "8 months", "slug": "8_months", "days": 240, "is_active": True}, | ||
| {"name": "9 months", "slug": "9_months", "days": 270, "is_active": True}, | ||
| {"name": "10 months", "slug": "10_months", "days": 300, "is_active": True}, | ||
| {"name": "11 months", "slug": "11_months", "days": 330, "is_active": True}, | ||
| {"name": "1 year", "slug": "1_year", "days": 365, "is_active": True}, | ||
| {"name": "forever", "slug": "forever", "days": None, "is_active": True}, | ||
| ], | ||
| ) | ||
|
|
||
| # Update api_tokens table - these might already exist in some environments but let's ensure they are there | ||
| # Check if columns exist first to be safe | ||
| conn = op.get_bind() | ||
| inspector = sa.inspect(conn) | ||
| columns = [c["name"] for c in inspector.get_columns("api_tokens")] | ||
|
|
||
| if "expires_at" not in columns: | ||
| op.add_column( | ||
| "api_tokens", | ||
| sa.Column("expires_at", sa.DateTime(timezone=True), nullable=True), | ||
| ) | ||
| if "expiry_option" not in columns: | ||
| op.add_column( | ||
| "api_tokens", | ||
| sa.Column( | ||
| "expiry_option", sa.String(), nullable=False, server_default="forever" | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| conn = op.get_bind() | ||
| inspector = sa.inspect(conn) | ||
| columns = [c["name"] for c in inspector.get_columns("api_tokens")] | ||
|
|
||
| if "expiry_option" in columns: | ||
| op.drop_column("api_tokens", "expiry_option") | ||
| if "expires_at" in columns: | ||
| op.drop_column("api_tokens", "expires_at") | ||
| op.drop_index( | ||
| op.f("ix_api_token_expiry_options_slug"), table_name="api_token_expiry_options" | ||
| ) | ||
| op.drop_index( | ||
| op.f("ix_api_token_expiry_options_id"), table_name="api_token_expiry_options" | ||
| ) | ||
| op.drop_table("api_token_expiry_options") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.