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,110 @@
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
+
15
+ class HostConfiguration:
16
+ def __init__(
17
+ self,
18
+ region=None,
19
+ server_index=None,
20
+ server_variables=None,
21
+ server_operation_index=None,
22
+ server_operation_variables=None,
23
+ ignore_operation_servers=False,
24
+ ) -> None:
25
+ """Constructor"""
26
+ self._base_path = "https://authorization.api.stackit.cloud"
27
+ """Default Base url
28
+ """
29
+ self.server_index = 0 if server_index is None else server_index
30
+ self.server_operation_index = server_operation_index or {}
31
+ """Default server index
32
+ """
33
+ self.server_variables = server_variables or {}
34
+ if region:
35
+ self.server_variables["region"] = "{}.".format(region)
36
+ self.server_operation_variables = server_operation_variables or {}
37
+ """Default server variables
38
+ """
39
+ self.ignore_operation_servers = ignore_operation_servers
40
+ """Ignore operation servers
41
+ """
42
+
43
+ def get_host_settings(self):
44
+ """Gets an array of host settings
45
+
46
+ :return: An array of host settings
47
+ """
48
+ return [
49
+ {
50
+ "url": "https://authorization.api.stackit.cloud",
51
+ "description": "No description provided",
52
+ "variables": {
53
+ "region": {
54
+ "description": "No description provided",
55
+ "default_value": "global",
56
+ }
57
+ },
58
+ }
59
+ ]
60
+
61
+ def get_host_from_settings(self, index, variables=None, servers=None):
62
+ """Gets host URL based on the index and variables
63
+ :param index: array index of the host settings
64
+ :param variables: hash of variable and the corresponding value
65
+ :param servers: an array of host settings or None
66
+ :return: URL based on host settings
67
+ """
68
+ if index is None:
69
+ return self._base_path
70
+
71
+ variables = {} if variables is None else variables
72
+ servers = self.get_host_settings() if servers is None else servers
73
+
74
+ try:
75
+ server = servers[index]
76
+ except IndexError:
77
+ raise ValueError(
78
+ "Invalid index {0} when selecting the host settings. "
79
+ "Must be less than {1}".format(index, len(servers))
80
+ )
81
+
82
+ url = server["url"]
83
+
84
+ # go through variables and replace placeholders
85
+ for variable_name, variable in server.get("variables", {}).items():
86
+ used_value = variables.get(variable_name, variable["default_value"])
87
+
88
+ if "enum_values" in variable and used_value not in variable["enum_values"]:
89
+ given_value = variables[variable_name].replace(".", "")
90
+ valid_values = [v.replace(".", "") for v in variable["enum_values"]]
91
+ raise ValueError(
92
+ "The variable `{0}` in the host URL has invalid value '{1}'. Must be '{2}'.".format(
93
+ variable_name, given_value, valid_values
94
+ )
95
+ )
96
+
97
+ url = url.replace("{" + variable_name + "}", used_value)
98
+
99
+ return url
100
+
101
+ @property
102
+ def host(self):
103
+ """Return generated host."""
104
+ return self.get_host_from_settings(self.server_index, variables=self.server_variables)
105
+
106
+ @host.setter
107
+ def host(self, value):
108
+ """Fix base path."""
109
+ self._base_path = value
110
+ self.server_index = None
@@ -0,0 +1,198 @@
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 typing import Any, Optional
15
+
16
+ from typing_extensions import Self
17
+
18
+
19
+ class OpenApiException(Exception):
20
+ """The base exception class for all OpenAPIExceptions"""
21
+
22
+
23
+ class ApiTypeError(OpenApiException, TypeError):
24
+ def __init__(self, msg, path_to_item=None, valid_classes=None, key_type=None) -> None:
25
+ """Raises an exception for TypeErrors
26
+
27
+ Args:
28
+ msg (str): the exception message
29
+
30
+ Keyword Args:
31
+ path_to_item (list): a list of keys an indices to get to the
32
+ current_item
33
+ None if unset
34
+ valid_classes (tuple): the primitive classes that current item
35
+ should be an instance of
36
+ None if unset
37
+ key_type (bool): False if our value is a value in a dict
38
+ True if it is a key in a dict
39
+ False if our item is an item in a list
40
+ None if unset
41
+ """
42
+ self.path_to_item = path_to_item
43
+ self.valid_classes = valid_classes
44
+ self.key_type = key_type
45
+ full_msg = msg
46
+ if path_to_item:
47
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
48
+ super(ApiTypeError, self).__init__(full_msg)
49
+
50
+
51
+ class ApiValueError(OpenApiException, ValueError):
52
+ def __init__(self, msg, path_to_item=None) -> None:
53
+ """
54
+ Args:
55
+ msg (str): the exception message
56
+
57
+ Keyword Args:
58
+ path_to_item (list) the path to the exception in the
59
+ received_data dict. None if unset
60
+ """
61
+
62
+ self.path_to_item = path_to_item
63
+ full_msg = msg
64
+ if path_to_item:
65
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
66
+ super(ApiValueError, self).__init__(full_msg)
67
+
68
+
69
+ class ApiAttributeError(OpenApiException, AttributeError):
70
+ def __init__(self, msg, path_to_item=None) -> None:
71
+ """
72
+ Raised when an attribute reference or assignment fails.
73
+
74
+ Args:
75
+ msg (str): the exception message
76
+
77
+ Keyword Args:
78
+ path_to_item (None/list) the path to the exception in the
79
+ received_data dict
80
+ """
81
+ self.path_to_item = path_to_item
82
+ full_msg = msg
83
+ if path_to_item:
84
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
85
+ super(ApiAttributeError, self).__init__(full_msg)
86
+
87
+
88
+ class ApiKeyError(OpenApiException, KeyError):
89
+ def __init__(self, msg, path_to_item=None) -> None:
90
+ """
91
+ Args:
92
+ msg (str): the exception message
93
+
94
+ Keyword Args:
95
+ path_to_item (None/list) the path to the exception in the
96
+ received_data dict
97
+ """
98
+ self.path_to_item = path_to_item
99
+ full_msg = msg
100
+ if path_to_item:
101
+ full_msg = "{0} at {1}".format(msg, render_path(path_to_item))
102
+ super(ApiKeyError, self).__init__(full_msg)
103
+
104
+
105
+ class ApiException(OpenApiException):
106
+
107
+ def __init__(
108
+ self,
109
+ status=None,
110
+ reason=None,
111
+ http_resp=None,
112
+ *,
113
+ body: Optional[str] = None,
114
+ data: Optional[Any] = None,
115
+ ) -> None:
116
+ self.status = status
117
+ self.reason = reason
118
+ self.body = body
119
+ self.data = data
120
+ self.headers = None
121
+
122
+ if http_resp:
123
+ if self.status is None:
124
+ self.status = http_resp.status
125
+ if self.reason is None:
126
+ self.reason = http_resp.reason
127
+ if self.body is None:
128
+ try:
129
+ self.body = http_resp.data.decode("utf-8")
130
+ except Exception: # noqa: S110
131
+ pass
132
+ self.headers = http_resp.getheaders()
133
+
134
+ @classmethod
135
+ def from_response(
136
+ cls,
137
+ *,
138
+ http_resp,
139
+ body: Optional[str],
140
+ data: Optional[Any],
141
+ ) -> Self:
142
+ if http_resp.status == 400:
143
+ raise BadRequestException(http_resp=http_resp, body=body, data=data)
144
+
145
+ if http_resp.status == 401:
146
+ raise UnauthorizedException(http_resp=http_resp, body=body, data=data)
147
+
148
+ if http_resp.status == 403:
149
+ raise ForbiddenException(http_resp=http_resp, body=body, data=data)
150
+
151
+ if http_resp.status == 404:
152
+ raise NotFoundException(http_resp=http_resp, body=body, data=data)
153
+
154
+ if 500 <= http_resp.status <= 599:
155
+ raise ServiceException(http_resp=http_resp, body=body, data=data)
156
+ raise ApiException(http_resp=http_resp, body=body, data=data)
157
+
158
+ def __str__(self):
159
+ """Custom error messages for exception"""
160
+ error_message = "({0})\n" "Reason: {1}\n".format(self.status, self.reason)
161
+ if self.headers:
162
+ error_message += "HTTP response headers: {0}\n".format(self.headers)
163
+
164
+ if self.data or self.body:
165
+ error_message += "HTTP response body: {0}\n".format(self.data or self.body)
166
+
167
+ return error_message
168
+
169
+
170
+ class BadRequestException(ApiException):
171
+ pass
172
+
173
+
174
+ class NotFoundException(ApiException):
175
+ pass
176
+
177
+
178
+ class UnauthorizedException(ApiException):
179
+ pass
180
+
181
+
182
+ class ForbiddenException(ApiException):
183
+ pass
184
+
185
+
186
+ class ServiceException(ApiException):
187
+ pass
188
+
189
+
190
+ def render_path(path_to_item):
191
+ """Returns a string representation of a path"""
192
+ result = ""
193
+ for pth in path_to_item:
194
+ if isinstance(pth, int):
195
+ result += "[{0}]".format(pth)
196
+ else:
197
+ result += "['{0}']".format(pth)
198
+ return result
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+
3
+ # flake8: noqa
4
+ """
5
+ STACKIT Membership API
6
+
7
+ The Membership API is used to manage memberships, roles and permissions of STACKIT resources, like projects, folders, organizations and other resources.
8
+
9
+ The version of the OpenAPI document: 2.0
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501 docstring might be too long
14
+
15
+
16
+ # import models into model package
17
+ from stackit.authorization.models.add_members_payload import AddMembersPayload
18
+ from stackit.authorization.models.error_response import ErrorResponse
19
+ from stackit.authorization.models.existing_permission import ExistingPermission
20
+ from stackit.authorization.models.list_members_response import ListMembersResponse
21
+ from stackit.authorization.models.list_permissions_response import (
22
+ ListPermissionsResponse,
23
+ )
24
+ from stackit.authorization.models.list_user_memberships_response import (
25
+ ListUserMembershipsResponse,
26
+ )
27
+ from stackit.authorization.models.list_user_permissions_response import (
28
+ ListUserPermissionsResponse,
29
+ )
30
+ from stackit.authorization.models.member import Member
31
+ from stackit.authorization.models.members_response import MembersResponse
32
+ from stackit.authorization.models.permission import Permission
33
+ from stackit.authorization.models.remove_members_payload import RemoveMembersPayload
34
+ from stackit.authorization.models.role import Role
35
+ from stackit.authorization.models.roles_response import RolesResponse
36
+ from stackit.authorization.models.user_membership import UserMembership
37
+ from stackit.authorization.models.user_permission import UserPermission
38
+ from stackit.authorization.models.zookie import Zookie
@@ -0,0 +1,106 @@
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.member import Member
25
+
26
+
27
+ class AddMembersPayload(BaseModel):
28
+ """
29
+ AddMembersPayload
30
+ """
31
+
32
+ members: List[Member]
33
+ resource_type: Annotated[str, Field(strict=True)] = Field(alias="resourceType")
34
+ __properties: ClassVar[List[str]] = ["members", "resourceType"]
35
+
36
+ @field_validator("resource_type")
37
+ def resource_type_validate_regular_expression(cls, value):
38
+ """Validates the regular expression"""
39
+ if not re.match(r"^[a-z](?:-?[a-z]){1,63}$", value):
40
+ raise ValueError(r"must validate the regular expression /^[a-z](?:-?[a-z]){1,63}$/")
41
+ return value
42
+
43
+ model_config = ConfigDict(
44
+ populate_by_name=True,
45
+ validate_assignment=True,
46
+ protected_namespaces=(),
47
+ )
48
+
49
+ def to_str(self) -> str:
50
+ """Returns the string representation of the model using alias"""
51
+ return pprint.pformat(self.model_dump(by_alias=True))
52
+
53
+ def to_json(self) -> str:
54
+ """Returns the JSON representation of the model using alias"""
55
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
56
+ return json.dumps(self.to_dict())
57
+
58
+ @classmethod
59
+ def from_json(cls, json_str: str) -> Optional[Self]:
60
+ """Create an instance of AddMembersPayload from a JSON string"""
61
+ return cls.from_dict(json.loads(json_str))
62
+
63
+ def to_dict(self) -> Dict[str, Any]:
64
+ """Return the dictionary representation of the model using alias.
65
+
66
+ This has the following differences from calling pydantic's
67
+ `self.model_dump(by_alias=True)`:
68
+
69
+ * `None` is only added to the output dict for nullable fields that
70
+ were set at model initialization. Other fields with value `None`
71
+ are ignored.
72
+ """
73
+ excluded_fields: Set[str] = set([])
74
+
75
+ _dict = self.model_dump(
76
+ by_alias=True,
77
+ exclude=excluded_fields,
78
+ exclude_none=True,
79
+ )
80
+ # override the default output from pydantic by calling `to_dict()` of each item in members (list)
81
+ _items = []
82
+ if self.members:
83
+ for _item in self.members:
84
+ if _item:
85
+ _items.append(_item.to_dict())
86
+ _dict["members"] = _items
87
+ return _dict
88
+
89
+ @classmethod
90
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
91
+ """Create an instance of AddMembersPayload from a dict"""
92
+ if obj is None:
93
+ return None
94
+
95
+ if not isinstance(obj, dict):
96
+ return cls.model_validate(obj)
97
+
98
+ _obj = cls.model_validate(
99
+ {
100
+ "members": (
101
+ [Member.from_dict(_item) for _item in obj["members"]] if obj.get("members") is not None else None
102
+ ),
103
+ "resourceType": obj.get("resourceType"),
104
+ }
105
+ )
106
+ return _obj
@@ -0,0 +1,94 @@
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
+ from datetime import datetime
19
+ from typing import Any, ClassVar, Dict, List, Optional, Set
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
22
+ from typing_extensions import Self
23
+
24
+
25
+ class ErrorResponse(BaseModel):
26
+ """
27
+ ErrorResponse
28
+ """
29
+
30
+ error: StrictStr
31
+ message: StrictStr
32
+ path: StrictStr
33
+ status: StrictInt
34
+ time_stamp: datetime = Field(alias="timeStamp")
35
+ __properties: ClassVar[List[str]] = ["error", "message", "path", "status", "timeStamp"]
36
+
37
+ model_config = ConfigDict(
38
+ populate_by_name=True,
39
+ validate_assignment=True,
40
+ protected_namespaces=(),
41
+ )
42
+
43
+ def to_str(self) -> str:
44
+ """Returns the string representation of the model using alias"""
45
+ return pprint.pformat(self.model_dump(by_alias=True))
46
+
47
+ def to_json(self) -> str:
48
+ """Returns the JSON representation of the model using alias"""
49
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
50
+ return json.dumps(self.to_dict())
51
+
52
+ @classmethod
53
+ def from_json(cls, json_str: str) -> Optional[Self]:
54
+ """Create an instance of ErrorResponse from a JSON string"""
55
+ return cls.from_dict(json.loads(json_str))
56
+
57
+ def to_dict(self) -> Dict[str, Any]:
58
+ """Return the dictionary representation of the model using alias.
59
+
60
+ This has the following differences from calling pydantic's
61
+ `self.model_dump(by_alias=True)`:
62
+
63
+ * `None` is only added to the output dict for nullable fields that
64
+ were set at model initialization. Other fields with value `None`
65
+ are ignored.
66
+ """
67
+ excluded_fields: Set[str] = set([])
68
+
69
+ _dict = self.model_dump(
70
+ by_alias=True,
71
+ exclude=excluded_fields,
72
+ exclude_none=True,
73
+ )
74
+ return _dict
75
+
76
+ @classmethod
77
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
78
+ """Create an instance of ErrorResponse from a dict"""
79
+ if obj is None:
80
+ return None
81
+
82
+ if not isinstance(obj, dict):
83
+ return cls.model_validate(obj)
84
+
85
+ _obj = cls.model_validate(
86
+ {
87
+ "error": obj.get("error"),
88
+ "message": obj.get("message"),
89
+ "path": obj.get("path"),
90
+ "status": obj.get("status"),
91
+ "timeStamp": obj.get("timeStamp"),
92
+ }
93
+ )
94
+ return _obj
@@ -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 ExistingPermission(BaseModel):
26
+ """
27
+ ExistingPermission
28
+ """
29
+
30
+ description: Annotated[str, Field(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 ExistingPermission 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 ExistingPermission 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