stackit-authorization 0.0.1a0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. stackit/authorization/__init__.py +57 -0
  2. stackit/authorization/api/__init__.py +4 -0
  3. stackit/authorization/api/default_api.py +1894 -0
  4. stackit/authorization/api_client.py +626 -0
  5. stackit/authorization/api_response.py +23 -0
  6. stackit/authorization/configuration.py +110 -0
  7. stackit/authorization/exceptions.py +198 -0
  8. stackit/authorization/models/__init__.py +38 -0
  9. stackit/authorization/models/add_members_payload.py +106 -0
  10. stackit/authorization/models/error_response.py +94 -0
  11. stackit/authorization/models/existing_permission.py +90 -0
  12. stackit/authorization/models/list_members_response.py +115 -0
  13. stackit/authorization/models/list_permissions_response.py +98 -0
  14. stackit/authorization/models/list_user_memberships_response.py +98 -0
  15. stackit/authorization/models/list_user_permissions_response.py +98 -0
  16. stackit/authorization/models/member.py +90 -0
  17. stackit/authorization/models/members_response.py +121 -0
  18. stackit/authorization/models/permission.py +90 -0
  19. stackit/authorization/models/remove_members_payload.py +108 -0
  20. stackit/authorization/models/role.py +122 -0
  21. stackit/authorization/models/roles_response.py +113 -0
  22. stackit/authorization/models/user_membership.py +113 -0
  23. stackit/authorization/models/user_permission.py +117 -0
  24. stackit/authorization/models/zookie.py +81 -0
  25. stackit/authorization/py.typed +0 -0
  26. stackit/authorization/rest.py +148 -0
  27. stackit_authorization-0.0.1a0.dist-info/METADATA +44 -0
  28. stackit_authorization-0.0.1a0.dist-info/RECORD +29 -0
  29. stackit_authorization-0.0.1a0.dist-info/WHEEL +4 -0
