-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added created service method * added function to create new principal * Refactor authentication test methods * fixed precommit issues * add service account from context * Migrate to add 'write:prinicipals' to default admin role. * Apply new "write:principals" scope protection * Docstring clarifications Co-authored-by: Padraic Shafer <[email protected]> * Improve error handling on unknown role. * Use briefer name; rely on namespace to distinguish. * Fix sign of error handling --------- Co-authored-by: Thomas Morris <[email protected]> Co-authored-by: Dan Allan <[email protected]> Co-authored-by: Padraic Shafer <[email protected]> Co-authored-by: Dan Allan <[email protected]>
- Loading branch information
1 parent
5984ad1
commit 62b48d9
Showing
7 changed files
with
172 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 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
47 changes: 47 additions & 0 deletions
47
tiled/authn_database/migrations/versions/769180ce732e_add_write_principals_scope_to_admin.py
This file contains 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,47 @@ | ||
"""Add 'write:principals' scope to admin | ||
Revision ID: 769180ce732e | ||
Revises: c7bd2573716d | ||
Create Date: 2023-12-12 17:57:56.388145 | ||
""" | ||
from alembic import op | ||
from sqlalchemy.orm.session import Session | ||
|
||
from tiled.authn_database.orm import Role | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "769180ce732e" | ||
down_revision = "c7bd2573716d" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
SCOPE = "write:principals" | ||
|
||
|
||
def upgrade(): | ||
""" | ||
Add 'write:principals' scope to default 'admin' Role. | ||
""" | ||
connection = op.get_bind() | ||
with Session(bind=connection) as db: | ||
role = db.query(Role).filter(Role.name == "admin").first() | ||
scopes = role.scopes.copy() | ||
scopes.append(SCOPE) | ||
role.scopes = scopes | ||
db.commit() | ||
|
||
|
||
def downgrade(): | ||
""" | ||
Remove new scopes from Roles, if present. | ||
""" | ||
connection = op.get_bind() | ||
with Session(bind=connection) as db: | ||
role = db.query(Role).filter(Role.name == "admin").first() | ||
scopes = role.scopes.copy() | ||
if SCOPE in scopes: | ||
scopes.remove(SCOPE) | ||
role.scopes = scopes | ||
db.commit() |
This file contains 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 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 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 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