clear-skies 2.0.4__py3-none-any.whl → 2.0.5__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.

Potentially problematic release.


This version of clear-skies might be problematic. Click here for more details.

Files changed (253) hide show
  1. clear_skies-2.0.5.dist-info/METADATA +74 -0
  2. clear_skies-2.0.5.dist-info/RECORD +4 -0
  3. {clear_skies-2.0.4.dist-info → clear_skies-2.0.5.dist-info}/WHEEL +1 -1
  4. clear_skies-2.0.4.dist-info/METADATA +0 -36
  5. clear_skies-2.0.4.dist-info/RECORD +0 -251
  6. clearskies/__init__.py +0 -61
  7. clearskies/action.py +0 -7
  8. clearskies/authentication/__init__.py +0 -15
  9. clearskies/authentication/authentication.py +0 -46
  10. clearskies/authentication/authorization.py +0 -16
  11. clearskies/authentication/authorization_pass_through.py +0 -20
  12. clearskies/authentication/jwks.py +0 -163
  13. clearskies/authentication/public.py +0 -5
  14. clearskies/authentication/secret_bearer.py +0 -553
  15. clearskies/autodoc/__init__.py +0 -8
  16. clearskies/autodoc/formats/__init__.py +0 -5
  17. clearskies/autodoc/formats/oai3_json/__init__.py +0 -7
  18. clearskies/autodoc/formats/oai3_json/oai3_json.py +0 -87
  19. clearskies/autodoc/formats/oai3_json/oai3_schema_resolver.py +0 -15
  20. clearskies/autodoc/formats/oai3_json/parameter.py +0 -35
  21. clearskies/autodoc/formats/oai3_json/request.py +0 -68
  22. clearskies/autodoc/formats/oai3_json/response.py +0 -28
  23. clearskies/autodoc/formats/oai3_json/schema/__init__.py +0 -11
  24. clearskies/autodoc/formats/oai3_json/schema/array.py +0 -9
  25. clearskies/autodoc/formats/oai3_json/schema/default.py +0 -13
  26. clearskies/autodoc/formats/oai3_json/schema/enum.py +0 -7
  27. clearskies/autodoc/formats/oai3_json/schema/object.py +0 -35
  28. clearskies/autodoc/formats/oai3_json/test.json +0 -1985
  29. clearskies/autodoc/py.typed +0 -0
  30. clearskies/autodoc/request/__init__.py +0 -15
  31. clearskies/autodoc/request/header.py +0 -6
  32. clearskies/autodoc/request/json_body.py +0 -6
  33. clearskies/autodoc/request/parameter.py +0 -8
  34. clearskies/autodoc/request/request.py +0 -47
  35. clearskies/autodoc/request/url_parameter.py +0 -6
  36. clearskies/autodoc/request/url_path.py +0 -6
  37. clearskies/autodoc/response/__init__.py +0 -5
  38. clearskies/autodoc/response/response.py +0 -9
  39. clearskies/autodoc/schema/__init__.py +0 -31
  40. clearskies/autodoc/schema/array.py +0 -10
  41. clearskies/autodoc/schema/base64.py +0 -8
  42. clearskies/autodoc/schema/boolean.py +0 -5
  43. clearskies/autodoc/schema/date.py +0 -5
  44. clearskies/autodoc/schema/datetime.py +0 -5
  45. clearskies/autodoc/schema/double.py +0 -5
  46. clearskies/autodoc/schema/enum.py +0 -17
  47. clearskies/autodoc/schema/integer.py +0 -6
  48. clearskies/autodoc/schema/long.py +0 -5
  49. clearskies/autodoc/schema/number.py +0 -6
  50. clearskies/autodoc/schema/object.py +0 -13
  51. clearskies/autodoc/schema/password.py +0 -5
  52. clearskies/autodoc/schema/schema.py +0 -11
  53. clearskies/autodoc/schema/string.py +0 -5
  54. clearskies/backends/__init__.py +0 -65
  55. clearskies/backends/api_backend.py +0 -1178
  56. clearskies/backends/backend.py +0 -136
  57. clearskies/backends/cursor_backend.py +0 -335
  58. clearskies/backends/memory_backend.py +0 -797
  59. clearskies/backends/secrets_backend.py +0 -106
  60. clearskies/column.py +0 -1233
  61. clearskies/columns/__init__.py +0 -71
  62. clearskies/columns/audit.py +0 -206
  63. clearskies/columns/belongs_to_id.py +0 -483
  64. clearskies/columns/belongs_to_model.py +0 -132
  65. clearskies/columns/belongs_to_self.py +0 -105
  66. clearskies/columns/boolean.py +0 -113
  67. clearskies/columns/category_tree.py +0 -275
  68. clearskies/columns/category_tree_ancestors.py +0 -51
  69. clearskies/columns/category_tree_children.py +0 -127
  70. clearskies/columns/category_tree_descendants.py +0 -48
  71. clearskies/columns/created.py +0 -95
  72. clearskies/columns/created_by_authorization_data.py +0 -116
  73. clearskies/columns/created_by_header.py +0 -99
  74. clearskies/columns/created_by_ip.py +0 -92
  75. clearskies/columns/created_by_routing_data.py +0 -97
  76. clearskies/columns/created_by_user_agent.py +0 -92
  77. clearskies/columns/date.py +0 -234
  78. clearskies/columns/datetime.py +0 -282
  79. clearskies/columns/email.py +0 -76
  80. clearskies/columns/float.py +0 -153
  81. clearskies/columns/has_many.py +0 -505
  82. clearskies/columns/has_many_self.py +0 -56
  83. clearskies/columns/has_one.py +0 -14
  84. clearskies/columns/integer.py +0 -160
  85. clearskies/columns/json.py +0 -126
  86. clearskies/columns/many_to_many_ids.py +0 -337
  87. clearskies/columns/many_to_many_ids_with_data.py +0 -274
  88. clearskies/columns/many_to_many_models.py +0 -158
  89. clearskies/columns/many_to_many_pivots.py +0 -134
  90. clearskies/columns/phone.py +0 -159
  91. clearskies/columns/select.py +0 -92
  92. clearskies/columns/string.py +0 -102
  93. clearskies/columns/timestamp.py +0 -164
  94. clearskies/columns/updated.py +0 -110
  95. clearskies/columns/uuid.py +0 -86
  96. clearskies/configs/README.md +0 -105
  97. clearskies/configs/__init__.py +0 -162
  98. clearskies/configs/actions.py +0 -43
  99. clearskies/configs/any.py +0 -13
  100. clearskies/configs/any_dict.py +0 -22
  101. clearskies/configs/any_dict_or_callable.py +0 -23
  102. clearskies/configs/authentication.py +0 -23
  103. clearskies/configs/authorization.py +0 -23
  104. clearskies/configs/boolean.py +0 -16
  105. clearskies/configs/boolean_or_callable.py +0 -18
  106. clearskies/configs/callable_config.py +0 -18
  107. clearskies/configs/columns.py +0 -34
  108. clearskies/configs/conditions.py +0 -30
  109. clearskies/configs/config.py +0 -24
  110. clearskies/configs/datetime.py +0 -18
  111. clearskies/configs/datetime_or_callable.py +0 -19
  112. clearskies/configs/endpoint.py +0 -23
  113. clearskies/configs/endpoint_list.py +0 -28
  114. clearskies/configs/float.py +0 -16
  115. clearskies/configs/float_or_callable.py +0 -18
  116. clearskies/configs/integer.py +0 -16
  117. clearskies/configs/integer_or_callable.py +0 -18
  118. clearskies/configs/joins.py +0 -30
  119. clearskies/configs/list_any_dict.py +0 -30
  120. clearskies/configs/list_any_dict_or_callable.py +0 -31
  121. clearskies/configs/model_class.py +0 -35
  122. clearskies/configs/model_column.py +0 -65
  123. clearskies/configs/model_columns.py +0 -56
  124. clearskies/configs/model_destination_name.py +0 -25
  125. clearskies/configs/model_to_id_column.py +0 -43
  126. clearskies/configs/readable_model_column.py +0 -9
  127. clearskies/configs/readable_model_columns.py +0 -9
  128. clearskies/configs/schema.py +0 -23
  129. clearskies/configs/searchable_model_columns.py +0 -9
  130. clearskies/configs/security_headers.py +0 -39
  131. clearskies/configs/select.py +0 -26
  132. clearskies/configs/select_list.py +0 -47
  133. clearskies/configs/string.py +0 -29
  134. clearskies/configs/string_dict.py +0 -32
  135. clearskies/configs/string_list.py +0 -32
  136. clearskies/configs/string_list_or_callable.py +0 -35
  137. clearskies/configs/string_or_callable.py +0 -18
  138. clearskies/configs/timedelta.py +0 -18
  139. clearskies/configs/timezone.py +0 -18
  140. clearskies/configs/url.py +0 -23
  141. clearskies/configs/validators.py +0 -45
  142. clearskies/configs/writeable_model_column.py +0 -9
  143. clearskies/configs/writeable_model_columns.py +0 -9
  144. clearskies/configurable.py +0 -76
  145. clearskies/contexts/__init__.py +0 -11
  146. clearskies/contexts/cli.py +0 -117
  147. clearskies/contexts/context.py +0 -98
  148. clearskies/contexts/wsgi.py +0 -76
  149. clearskies/contexts/wsgi_ref.py +0 -82
  150. clearskies/decorators.py +0 -33
  151. clearskies/di/__init__.py +0 -14
  152. clearskies/di/additional_config.py +0 -130
  153. clearskies/di/additional_config_auto_import.py +0 -17
  154. clearskies/di/di.py +0 -973
  155. clearskies/di/inject/__init__.py +0 -23
  156. clearskies/di/inject/by_class.py +0 -21
  157. clearskies/di/inject/by_name.py +0 -18
  158. clearskies/di/inject/di.py +0 -13
  159. clearskies/di/inject/environment.py +0 -14
  160. clearskies/di/inject/input_output.py +0 -20
  161. clearskies/di/inject/now.py +0 -13
  162. clearskies/di/inject/requests.py +0 -13
  163. clearskies/di/inject/secrets.py +0 -14
  164. clearskies/di/inject/utcnow.py +0 -13
  165. clearskies/di/inject/uuid.py +0 -15
  166. clearskies/di/injectable.py +0 -29
  167. clearskies/di/injectable_properties.py +0 -131
  168. clearskies/di/test_module/__init__.py +0 -6
  169. clearskies/di/test_module/another_module/__init__.py +0 -2
  170. clearskies/di/test_module/module_class.py +0 -5
  171. clearskies/end.py +0 -183
  172. clearskies/endpoint.py +0 -1314
  173. clearskies/endpoint_group.py +0 -338
  174. clearskies/endpoints/__init__.py +0 -25
  175. clearskies/endpoints/advanced_search.py +0 -526
  176. clearskies/endpoints/callable.py +0 -388
  177. clearskies/endpoints/create.py +0 -205
  178. clearskies/endpoints/delete.py +0 -139
  179. clearskies/endpoints/get.py +0 -271
  180. clearskies/endpoints/health_check.py +0 -183
  181. clearskies/endpoints/list.py +0 -574
  182. clearskies/endpoints/restful_api.py +0 -427
  183. clearskies/endpoints/schema.py +0 -189
  184. clearskies/endpoints/simple_search.py +0 -286
  185. clearskies/endpoints/update.py +0 -193
  186. clearskies/environment.py +0 -104
  187. clearskies/exceptions/__init__.py +0 -19
  188. clearskies/exceptions/authentication.py +0 -2
  189. clearskies/exceptions/authorization.py +0 -2
  190. clearskies/exceptions/client_error.py +0 -2
  191. clearskies/exceptions/input_errors.py +0 -4
  192. clearskies/exceptions/missing_dependency.py +0 -2
  193. clearskies/exceptions/moved_permanently.py +0 -3
  194. clearskies/exceptions/moved_temporarily.py +0 -3
  195. clearskies/exceptions/not_found.py +0 -2
  196. clearskies/functional/__init__.py +0 -7
  197. clearskies/functional/routing.py +0 -92
  198. clearskies/functional/string.py +0 -112
  199. clearskies/functional/validations.py +0 -76
  200. clearskies/input_outputs/__init__.py +0 -13
  201. clearskies/input_outputs/cli.py +0 -171
  202. clearskies/input_outputs/exceptions/__init__.py +0 -2
  203. clearskies/input_outputs/exceptions/cli_input_error.py +0 -2
  204. clearskies/input_outputs/exceptions/cli_not_found.py +0 -2
  205. clearskies/input_outputs/headers.py +0 -45
  206. clearskies/input_outputs/input_output.py +0 -138
  207. clearskies/input_outputs/programmatic.py +0 -69
  208. clearskies/input_outputs/py.typed +0 -0
  209. clearskies/input_outputs/wsgi.py +0 -77
  210. clearskies/model.py +0 -1922
  211. clearskies/py.typed +0 -0
  212. clearskies/query/__init__.py +0 -12
  213. clearskies/query/condition.py +0 -223
  214. clearskies/query/join.py +0 -136
  215. clearskies/query/query.py +0 -196
  216. clearskies/query/sort.py +0 -27
  217. clearskies/schema.py +0 -82
  218. clearskies/secrets/__init__.py +0 -6
  219. clearskies/secrets/additional_configs/__init__.py +0 -32
  220. clearskies/secrets/additional_configs/mysql_connection_dynamic_producer.py +0 -61
  221. clearskies/secrets/additional_configs/mysql_connection_dynamic_producer_via_ssh_cert_bastion.py +0 -160
  222. clearskies/secrets/akeyless.py +0 -182
  223. clearskies/secrets/exceptions/__init__.py +0 -1
  224. clearskies/secrets/exceptions/not_found.py +0 -2
  225. clearskies/secrets/secrets.py +0 -38
  226. clearskies/security_header.py +0 -15
  227. clearskies/security_headers/__init__.py +0 -11
  228. clearskies/security_headers/cache_control.py +0 -67
  229. clearskies/security_headers/cors.py +0 -50
  230. clearskies/security_headers/csp.py +0 -94
  231. clearskies/security_headers/hsts.py +0 -22
  232. clearskies/security_headers/x_content_type_options.py +0 -0
  233. clearskies/security_headers/x_frame_options.py +0 -0
  234. clearskies/test_base.py +0 -8
  235. clearskies/typing.py +0 -11
  236. clearskies/validator.py +0 -37
  237. clearskies/validators/__init__.py +0 -33
  238. clearskies/validators/after_column.py +0 -62
  239. clearskies/validators/before_column.py +0 -13
  240. clearskies/validators/in_the_future.py +0 -32
  241. clearskies/validators/in_the_future_at_least.py +0 -11
  242. clearskies/validators/in_the_future_at_most.py +0 -10
  243. clearskies/validators/in_the_past.py +0 -32
  244. clearskies/validators/in_the_past_at_least.py +0 -10
  245. clearskies/validators/in_the_past_at_most.py +0 -10
  246. clearskies/validators/maximum_length.py +0 -26
  247. clearskies/validators/maximum_value.py +0 -29
  248. clearskies/validators/minimum_length.py +0 -26
  249. clearskies/validators/minimum_value.py +0 -29
  250. clearskies/validators/required.py +0 -34
  251. clearskies/validators/timedelta.py +0 -59
  252. clearskies/validators/unique.py +0 -30
  253. {clear_skies-2.0.4.dist-info → clear_skies-2.0.5.dist-info/licenses}/LICENSE +0 -0