@@ -0,0 +1,90 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT Membership API
5
+
6
+ The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources.
7
+
8
+ The version of the OpenAPI document: 2.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501 docstring might be too long
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import pprint
18
+ import re
19
+ from typing import Any, ClassVar, Dict, List, Optional, Set
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, field_validator
22
+ from typing_extensions import Annotated, Self
23
+
24
+
25
+ class Permission(BaseModel):
26
+ """
27
+ Permission
28
+ """
29
+
30
+ description: Annotated[str, Field(min_length=1, strict=True, max_length=255)]
31
+ name: Annotated[str, Field(strict=True, max_length=255)]
32
+ __properties: ClassVar[List[str]] = ["description", "name"]
33
+
34
+ @field_validator("name")
35
+ def name_validate_regular_expression(cls, value):
36
+ """Validates the regular expression"""
37
+ if not re.match(r"^[a-z](?:-?\.?[a-z]){1,63}$", value):
38
+ raise ValueError(r"must validate the regular expression /^[a-z](?:-?\.?[a-z]){1,63}$/")
39
+ return value
40
+
41
+ model_config = ConfigDict(
42
+ populate_by_name=True,
43
+ validate_assignment=True,
44
+ protected_namespaces=(),
45
+ )
46
+
47
+ def to_str(self) -> str:
48
+ """Returns the string representation of the model using alias"""
49
+ return pprint.pformat(self.model_dump(by_alias=True))
50
+
51
+ def to_json(self) -> str:
52
+ """Returns the JSON representation of the model using alias"""
53
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
54
+ return json.dumps(self.to_dict())
55
+
56
+ @classmethod
57
+ def from_json(cls, json_str: str) -> Optional[Self]:
58
+ """Create an instance of Permission from a JSON string"""
59
+ return cls.from_dict(json.loads(json_str))
60
+
61
+ def to_dict(self) -> Dict[str, Any]:
62
+ """Return the dictionary representation of the model using alias.
63
+
64
+ This has the following differences from calling pydantic's
65
+ `self.model_dump(by_alias=True)`:
66
+
67
+ * `None` is only added to the output dict for nullable fields that
68
+ were set at model initialization. Other fields with value `None`
69
+ are ignored.
70
+ """
71
+ excluded_fields: Set[str] = set([])
72
+
73
+ _dict = self.model_dump(
74
+ by_alias=True,
75
+ exclude=excluded_fields,
76
+ exclude_none=True,
77
+ )
78
+ return _dict
79
+
80
+ @classmethod
81
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
82
+ """Create an instance of Permission from a dict"""
83
+ if obj is None:
84
+ return None
85
+
86
+ if not isinstance(obj, dict):
87
+ return cls.model_validate(obj)
88
+
89
+ _obj = cls.model_validate({"description": obj.get("description"), "name": obj.get("name")})
90
+ return _obj
@@ -0,0 +1,108 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT Membership API
5
+
6
+ The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources.
7
+
8
+ The version of the OpenAPI document: 2.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501 docstring might be too long
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import pprint
18
+ import re
19
+ from typing import Any, ClassVar, Dict, List, Optional, Set
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictBool, field_validator
22
+ from typing_extensions import Annotated, Self
23
+
24
+ from stackit.authorization.models.member import Member
25
+
26
+
27
+ class RemoveMembersPayload(BaseModel):
28
+ """
29
+ RemoveMembersPayload
30
+ """
31
+
32
+ force_remove: Optional[StrictBool] = Field(default=None, alias="forceRemove")
33
+ members: List[Member]
34
+ resource_type: Annotated[str, Field(strict=True)] = Field(alias="resourceType")
35
+ __properties: ClassVar[List[str]] = ["forceRemove", "members", "resourceType"]
36
+
37
+ @field_validator("resource_type")
38
+ def resource_type_validate_regular_expression(cls, value):
39
+ """Validates the regular expression"""
40
+ if not re.match(r"^[a-z](?:-?[a-z]){1,63}$", value):
41
+ raise ValueError(r"must validate the regular expression /^[a-z](?:-?[a-z]){1,63}$/")
42
+ return value
43
+
44
+ model_config = ConfigDict(
45
+ populate_by_name=True,
46
+ validate_assignment=True,
47
+ protected_namespaces=(),
48
+ )
49
+
50
+ def to_str(self) -> str:
51
+ """Returns the string representation of the model using alias"""
52
+ return pprint.pformat(self.model_dump(by_alias=True))
53
+
54
+ def to_json(self) -> str:
55
+ """Returns the JSON representation of the model using alias"""
56
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
57
+ return json.dumps(self.to_dict())
58
+
59
+ @classmethod
60
+ def from_json(cls, json_str: str) -> Optional[Self]:
61
+ """Create an instance of RemoveMembersPayload from a JSON string"""
62
+ return cls.from_dict(json.loads(json_str))
63
+
64
+ def to_dict(self) -> Dict[str, Any]:
65
+ """Return the dictionary representation of the model using alias.
66
+
67
+ This has the following differences from calling pydantic's
68
+ `self.model_dump(by_alias=True)`:
69
+
70
+ * `None` is only added to the output dict for nullable fields that
71
+ were set at model initialization. Other fields with value `None`
72
+ are ignored.
73
+ """
74
+ excluded_fields: Set[str] = set([])
75
+
76
+ _dict = self.model_dump(
77
+ by_alias=True,
78
+ exclude=excluded_fields,
79
+ exclude_none=True,
80
+ )
81
+ # override the default output from pydantic by calling `to_dict()` of each item in members (list)
82
+ _items = []
83
+ if self.members:
84
+ for _item in self.members:
85
+ if _item:
86
+ _items.append(_item.to_dict())
87
+ _dict["members"] = _items
88
+ return _dict
89
+
90
+ @classmethod
91
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
92
+ """Create an instance of RemoveMembersPayload from a dict"""
93
+ if obj is None:
94
+ return None
95
+
96
+ if not isinstance(obj, dict):
97
+ return cls.model_validate(obj)
98
+
99
+ _obj = cls.model_validate(
100
+ {
101
+ "forceRemove": obj.get("forceRemove"),
102
+ "members": (
103
+ [Member.from_dict(_item) for _item in obj["members"]] if obj.get("members") is not None else None
104
+ ),
105
+ "resourceType": obj.get("resourceType"),
106
+ }
107
+ )
108
+ return _obj
@@ -0,0 +1,122 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT Membership API
5
+
6
+ The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources.
7
+
8
+ The version of the OpenAPI document: 2.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501 docstring might be too long
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import pprint
18
+ import re
19
+ from typing import Any, ClassVar, Dict, List, Optional, Set
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, field_validator
22
+ from typing_extensions import Annotated, Self
23
+
24
+ from stackit.authorization.models.permission import Permission
25
+
26
+
27
+ class Role(BaseModel):
28
+ """
29
+ Role
30
+ """
31
+
32
+ description: Annotated[str, Field(strict=True, max_length=255)]
33
+ id: Optional[Annotated[str, Field(strict=True)]] = None
34
+ name: Annotated[str, Field(strict=True)]
35
+ permissions: List[Permission]
36
+ __properties: ClassVar[List[str]] = ["description", "id", "name", "permissions"]
37
+
38
+ @field_validator("id")
39
+ def id_validate_regular_expression(cls, value):
40
+ """Validates the regular expression"""
41
+ if value is None:
42
+ return value
43
+
44
+ if not re.match(r"^([a-zA-Z0-9\/_|\-=+]{1,})$", value):
45
+ raise ValueError(r"must validate the regular expression /^([a-zA-Z0-9\/_|\-=+]{1,})$/")
46
+ return value
47
+
48
+ @field_validator("name")
49
+ def name_validate_regular_expression(cls, value):
50
+ """Validates the regular expression"""
51
+ if not re.match(r"^[a-z](?:-?\.?[a-z]){1,63}$", value):
52
+ raise ValueError(r"must validate the regular expression /^[a-z](?:-?\.?[a-z]){1,63}$/")
53
+ return value
54
+
55
+ model_config = ConfigDict(
56
+ populate_by_name=True,
57
+ validate_assignment=True,
58
+ protected_namespaces=(),
59
+ )
60
+
61
+ def to_str(self) -> str:
62
+ """Returns the string representation of the model using alias"""
63
+ return pprint.pformat(self.model_dump(by_alias=True))
64
+
65
+ def to_json(self) -> str:
66
+ """Returns the JSON representation of the model using alias"""
67
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
68
+ return json.dumps(self.to_dict())
69
+
70
+ @classmethod
71
+ def from_json(cls, json_str: str) -> Optional[Self]:
72
+ """Create an instance of Role from a JSON string"""
73
+ return cls.from_dict(json.loads(json_str))
74
+
75
+ def to_dict(self) -> Dict[str, Any]:
76
+ """Return the dictionary representation of the model using alias.
77
+
78
+ This has the following differences from calling pydantic's
79
+ `self.model_dump(by_alias=True)`:
80
+
81
+ * `None` is only added to the output dict for nullable fields that
82
+ were set at model initialization. Other fields with value `None`
83
+ are ignored.
84
+ """
85
+ excluded_fields: Set[str] = set([])
86
+
87
+ _dict = self.model_dump(
88
+ by_alias=True,
89
+ exclude=excluded_fields,
90
+ exclude_none=True,
91
+ )
92
+ # override the default output from pydantic by calling `to_dict()` of each item in permissions (list)
93
+ _items = []
94
+ if self.permissions:
95
+ for _item in self.permissions:
96
+ if _item:
97
+ _items.append(_item.to_dict())
98
+ _dict["permissions"] = _items
99
+ return _dict
100
+
101
+ @classmethod
102
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
103
+ """Create an instance of Role from a dict"""
104
+ if obj is None:
105
+ return None
106
+
107
+ if not isinstance(obj, dict):
108
+ return cls.model_validate(obj)
109
+
110
+ _obj = cls.model_validate(
111
+ {
112
+ "description": obj.get("description"),
113
+ "id": obj.get("id"),
114
+ "name": obj.get("name"),
115
+ "permissions": (
116
+ [Permission.from_dict(_item) for _item in obj["permissions"]]
117
+ if obj.get("permissions") is not None
118
+ else None
119
+ ),
120
+ }
121
+ )
122
+ return _obj
@@ -0,0 +1,113 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT Membership API
5
+
6
+ The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources.
7
+
8
+ The version of the OpenAPI document: 2.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501 docstring might be too long
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import pprint
18
+ import re
19
+ from typing import Any, ClassVar, Dict, List, Optional, Set
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, field_validator
22
+ from typing_extensions import Annotated, Self
23
+
24
+ from stackit.authorization.models.role import Role
25
+
26
+
27
+ class RolesResponse(BaseModel):
28
+ """
29
+ RolesResponse
30
+ """
31
+
32
+ resource_id: Annotated[str, Field(strict=True)] = Field(alias="resourceId")
33
+ resource_type: Annotated[str, Field(strict=True)] = Field(alias="resourceType")
34
+ roles: List[Role]
35
+ __properties: ClassVar[List[str]] = ["resourceId", "resourceType", "roles"]
36
+
37
+ @field_validator("resource_id")
38
+ def resource_id_validate_regular_expression(cls, value):
39
+ """Validates the regular expression"""
40
+ if not re.match(r"^([a-zA-Z0-9\/_|\-=+@.]{1,})$", value):
41
+ raise ValueError(r"must validate the regular expression /^([a-zA-Z0-9\/_|\-=+@.]{1,})$/")
42
+ return value
43
+
44
+ @field_validator("resource_type")
45
+ def resource_type_validate_regular_expression(cls, value):
46
+ """Validates the regular expression"""
47
+ if not re.match(r"^[a-z](?:-?[a-z]){1,63}$", value):
48
+ raise ValueError(r"must validate the regular expression /^[a-z](?:-?[a-z]){1,63}$/")
49
+ return value
50
+
51
+ model_config = ConfigDict(
52
+ populate_by_name=True,
53
+ validate_assignment=True,
54
+ protected_namespaces=(),
55
+ )
56
+
57
+ def to_str(self) -> str:
58
+ """Returns the string representation of the model using alias"""
59
+ return pprint.pformat(self.model_dump(by_alias=True))
60
+
61
+ def to_json(self) -> str:
62
+ """Returns the JSON representation of the model using alias"""
63
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
64
+ return json.dumps(self.to_dict())
65
+
66
+ @classmethod
67
+ def from_json(cls, json_str: str) -> Optional[Self]:
68
+ """Create an instance of RolesResponse from a JSON string"""
69
+ return cls.from_dict(json.loads(json_str))
70
+
71
+ def to_dict(self) -> Dict[str, Any]:
72
+ """Return the dictionary representation of the model using alias.
73
+
74
+ This has the following differences from calling pydantic's
75
+ `self.model_dump(by_alias=True)`:
76
+
77
+ * `None` is only added to the output dict for nullable fields that
78
+ were set at model initialization. Other fields with value `None`
79
+ are ignored.
80
+ """
81
+ excluded_fields: Set[str] = set([])
82
+
83
+ _dict = self.model_dump(
84
+ by_alias=True,
85
+ exclude=excluded_fields,
86
+ exclude_none=True,
87
+ )
88
+ # override the default output from pydantic by calling `to_dict()` of each item in roles (list)
89
+ _items = []
90
+ if self.roles:
91
+ for _item in self.roles:
92
+ if _item:
93
+ _items.append(_item.to_dict())
94
+ _dict["roles"] = _items
95
+ return _dict
96
+
97
+ @classmethod
98
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
99
+ """Create an instance of RolesResponse from a dict"""
100
+ if obj is None:
101
+ return None
102
+
103
+ if not isinstance(obj, dict):
104
+ return cls.model_validate(obj)
105
+
106
+ _obj = cls.model_validate(
107
+ {
108
+ "resourceId": obj.get("resourceId"),
109
+ "resourceType": obj.get("resourceType"),
110
+ "roles": [Role.from_dict(_item) for _item in obj["roles"]] if obj.get("roles") is not None else None,
111
+ }
112
+ )
113
+ return _obj
@@ -0,0 +1,113 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT Membership API
5
+
6
+ The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources.
7
+
8
+ The version of the OpenAPI document: 2.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501 docstring might be too long
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import pprint
18
+ import re
19
+ from typing import Any, ClassVar, Dict, List, Optional, Set
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, field_validator
22
+ from typing_extensions import Annotated, Self
23
+
24
+
25
+ class UserMembership(BaseModel):
26
+ """
27
+ UserMembership
28
+ """
29
+
30
+ resource_id: Annotated[str, Field(strict=True)] = Field(alias="resourceId")
31
+ resource_type: Annotated[str, Field(strict=True)] = Field(alias="resourceType")
32
+ role: Annotated[str, Field(strict=True)]
33
+ subject: Annotated[str, Field(strict=True, max_length=255)]
34
+ __properties: ClassVar[List[str]] = ["resourceId", "resourceType", "role", "subject"]
35
+
36
+ @field_validator("resource_id")
37
+ def resource_id_validate_regular_expression(cls, value):
38
+ """Validates the regular expression"""
39
+ if not re.match(r"^([a-zA-Z0-9\/_|\-=+@.]{1,})$", value):
40
+ raise ValueError(r"must validate the regular expression /^([a-zA-Z0-9\/_|\-=+@.]{1,})$/")
41
+ return value
42
+
43
+ @field_validator("resource_type")
44
+ def resource_type_validate_regular_expression(cls, value):
45
+ """Validates the regular expression"""
46
+ if not re.match(r"^[a-z](?:-?[a-z]){1,63}$", value):
47
+ raise ValueError(r"must validate the regular expression /^[a-z](?:-?[a-z]){1,63}$/")
48
+ return value
49
+
50
+ @field_validator("role")
51
+ def role_validate_regular_expression(cls, value):
52
+ """Validates the regular expression"""
53
+ if not re.match(r"^[a-z](?:-?\.?[a-z]){1,63}$", value):
54
+ raise ValueError(r"must validate the regular expression /^[a-z](?:-?\.?[a-z]){1,63}$/")
55
+ return value
56
+
57
+ model_config = ConfigDict(
58
+ populate_by_name=True,
59
+ validate_assignment=True,
60
+ protected_namespaces=(),
61
+ )
62
+
63
+ def to_str(self) -> str:
64
+ """Returns the string representation of the model using alias"""
65
+ return pprint.pformat(self.model_dump(by_alias=True))
66
+
67
+ def to_json(self) -> str:
68
+ """Returns the JSON representation of the model using alias"""
69
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
70
+ return json.dumps(self.to_dict())
71
+
72
+ @classmethod
73
+ def from_json(cls, json_str: str) -> Optional[Self]:
74
+ """Create an instance of UserMembership from a JSON string"""
75
+ return cls.from_dict(json.loads(json_str))
76
+
77
+ def to_dict(self) -> Dict[str, Any]:
78
+ """Return the dictionary representation of the model using alias.
79
+
80
+ This has the following differences from calling pydantic's
81
+ `self.model_dump(by_alias=True)`:
82
+
83
+ * `None` is only added to the output dict for nullable fields that
84
+ were set at model initialization. Other fields with value `None`
85
+ are ignored.
86
+ """
87
+ excluded_fields: Set[str] = set([])
88
+
89
+ _dict = self.model_dump(
90
+ by_alias=True,
91
+ exclude=excluded_fields,
92
+ exclude_none=True,
93
+ )
94
+ return _dict
95
+
96
+ @classmethod
97
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
98
+ """Create an instance of UserMembership from a dict"""
99
+ if obj is None:
100
+ return None
101
+
102
+ if not isinstance(obj, dict):
103
+ return cls.model_validate(obj)
104
+
105
+ _obj = cls.model_validate(
106
+ {
107
+ "resourceId": obj.get("resourceId"),
108
+ "resourceType": obj.get("resourceType"),
109
+ "role": obj.get("role"),
110
+ "subject": obj.get("subject"),
111
+ }
112
+ )
113
+ return _obj
@@ -0,0 +1,117 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT Membership API
5
+
6
+ The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources.
7
+
8
+ The version of the OpenAPI document: 2.0
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501 docstring might be too long
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ import pprint
18
+ import re
19
+ from typing import Any, ClassVar, Dict, List, Optional, Set
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, field_validator
22
+ from typing_extensions import Annotated, Self
23
+
24
+ from stackit.authorization.models.existing_permission import ExistingPermission
25
+
26
+
27
+ class UserPermission(BaseModel):
28
+ """
29
+ UserPermission
30
+ """
31
+
32
+ permissions: List[ExistingPermission]
33
+ resource_id: Annotated[str, Field(strict=True)] = Field(alias="resourceId")
34
+ resource_type: Annotated[str, Field(strict=True)] = Field(alias="resourceType")
35
+ __properties: ClassVar[List[str]] = ["permissions", "resourceId", "resourceType"]
36
+
37
+ @field_validator("resource_id")
38
+ def resource_id_validate_regular_expression(cls, value):
39
+ """Validates the regular expression"""
40
+ if not re.match(r"^([a-zA-Z0-9\/_|\-=+@.]{1,})$", value):
41
+ raise ValueError(r"must validate the regular expression /^([a-zA-Z0-9\/_|\-=+@.]{1,})$/")
42
+ return value
43
+
44
+ @field_validator("resource_type")
45
+ def resource_type_validate_regular_expression(cls, value):
46
+ """Validates the regular expression"""
47
+ if not re.match(r"^[a-z](?:-?[a-z]){1,63}$", value):
48
+ raise ValueError(r"must validate the regular expression /^[a-z](?:-?[a-z]){1,63}$/")
49
+ return value
50
+
51
+ model_config = ConfigDict(
52
+ populate_by_name=True,
53
+ validate_assignment=True,
54
+ protected_namespaces=(),
55
+ )
56
+
57
+ def to_str(self) -> str:
58
+ """Returns the string representation of the model using alias"""
59
+ return pprint.pformat(self.model_dump(by_alias=True))
60
+
61
+ def to_json(self) -> str:
62
+ """Returns the JSON representation of the model using alias"""
63
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
64
+ return json.dumps(self.to_dict())
65
+
66
+ @classmethod
67
+ def from_json(cls, json_str: str) -> Optional[Self]:
68
+ """Create an instance of UserPermission from a JSON string"""
69
+ return cls.from_dict(json.loads(json_str))
70
+
71
+ def to_dict(self) -> Dict[str, Any]:
72
+ """Return the dictionary representation of the model using alias.
73
+
74
+ This has the following differences from calling pydantic's
75
+ `self.model_dump(by_alias=True)`:
76
+
77
+ * `None` is only added to the output dict for nullable fields that
78
+ were set at model initialization. Other fields with value `None`
79
+ are ignored.
80
+ """
81
+ excluded_fields: Set[str] = set([])
82
+
83
+ _dict = self.model_dump(
84
+ by_alias=True,
85
+ exclude=excluded_fields,
86
+ exclude_none=True,
87
+ )
88
+ # override the default output from pydantic by calling `to_dict()` of each item in permissions (list)
89
+ _items = []
90
+ if self.permissions:
91
+ for _item in self.permissions:
92
+ if _item:
93
+ _items.append(_item.to_dict())
94
+ _dict["permissions"] = _items
95
+ return _dict
96
+
97
+ @classmethod
98
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
99
+ """Create an instance of UserPermission from a dict"""
100
+ if obj is None:
101
+ return None
102
+
103
+ if not isinstance(obj, dict):
104
+ return cls.model_validate(obj)
105
+
106
+ _obj = cls.model_validate(
107
+ {
108
+ "permissions": (
109
+ [ExistingPermission.from_dict(_item) for _item in obj["permissions"]]
110
+ if obj.get("permissions") is not None
111
+ else None
112
+ ),
113
+ "resourceId": obj.get("resourceId"),
114
+ "resourceType": obj.get("resourceType"),
115
+ }
116
+ )
117
+ return _obj