Skip to content

Commit 28dc7f2

Browse files
committed
Added appropriate definitions to the API ACL resources.
1 parent 9bf900c commit 28dc7f2

13 files changed

Lines changed: 770 additions & 0 deletions

File tree

src/dnsmin/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from dnsmin.config import Config
22
from dnsmin.transport import Transport, AsyncTransport
33
from dnsmin.enums import ApiVersionEnum
4+
from dnsmin.resources.acl import AclAPI, AsyncAclAPI
45
from dnsmin.resources.auth import AuthAPI, AsyncAuthAPI
56
from dnsmin.resources.servers import ServersAPI, AsyncServersAPI
67
from dnsmin.resources.system import SystemAPI, AsyncSystemAPI
@@ -12,6 +13,9 @@
1213
class ApiClient:
1314
"""Provides a synchronous client for the DNSMin API."""
1415

16+
acl: AclAPI
17+
"""Provides a synchronous API client for managing ACL resources."""
18+
1519
auth: AuthAPI
1620
"""Provides a synchronous API client for managing authentication resources."""
1721

@@ -43,6 +47,7 @@ def __init__(self, *, base_url: str, token_url: str, client_id: str, client_secr
4347

4448
transport = Transport(config)
4549

50+
self.acl = AclAPI("/acl", transport)
4651
self.auth = AuthAPI("/auth", transport)
4752
self.servers = ServersAPI("/servers", transport)
4853
self.system = SystemAPI("/system", transport)
@@ -54,6 +59,9 @@ def __init__(self, *, base_url: str, token_url: str, client_id: str, client_secr
5459
class AsyncApiClient:
5560
"""Provides an asynchronous client for the DNSMin API."""
5661

62+
acl: AsyncAclAPI
63+
"""Provides an asynchronous API client for managing ACL resources."""
64+
5765
auth: AsyncAuthAPI
5866
"""Provides an asynchronous API client for managing authentication resources."""
5967

@@ -85,6 +93,7 @@ def __init__(self, *, base_url: str, token_url: str, client_id: str, client_secr
8593

8694
transport = AsyncTransport(config)
8795

96+
self.acl = AsyncAclAPI("/acl", transport)
8897
self.auth = AsyncAuthAPI("/auth", transport)
8998
self.servers = AsyncServersAPI("/servers", transport)
9099
self.system = AsyncSystemAPI("/system", transport)

src/dnsmin/enums.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,49 @@ class ApiVersionEnum(str, Enum):
66
v1 = 'v1'
77

88

9+
class PrincipalTypeEnum(str, Enum):
10+
"""Defines the app's principal types."""
11+
all = 'all'
12+
role = 'role'
13+
tenant = 'tenant'
14+
group = 'group'
15+
client = 'client'
16+
user = 'user'
17+
18+
19+
class ResourceTypeEnum(str, Enum):
20+
"""Defines the app's resource types."""
21+
all = 'all'
22+
auth_user = 'auth:user'
23+
auth_user_authenticator = 'auth:user_authenticator'
24+
auth_session = 'auth:session'
25+
auth_client = 'auth:client'
26+
auth_refresh_token = 'auth:refresh_token'
27+
acl_principal = 'acl:principal'
28+
acl_principal_role = 'acl:principal_role'
29+
acl_role = 'acl:role'
30+
acl_role_association = 'acl:role_association'
31+
acl_policy = 'acl:policy'
32+
settings_setting = 'settings:setting'
33+
system_stopgap_domain = 'system:stopgap_domain'
34+
system_timezone = 'system:timezone'
35+
tenants_tenant = 'tenants:tenant'
36+
servers_server = 'servers:server'
37+
servers_auto_primary = 'servers:auto_primary'
38+
keys_crypto_key = 'keys:crypto_key'
39+
keys_tsig_key = 'keys:tsig_key'
40+
zones_azone = 'zones:azone'
41+
zones_azone_record = 'zones:azone_record'
42+
zones_azone_metadata = 'zones:azone_metadata'
43+
zones_rzone = 'zones:rzone'
44+
zones_rzone_record = 'zones:rzone_record'
45+
views_view = 'views:view'
46+
views_zone = 'views:zone'
47+
views_network = 'views:network'
48+
tasks_job = 'tasks:job'
49+
tasks_job_activity = 'tasks:job_activity'
50+
51+
952
class UserStatusEnum(str, Enum):
1053
"""Defines the different statuses a user can have."""
1154
pending = 'pending'

src/dnsmin/models/acl/policy.py

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
from datetime import datetime
2+
from typing import Optional
3+
from uuid import UUID, uuid4
4+
5+
from pydantic import BaseModel, Field
6+
7+
from dnsmin.enums import ResourceTypeEnum, PrincipalTypeEnum
8+
9+
10+
class Policy(BaseModel):
11+
"""Provides an API response model for representing ACL policies."""
12+
13+
id: UUID = Field(
14+
title='Policy ID',
15+
description='The unique identifier of the policy.',
16+
examples=[uuid4()],
17+
)
18+
"""The unique identifier of the policy."""
19+
20+
tenant_id: Optional[UUID] = Field(
21+
title='Tenant ID',
22+
description='The unique identifier of the tenant associated with the policy if any.',
23+
default=None,
24+
examples=[uuid4()],
25+
)
26+
"""The unique identifier of the tenant associated with the policy if any."""
27+
28+
resource_type: ResourceTypeEnum = Field(
29+
title='Resource Type',
30+
description='The resource type associated with the policy.',
31+
examples=[
32+
ResourceTypeEnum.auth_user,
33+
ResourceTypeEnum.auth_client,
34+
ResourceTypeEnum.auth_session,
35+
ResourceTypeEnum.zones_azone,
36+
ResourceTypeEnum.zones_rzone,
37+
],
38+
)
39+
"""The resource type associated with the policy."""
40+
41+
resource_id: Optional[UUID] = Field(
42+
title='Resource ID',
43+
description='The unique identifier of the resource associated with the policy if any.',
44+
default=None,
45+
examples=[uuid4()],
46+
)
47+
"""The unique identifier of the resource associated with the policy if any."""
48+
49+
principal_type: PrincipalTypeEnum = Field(
50+
title='Principal Type',
51+
description='The principal type associated with the policy.',
52+
examples=[
53+
PrincipalTypeEnum.role,
54+
PrincipalTypeEnum.tenant,
55+
PrincipalTypeEnum.client,
56+
PrincipalTypeEnum.user,
57+
],
58+
)
59+
"""The principal type associated with the policy."""
60+
61+
principal_id: Optional[UUID] = Field(
62+
title='Principal ID',
63+
description='The unique identifier of the principal associated with the policy if any.',
64+
default=None,
65+
examples=[uuid4()],
66+
)
67+
"""The unique identifier of the principal associated with the policy if any."""
68+
69+
permission: str = Field(
70+
title='Permission',
71+
description='The permission associated with the policy.',
72+
)
73+
"""The permission associated with the policy."""
74+
75+
deny: bool = Field(
76+
title='Deny Policy',
77+
description='Determines if the policy is an allow or deny policy.',
78+
default=False,
79+
)
80+
"""Determines if the policy is an allow or deny policy."""
81+
82+
created_at: datetime = Field(
83+
title='Created At',
84+
description='The timestamp representing when the policy was created.',
85+
default_factory=datetime.now,
86+
examples=[datetime.now()],
87+
)
88+
"""The timestamp representing when the policy was created."""
89+
90+
updated_at: Optional[datetime] = Field(
91+
title='Updated At',
92+
description='The timestamp representing when the policy was last updated.',
93+
default=None,
94+
examples=[datetime.now()],
95+
)
96+
"""The timestamp representing when the policy was last updated."""
97+
98+
99+
class CreatePolicy(BaseModel):
100+
"""Provides an API input model for creating ACL policies."""
101+
102+
tenant_id: Optional[UUID] = Field(
103+
title='Tenant ID',
104+
description='The unique identifier of the tenant associated with the policy if any.',
105+
default=None,
106+
examples=[uuid4()],
107+
)
108+
"""The unique identifier of the tenant associated with the policy if any."""
109+
110+
resource_type: ResourceTypeEnum = Field(
111+
title='Resource Type',
112+
description='The resource type associated with the policy.',
113+
examples=[
114+
ResourceTypeEnum.auth_user,
115+
ResourceTypeEnum.auth_client,
116+
ResourceTypeEnum.auth_session,
117+
ResourceTypeEnum.zones_azone,
118+
ResourceTypeEnum.zones_rzone,
119+
],
120+
)
121+
"""The resource type associated with the policy."""
122+
123+
resource_id: Optional[UUID] = Field(
124+
title='Resource ID',
125+
description='The unique identifier of the resource associated with the policy if any.',
126+
default=None,
127+
examples=[uuid4()],
128+
)
129+
"""The unique identifier of the resource associated with the policy if any."""
130+
131+
principal_type: PrincipalTypeEnum = Field(
132+
title='Principal Type',
133+
description='The principal type associated with the policy.',
134+
examples=[
135+
PrincipalTypeEnum.role,
136+
PrincipalTypeEnum.tenant,
137+
PrincipalTypeEnum.client,
138+
PrincipalTypeEnum.user,
139+
],
140+
)
141+
"""The principal type associated with the policy."""
142+
143+
principal_id: Optional[UUID] = Field(
144+
title='Principal ID',
145+
description='The unique identifier of the principal associated with the policy if any.',
146+
default=None,
147+
examples=[uuid4()],
148+
)
149+
"""The unique identifier of the principal associated with the policy if any."""
150+
151+
permission: str = Field(
152+
title='Permission',
153+
description='The permission associated with the policy.',
154+
)
155+
"""The permission associated with the policy."""
156+
157+
deny: bool = Field(
158+
title='Deny Policy',
159+
description='Determines if the policy is an allow or deny policy.',
160+
default=False,
161+
)
162+
"""Determines if the policy is an allow or deny policy."""
163+
164+
165+
class UpdatePolicy(CreatePolicy):
166+
"""Provides an API input model for updating ACL policies."""
167+
168+
id: UUID = Field(
169+
title='Policy ID',
170+
description='The unique identifier of the policy.',
171+
examples=[uuid4()],
172+
)
173+
"""The unique identifier of the policy."""

src/dnsmin/models/acl/principal.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
from datetime import datetime
2+
from typing import Optional
3+
from uuid import UUID, uuid4
4+
5+
from pydantic import BaseModel, Field
6+
7+
from dnsmin.enums import PrincipalTypeEnum
8+
9+
10+
class Principal(BaseModel):
11+
"""Provides an API response model for representing ACL principals."""
12+
13+
id: UUID = Field(
14+
title='Principal ID',
15+
description='The unique identifier of the principal.',
16+
examples=[uuid4()],
17+
)
18+
"""The unique identifier of the principal."""
19+
20+
tenant_id: Optional[UUID] = Field(
21+
title='Tenant ID',
22+
description='The unique identifier of the tenant associated with the principal if any.',
23+
default=None,
24+
examples=[uuid4()],
25+
)
26+
"""The unique identifier of the tenant associated with the principal if any."""
27+
28+
type: PrincipalTypeEnum = Field(
29+
title='Principal Type',
30+
description='The type of the associated principal.',
31+
examples=[
32+
PrincipalTypeEnum.user,
33+
PrincipalTypeEnum.client,
34+
],
35+
)
36+
"""The type of the associated principal."""
37+
38+
created_at: datetime = Field(
39+
title='Created At',
40+
description='The timestamp representing when the principal was created.',
41+
default_factory=datetime.now,
42+
examples=[datetime.now()],
43+
)
44+
"""The timestamp representing when the principal was created."""
45+
46+
47+
class CreatePrincipal(BaseModel):
48+
"""Provides an API input model for creating ACL principals."""
49+
50+
id: UUID = Field(
51+
title='Principal ID',
52+
description='The unique identifier of the principal.',
53+
examples=[uuid4()],
54+
)
55+
"""The unique identifier of the principal."""
56+
57+
tenant_id: Optional[UUID] = Field(
58+
title='Tenant ID',
59+
description='The unique identifier of the tenant associated with the principal if any.',
60+
default=None,
61+
examples=[uuid4()],
62+
)
63+
"""The unique identifier of the tenant associated with the principal if any."""
64+
65+
type: PrincipalTypeEnum = Field(
66+
title='Principal Type',
67+
description='The type of the associated principal.',
68+
examples=[
69+
PrincipalTypeEnum.user,
70+
PrincipalTypeEnum.client,
71+
],
72+
)
73+
"""The type of the associated principal."""
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from datetime import datetime
2+
from uuid import UUID, uuid4
3+
4+
from pydantic import BaseModel, Field
5+
6+
7+
class PrincipalRole(BaseModel):
8+
"""Provides an API response model for representing ACL principal role associations."""
9+
10+
principal_id: UUID = Field(
11+
title='Principal ID',
12+
description='The unique identifier of the principal.',
13+
examples=[uuid4()],
14+
)
15+
"""The unique identifier of the principal."""
16+
17+
role_id: UUID = Field(
18+
title='Role ID',
19+
description='The unique identifier of the role.',
20+
examples=[uuid4()],
21+
)
22+
"""The unique identifier of the role."""
23+
24+
created_at: datetime = Field(
25+
title='Created At',
26+
description='The timestamp representing when the association was created.',
27+
default_factory=datetime.now,
28+
examples=[datetime.now()],
29+
)
30+
"""The timestamp representing when the association was created."""
31+
32+
33+
class CreatePrincipalRole(BaseModel):
34+
"""Provides an API input model for creating ACL principal role associations."""
35+
36+
principal_id: UUID = Field(
37+
title='Principal ID',
38+
description='The unique identifier of the principal.',
39+
examples=[uuid4()],
40+
)
41+
"""The unique identifier of the principal."""
42+
43+
role_id: UUID = Field(
44+
title='Role ID',
45+
description='The unique identifier of the role.',
46+
examples=[uuid4()],
47+
)
48+
"""The unique identifier of the role."""

0 commit comments

Comments
 (0)