@@ -1,338 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from typing import TYPE_CHECKING, Any, Callable, Self
4
-
5
- import clearskies.configurable
6
- import clearskies.di
7
- import clearskies.end
8
- from clearskies import exceptions
9
- from clearskies.authentication import Authentication, Authorization, Public
10
- from clearskies.endpoint import Endpoint
11
- from clearskies.functional import routing
12
- from clearskies.input_outputs import InputOutput
13
-
14
- if TYPE_CHECKING:
15
- from clearskies import SecurityHeader
16
-
17
-
18
- class EndpointGroup(
19
- clearskies.end.End, # type: ignore
20
- clearskies.configurable.Configurable,
21
- clearskies.di.InjectableProperties,
22
- ):
23
- """
24
- An endpoint group brings endpoints together: it basically handles routing.
25
-
26
- The endpoint group accepts a list of endpoints/endpoint groups and routes requests to them. You can set a URL for
27
- the endpoint group, and this becomes a URL prefix for all of the endpoints under it. Note that all routing is
28
- greedy, which means you want to put endpoints with more specific URLs first. Here's an example of how
29
- you can use them to build a fully functional API that manages both users and companies. Each individual
30
- endpoint is defined for the purpose of the example, but note that in practice you could accomplish this same
31
- thing with much less code by using the RestfulApi endpoint:
32
-
33
- ```python
34
- import clearskies
35
- from clearskies.validators import Required, Unique
36
- from clearskies import columns
37
-
38
-
39
- class Company(clearskies.Model):
40
- id_column_name = "id"
41
- backend = clearskies.backends.MemoryBackend()
42
-
43
- id = columns.Uuid()
44
- name = columns.String(
45
- validators=[
46
- Required(),
47
- Unique(),
48
- ]
49
- )
50
-
51
-
52
- class User(clearskies.Model):
53
- id_column_name = "id"
54
- backend = clearskies.backends.MemoryBackend()
55
-
56
- id = columns.Uuid()
57
- name = columns.String(validators=[Required()])
58
- username = columns.String(
59
- validators=[
60
- Required(),
61
- Unique(),
62
- ]
63
- )
64
- age = columns.Integer(validators=[Required()])
65
- created_at = columns.Created()
66
- updated_at = columns.Updated()
67
- company_id = columns.BelongsToId(
68
- Company,
69
- readable_parent_columns=["id", "name"],
70
- validators=[Required()],
71
- )
72
- company = columns.BelongsToModel("company_id")
73
-
74
-
75
- readable_user_column_names = [
76
- "id",
77
- "name",
78
- "username",
79
- "age",
80
- "created_at",
81
- "updated_at",
82
- "company",
83
- ]
84
- writeable_user_column_names = ["name", "username", "age", "company_id"]
85
- users_api = clearskies.EndpointGroup(
86
- [
87
- clearskies.endpoints.Update(
88
- model_class=User,
89
- url="/:id",
90
- readable_column_names=readable_user_column_names,
91
- writeable_column_names=writeable_user_column_names,
92
- ),
93
- clearskies.endpoints.Delete(
94
- model_class=User,
95
- url="/:id",
96
- ),
97
- clearskies.endpoints.Get(
98
- model_class=User,
99
- url="/:id",
100
- readable_column_names=readable_user_column_names,
101
- ),
102
- clearskies.endpoints.Create(
103
- model_class=User,
104
- readable_column_names=readable_user_column_names,
105
- writeable_column_names=writeable_user_column_names,
106
- ),
107
- clearskies.endpoints.SimpleSearch(
108
- model_class=User,
109
- readable_column_names=readable_user_column_names,
110
- sortable_column_names=readable_user_column_names,
111
- searchable_column_names=readable_user_column_names,
112
- default_sort_column_name="name",
113
- ),
114
- ],
115
- url="users",
116
- )
117
-
118
- readable_company_column_names = ["id", "name"]
119
- writeable_company_column_names = ["name"]
120
- companies_api = clearskies.EndpointGroup(
121
- [
122
- clearskies.endpoints.Update(
123
- model_class=Company,
124
- url="/:id",
125
- readable_column_names=readable_company_column_names,
126
- writeable_column_names=writeable_company_column_names,
127
- ),
128
- clearskies.endpoints.Delete(
129
- model_class=Company,
130
- url="/:id",
131
- ),
132
- clearskies.endpoints.Get(
133
- model_class=Company,
134
- url="/:id",
135
- readable_column_names=readable_company_column_names,
136
- ),
137
- clearskies.endpoints.Create(
138
- model_class=Company,
139
- readable_column_names=readable_company_column_names,
140
- writeable_column_names=writeable_company_column_names,
141
- ),
142
- clearskies.endpoints.SimpleSearch(
143
- model_class=Company,
144
- readable_column_names=readable_company_column_names,
145
- sortable_column_names=readable_company_column_names,
146
- searchable_column_names=readable_company_column_names,
147
- default_sort_column_name="name",
148
- ),
149
- ],
150
- url="companies",
151
- )
152
-
153
- wsgi = clearskies.contexts.WsgiRef(clearskies.EndpointGroup([users_api, companies_api]))
154
- wsgi()
155
- ```
156
-
157
- Usage then works exactly as expected:
158
-
159
- ```bash
160
- $ curl 'http://localhost:8080/companies' -d '{"name": "Box Store"}' | jq
161
- {
162
- "status": "success",
163
- "error": "",
164
- "data": {
165
- "id": "f073ee4d-318d-4e0b-a796-f450c40aa771",
166
- "name": "Box Store"
167
- },
168
- "pagination": {},
169
- "input_errors": {}
170
- }
171
-
172
- curl 'http://localhost:8080/users' -d '{"name": "Bob Brown", "username": "bobbrown", "age": 25, "company_id": "f073ee4d-318d-4e0b-a796-f450c40aa771"}'
173
- curl 'http://localhost:8080/users' -d '{"name": "Jane Doe", "username": "janedoe", "age": 32, "company_id": "f073ee4d-318d-4e0b-a796-f450c40aa771"}'
174
-
175
- $ curl 'http://localhost:8080/users' | jq
176
- {
177
- "status": "success",
178
- "error": "",
179
- "data": [
180
- {
181
- "id": "68cbb9e9-689a-4ae0-af77-d60e4cb344f1",
182
- "name": "Bob Brown",
183
- "username": "bobbrown",
184
- "age": 25,
185
- "created_at": "2025-06-08T10:40:37+00:00",
186
- "updated_at": "2025-06-08T10:40:37+00:00",
187
- "company": {
188
- "id": "f073ee4d-318d-4e0b-a796-f450c40aa771",
189
- "name": "Box Store"
190
- }
191
- },
192
- {
193
- "id": "e69c4ebf-38b1-40d2-b523-5d58f5befc7b",
194
- "name": "Jane Doe",
195
- "username": "janedoe",
196
- "age": 32,
197
- "created_at": "2025-06-08T10:41:04+00:00",
198
- "updated_at": "2025-06-08T10:41:04+00:00",
199
- "company": {
200
- "id": "f073ee4d-318d-4e0b-a796-f450c40aa771",
201
- "name": "Box Store"
202
- }
203
- }
204
- ],
205
- "pagination": {
206
- "number_results": 2,
207
- "limit": 50,
208
- "next_page": {}
209
- },
210
- "input_errors": {}
211
- }
212
-
213
- ```
214
- """
215
-
216
- """
217
- The dependency injection container
218
- """
219
- di = clearskies.di.inject.Di()
220
-
221
- """
222
- The base URL for the endpoint group.
223
-
224
- This URL is added as a prefix to all endpoints attached to the group. This includes any named URL parameters:
225
- """
226
- url = clearskies.configs.String(default="")
227
-
228
- """
229
- The list of endpoints connected to this endpoint group
230
- """
231
- endpoints = clearskies.configs.EndpointList()
232
-
233
- internal_casing = clearskies.configs.Select(["snake_case", "camelCase", "TitleCase"], default="snake_case")
234
- external_casing = clearskies.configs.Select(["snake_case", "camelCase", "TitleCase"], default="snake_case")
235
- response_headers = clearskies.configs.StringListOrCallable(default=[])
236
- authentication = clearskies.configs.Authentication(default=Public())
237
- authorization = clearskies.configs.Authorization(default=Authorization())
238
- security_headers = clearskies.configs.SecurityHeaders(default=[])
239
-
240
- cors_header: SecurityHeader = None # type: ignore
241
- has_cors: bool = False
242
- endpoints_initialized = False
243
- external_casing = "snake_case"
244
- internal_casing = "snake_case"
245
-
246
- @clearskies.decorators.parameters_to_properties
247
- def __init__(
248
- self,
249
- endpoints: list[Endpoint | Self],
250
- url: str = "",
251
- response_headers: list[str | Callable[..., list[str]]] = [],
252
- security_headers: list[SecurityHeader] = [],
253
- internal_casing: str = "snake_case",
254
- external_casing: str = "snake_case",
255
- authentication: Authentication = Public(),
256
- authorization: Authorization = Authorization(),
257
- ):
258
- self.finalize_and_validate_configuration()
259
- for security_header in self.security_headers:
260
- if not security_header.is_cors:
261
- continue
262
- self.cors_header = security_header
263
- self.has_cors = True
264
- break
265
-
266
- if not endpoints:
267
- raise ValueError(
268
- "An endpoint group must receive a list of endpoints/endpoint groups, but my list of endpoints is empty."
269
- )
270
- if not isinstance(endpoints, list):
271
- raise ValueError(
272
- f"An endpoint group must receive a list of endpoints/endpoint groups, but instead of a list I found an object of type '{endpoints.__class__.__name__}'"
273
- )
274
- for index, endpoint in enumerate(endpoints):
275
- if not isinstance(endpoint, Endpoint) and not isinstance(endpoint, self.__class__):
276
- raise ValueError(
277
- f"An endpoint group must receive a list of endpoints/endpoint groups, but item #{index + 1} was neither an endpoint nor an endpoint group, but an object of type '{endpoints.__class__.__name__}'"
278
- )
279
- if self.url.strip("/"):
280
- endpoint.add_url_prefix(self.url)
281
-
282
- def add_url_prefix(self, prefix: str) -> None:
283
- self.url = (prefix.rstrip("/") + "/" + self.url.lstrip("/")).lstrip("/")
284
- for endpoint in self.endpoints:
285
- endpoint.add_url_prefix(self.url)
286
-
287
- def matches_request(self, input_output: InputOutput, allow_partial=True) -> bool:
288
- """Whether or not we can handle an incoming request based on URL and request method."""
289
- expected_url = self.url.strip("/")
290
- incoming_url = input_output.get_full_path().strip("/")
291
- if not expected_url and not incoming_url:
292
- return True
293
- (matches, routing_data) = routing.match_route(expected_url, incoming_url, allow_partial=allow_partial)
294
- return matches
295
-
296
- def populate_routing_data(self, input_output: InputOutput) -> Any:
297
- # only endpoints (not the endpoint group) can handle this because the endpoint group doesn't have the full url
298
- return None
299
-
300
- def handle(self, input_output):
301
- if not self.endpoints_initialized:
302
- self.endpoints_initialized = True
303
- for endpoint in self.endpoints:
304
- endpoint.injectable_properties(self.di)
305
-
306
- has_match = False
307
- for endpoint in self.endpoints:
308
- if not endpoint.matches_request(input_output):
309
- continue
310
- has_match = True
311
- break
312
-
313
- if not has_match:
314
- return self.error(input_output, "Not Found", 404)
315
-
316
- self.add_response_headers(input_output)
317
-
318
- # "register" ourself with the DI system
319
- current_endpoint_groups = self.di.build_from_name("endpoint_groups", cache=True)
320
- current_endpoint_groups.append(self)
321
- self.di.add_binding("endpoint_groups", current_endpoint_groups)
322
-
323
- return endpoint(input_output)
324
-
325
- def error(self, input_output: InputOutput, message: str, status_code: int) -> Any:
326
- """Return a client-side error (e.g. 400)."""
327
- return self.respond_json(input_output, {"status": "client_error", "error": message}, status_code)
328
-
329
- def all_endpoints(self) -> list[Endpoint]:
330
- """Returns the full (recursive) list of all endpoints associated with this endpoint group"""
331
- all_endpoints: list[Endpoint] = []
332
- for endpoint in self.endpoints:
333
- if hasattr(endpoint, "all_endpoints"):
334
- all_endpoints = [*all_endpoints, *endpoint.all_endpoints()]
335
- else:
336
- all_endpoints.append(endpoint)
337
-
338
- return all_endpoints
@@ -1,25 +0,0 @@
1
- from clearskies.endpoints.advanced_search import AdvancedSearch
2
- from clearskies.endpoints.callable import Callable
3
- from clearskies.endpoints.create import Create
4
- from clearskies.endpoints.delete import Delete
5
- from clearskies.endpoints.get import Get
6
- from clearskies.endpoints.health_check import HealthCheck
7
- from clearskies.endpoints.list import List
8
- from clearskies.endpoints.restful_api import RestfulApi
9
- from clearskies.endpoints.schema import Schema
10
- from clearskies.endpoints.simple_search import SimpleSearch
11
- from clearskies.endpoints.update import Update
12
-
13
- __all__ = [
14
- "AdvancedSearch",
15
- "Callable",
16
- "Create",
17
- "Delete",
18
- "Get",
19
- "HealthCheck",
20
- "List",
21
- "RestfulApi",
22
- "Schema",
23
- "SimpleSearch",
24
- "Update",
25
- ]