Skip to content

Commit 2267a69

Browse files
[Internal] Extend _CREATE_USER_HOOKS with an optional config
1 parent 6b7cd8b commit 2267a69

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/dstack/_internal/core/models/users.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,11 @@ class UserTokenCreds(CoreModel):
4040
class UserWithCreds(User):
4141
creds: UserTokenCreds
4242
ssh_private_key: Optional[str] = None
43+
44+
45+
class UserHookConfig(CoreModel):
46+
"""
47+
This class can be inherited to extend the user creation configuration passed to the hooks.
48+
"""
49+
50+
pass

src/dstack/_internal/server/services/users.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from dstack._internal.core.models.users import (
1313
GlobalRole,
1414
User,
15+
UserHookConfig,
1516
UserPermissions,
1617
UserTokenCreds,
1718
UserWithCreds,
@@ -79,6 +80,7 @@ async def create_user(
7980
email: Optional[str] = None,
8081
active: bool = True,
8182
token: Optional[str] = None,
83+
config: Optional[UserHookConfig] = None,
8284
) -> UserModel:
8385
validate_username(username)
8486
user_model = await get_user_model_by_name(session=session, username=username, ignore_case=True)
@@ -101,7 +103,7 @@ async def create_user(
101103
session.add(user)
102104
await session.commit()
103105
for func in _CREATE_USER_HOOKS:
104-
await func(session, user)
106+
await func(session, user, config)
105107
return user
106108

107109

@@ -267,7 +269,9 @@ def is_valid_username(username: str) -> bool:
267269
_CREATE_USER_HOOKS = []
268270

269271

270-
def register_create_user_hook(func: Callable[[AsyncSession, UserModel], Awaitable[None]]):
272+
def register_create_user_hook(
273+
func: Callable[[AsyncSession, UserModel, Optional[UserHookConfig]], Awaitable[None]],
274+
):
271275
_CREATE_USER_HOOKS.append(func)
272276

273277

0 commit comments

Comments
 (0)