-
Notifications
You must be signed in to change notification settings - Fork 0
Add: SamAccountType #919
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
Merged
Merged
Add: SamAccountType #919
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c940b24
Add: introduce SamAccountType enum and update related attributes in c…
54a3fda
Fix: add missing commas in sAMAccountType assignments in FIRST_SETUP_…
6b7f15f
Add: set sAMAccountType to SAM_USER_OBJECT in SetupUseCase for user c…
2c16d93
Refactor: rename SamAccountType enum to SamAccountTypeCodes and updat…
b8ef04a
Fix: add missing comma in sAMAccountType assignment in TEST_DATA
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| """Add sAMAccountType to existing user/group/computer entries. | ||
|
|
||
| Revision ID: f4e6cd18a01d | ||
| Revises: 379fce54fb08 | ||
| Create Date: 2026-01-30 13:08:26.299158 | ||
|
|
||
| """ | ||
|
|
||
| from alembic import op | ||
| from dishka import AsyncContainer, Scope | ||
| from sqlalchemy import select | ||
| from sqlalchemy.ext.asyncio import AsyncConnection, AsyncSession | ||
| from sqlalchemy.orm import joinedload | ||
|
|
||
| from entities import Attribute, Directory, EntityType | ||
| from enums import EntityTypeNames, SamAccountTypeCodes | ||
| from repo.pg.tables import queryable_attr as qa | ||
|
|
||
| revision: None | str = "f4e6cd18a01d" | ||
| down_revision: None | str = "379fce54fb08" | ||
| branch_labels: None | list[str] = None | ||
| depends_on: None | list[str] = None | ||
|
|
||
| _SAM_ACCOUNT_TYPE_ATTR = "sAMAccountType" | ||
| _SECURITY_PRINCIPAL_TYPES = ( | ||
| EntityTypeNames.USER, | ||
| EntityTypeNames.GROUP, | ||
| EntityTypeNames.COMPUTER, | ||
| ) | ||
| _ENTITY_TO_SAM: dict[str, SamAccountTypeCodes] = { | ||
| EntityTypeNames.USER: SamAccountTypeCodes.SAM_USER_OBJECT, | ||
| EntityTypeNames.GROUP: SamAccountTypeCodes.SAM_GROUP_OBJECT, | ||
| EntityTypeNames.COMPUTER: SamAccountTypeCodes.SAM_MACHINE_ACCOUNT, | ||
| } | ||
|
|
||
|
|
||
| def upgrade(container: AsyncContainer) -> None: | ||
| """Add sAMAccountType attributes for user/group/computer.""" | ||
|
|
||
| async def _add_samaccounttype(connection: AsyncConnection) -> None: # noqa: ARG001 | ||
| async with container(scope=Scope.REQUEST) as cnt: | ||
| session = await cnt.get(AsyncSession) | ||
|
|
||
| entity_types = await session.scalars( | ||
| select(EntityType) | ||
| .where(qa(EntityType.name).in_(_SECURITY_PRINCIPAL_TYPES)), | ||
| ) # fmt: skip | ||
| entity_type_ids = [et.id for et in entity_types] | ||
| if not entity_type_ids: | ||
| return | ||
|
|
||
| has_sam = select( | ||
| qa(Attribute.directory_id), | ||
| ).where( | ||
| qa(Attribute.name).ilike(_SAM_ACCOUNT_TYPE_ATTR.lower()), | ||
| ) | ||
| dirs_without_sam = await session.scalars( | ||
| select(Directory) | ||
| .where( | ||
| qa(Directory.entity_type_id).in_(entity_type_ids), | ||
| ~qa(Directory.id).in_(has_sam), | ||
| ) | ||
| .options(joinedload(qa(Directory.entity_type))), | ||
| ) | ||
|
|
||
| for directory in dirs_without_sam: | ||
| sam_value = ( | ||
| _ENTITY_TO_SAM.get(directory.entity_type.name) | ||
| if directory.entity_type | ||
| else None | ||
| ) | ||
| if sam_value is None: | ||
| continue | ||
|
|
||
| session.add( | ||
| Attribute( | ||
| name=_SAM_ACCOUNT_TYPE_ATTR, | ||
| value=str(sam_value), | ||
| directory_id=directory.id, | ||
| ), | ||
| ) | ||
|
|
||
| await session.commit() | ||
|
|
||
| op.run_async(_add_samaccounttype) | ||
|
|
||
|
|
||
| def downgrade(container: AsyncContainer) -> None: | ||
| """Downgrade.""" | ||
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
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
Submodule interface
updated
from e1ca56 to f31962
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.
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.