|
1 | | -from __future__ import annotations |
| 1 | +from ....core.base import TeamScopedResource |
| 2 | +from .operations import _CREATE_OP, _GET_OP, _LIST_OP, _UPDATE_OP, _UPDATE_WS_OP |
| 3 | +from .schemas import CustomDomainConfig, Domain, DomainRouting, RoutingMap |
2 | 4 |
|
3 | | -import logging |
4 | 5 |
|
5 | | -from ....core.base import BoundModel |
6 | | -from ....utils import update_model_fields |
7 | | -from .schemas import ( |
8 | | - CustomDomainConfig, |
9 | | - DomainBase, |
10 | | - DomainRouting, |
11 | | - DomainVerificationStatus, |
12 | | - RoutingMap, |
13 | | -) |
| 6 | +class TeamDomainManager(TeamScopedResource): |
| 7 | + async def list(self) -> list[Domain]: |
| 8 | + result = await self._execute(_LIST_OP, team_id=self.team_id) |
| 9 | + return result.root |
14 | 10 |
|
15 | | -log = logging.getLogger(__name__) |
| 11 | + async def get(self, name: str) -> Domain: |
| 12 | + return await self._execute(_GET_OP, team_id=self.team_id, name=name) |
16 | 13 |
|
| 14 | + async def create(self, name: str) -> Domain: |
| 15 | + return await self._execute(_CREATE_OP, team_id=self.team_id, name=name) |
17 | 16 |
|
18 | | -class Domain(DomainBase, BoundModel): |
19 | | - async def update(self, data: CustomDomainConfig) -> Domain: |
20 | | - from .operations import _UPDATE_OP |
21 | | - |
22 | | - response = await self._execute( |
23 | | - _UPDATE_OP, team_id=self.team_id, name=self.name, data=data |
| 17 | + async def update(self, name: str, config: CustomDomainConfig) -> Domain: |
| 18 | + return await self._execute( |
| 19 | + _UPDATE_OP, team_id=self.team_id, name=name, data=config |
24 | 20 | ) |
25 | | - update_model_fields(target=self, source=response) |
26 | | - return response |
27 | 21 |
|
28 | 22 | async def update_workspace_connections( |
29 | | - self, connections: DomainRouting | RoutingMap |
| 23 | + self, name: str, connections: DomainRouting | RoutingMap |
30 | 24 | ) -> Domain: |
31 | | - from .operations import _UPDATE_WS_OP |
32 | | - |
33 | 25 | payload = ( |
34 | 26 | connections.root if isinstance(connections, DomainRouting) else connections |
35 | 27 | ) |
36 | | - response = await self._execute( |
37 | | - _UPDATE_WS_OP, team_id=self.team_id, name=self.name, data=payload |
| 28 | + return await self._execute( |
| 29 | + _UPDATE_WS_OP, team_id=self.team_id, name=name, data=payload |
38 | 30 | ) |
39 | | - update_model_fields(target=self, source=response) |
40 | | - return response |
41 | | - |
42 | | - async def verify_status(self) -> DomainVerificationStatus: |
43 | | - from .operations import _VERIFY_OP |
44 | | - |
45 | | - response = await self._execute(_VERIFY_OP, team_id=self.team_id, name=self.name) |
46 | | - update_model_fields(target=self.domain_verification_status, source=response) |
47 | | - return response |
48 | | - |
49 | | - async def delete(self) -> None: |
50 | | - from .operations import _DELETE_OP |
51 | | - |
52 | | - await self._execute(_DELETE_OP, team_id=self.team_id, name=self.name) |
0 commit comments