Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def _create_domain_controllers_ou(

domain_controller_data = [
{
"name": settings.HOST_MACHINE_NAME,
"name": settings.HOST_MACHINE_SHORT_NAME,
"object_class": "computer",
"attributes": {
"objectClass": ["top"],
Expand All @@ -77,7 +77,7 @@ async def _create_domain_controllers_ou(
"sAMAccountType": [
str(SamAccountTypeCodes.SAM_MACHINE_ACCOUNT),
],
"sAMAccountName": [settings.HOST_MACHINE_NAME],
"sAMAccountName": [settings.HOST_MACHINE_SHORT_NAME],
"ipHostNumber": [settings.DEFAULT_NAMESERVER],
},
},
Expand All @@ -101,7 +101,7 @@ async def _create_domain_controllers_ou(

dc = await session.scalar(
select(Directory).where(
qa(Directory.name) == settings.HOST_MACHINE_NAME,
qa(Directory.name) == settings.HOST_MACHINE_SHORT_NAME,
),
)
if not dc:
Expand Down
9 changes: 9 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ class Settings(BaseModel):
AUDIT_SECOND_RETRY_TIME: int = 60
AUDIT_THIRD_RETRY_TIME: int = 1440

@computed_field # type: ignore
@cached_property
def HOST_MACHINE_SHORT_NAME(self) -> str: # noqa: N802
"""Host machine name part before the first dot."""
value = self.HOST_MACHINE_NAME.strip()
if not value:
raise ValueError("HOST_MACHINE_NAME is not set or empty")
return value.split(".", 1)[0]

@computed_field # type: ignore
@cached_property
def POSTGRES_URI(self) -> PostgresDsn: # noqa
Expand Down
6 changes: 3 additions & 3 deletions app/extra/scripts/add_domain_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def _add_domain_controller(
) -> None:
dc_directory = Directory(
object_class="",
name=settings.HOST_MACHINE_NAME,
name=settings.HOST_MACHINE_SHORT_NAME,
is_system=True,
)
dc_directory.create_path(dc_ou_dir)
Expand All @@ -54,7 +54,7 @@ async def _add_domain_controller(
),
Attribute(
name="sAMAccountName",
value=settings.HOST_MACHINE_NAME,
value=settings.HOST_MACHINE_SHORT_NAME,
directory_id=dc_directory.id,
),
Attribute(
Expand All @@ -76,7 +76,7 @@ async def _add_domain_controller(
),
Attribute(
name="cn",
value=settings.HOST_MACHINE_NAME,
value=settings.HOST_MACHINE_SHORT_NAME,
directory_id=dc_directory.id,
),
]
Expand Down
6 changes: 4 additions & 2 deletions app/ldap_protocol/auth/use_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _create_domain_controller_data(self) -> dict:
},
"children": [
{
"name": self._settings.HOST_MACHINE_NAME,
"name": self._settings.HOST_MACHINE_SHORT_NAME,
"object_class": "computer",
"attributes": {
"objectClass": ["top"],
Expand All @@ -104,7 +104,9 @@ def _create_domain_controller_data(self) -> dict:
"sAMAccountType": [
str(SamAccountTypeCodes.SAM_MACHINE_ACCOUNT),
],
"sAMAccountName": [self._settings.HOST_MACHINE_NAME],
"sAMAccountName": [
self._settings.HOST_MACHINE_SHORT_NAME,
],
"ipHostNumber": [self._settings.DEFAULT_NAMESERVER],
},
},
Expand Down