clear-skies 2.0.5__py3-none-any.whl → 2.0.6__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 (252) hide show
  1. {clear_skies-2.0.5.dist-info → clear_skies-2.0.6.dist-info}/METADATA +1 -1
  2. clear_skies-2.0.6.dist-info/RECORD +251 -0
  3. clearskies/__init__.py +61 -0
  4. clearskies/action.py +7 -0
  5. clearskies/authentication/__init__.py +15 -0
  6. clearskies/authentication/authentication.py +46 -0
  7. clearskies/authentication/authorization.py +16 -0
  8. clearskies/authentication/authorization_pass_through.py +20 -0
  9. clearskies/authentication/jwks.py +163 -0
  10. clearskies/authentication/public.py +5 -0
  11. clearskies/authentication/secret_bearer.py +553 -0
  12. clearskies/autodoc/__init__.py +8 -0
  13. clearskies/autodoc/formats/__init__.py +5 -0
  14. clearskies/autodoc/formats/oai3_json/__init__.py +7 -0
  15. clearskies/autodoc/formats/oai3_json/oai3_json.py +87 -0
  16. clearskies/autodoc/formats/oai3_json/oai3_schema_resolver.py +15 -0
  17. clearskies/autodoc/formats/oai3_json/parameter.py +35 -0
  18. clearskies/autodoc/formats/oai3_json/request.py +68 -0
  19. clearskies/autodoc/formats/oai3_json/response.py +28 -0
  20. clearskies/autodoc/formats/oai3_json/schema/__init__.py +11 -0
  21. clearskies/autodoc/formats/oai3_json/schema/array.py +9 -0
  22. clearskies/autodoc/formats/oai3_json/schema/default.py +13 -0
  23. clearskies/autodoc/formats/oai3_json/schema/enum.py +7 -0
  24. clearskies/autodoc/formats/oai3_json/schema/object.py +35 -0
  25. clearskies/autodoc/formats/oai3_json/test.json +1985 -0
  26. clearskies/autodoc/py.typed +0 -0
  27. clearskies/autodoc/request/__init__.py +15 -0
  28. clearskies/autodoc/request/header.py +6 -0
  29. clearskies/autodoc/request/json_body.py +6 -0
  30. clearskies/autodoc/request/parameter.py +8 -0
  31. clearskies/autodoc/request/request.py +47 -0
  32. clearskies/autodoc/request/url_parameter.py +6 -0
  33. clearskies/autodoc/request/url_path.py +6 -0
  34. clearskies/autodoc/response/__init__.py +5 -0
  35. clearskies/autodoc/response/response.py +9 -0
  36. clearskies/autodoc/schema/__init__.py +31 -0
  37. clearskies/autodoc/schema/array.py +10 -0
  38. clearskies/autodoc/schema/base64.py +8 -0
  39. clearskies/autodoc/schema/boolean.py +5 -0
  40. clearskies/autodoc/schema/date.py +5 -0
  41. clearskies/autodoc/schema/datetime.py +5 -0
  42. clearskies/autodoc/schema/double.py +5 -0
  43. clearskies/autodoc/schema/enum.py +17 -0
  44. clearskies/autodoc/schema/integer.py +6 -0
  45. clearskies/autodoc/schema/long.py +5 -0
  46. clearskies/autodoc/schema/number.py +6 -0
  47. clearskies/autodoc/schema/object.py +13 -0
  48. clearskies/autodoc/schema/password.py +5 -0
  49. clearskies/autodoc/schema/schema.py +11 -0
  50. clearskies/autodoc/schema/string.py +5 -0
  51. clearskies/backends/__init__.py +65 -0
  52. clearskies/backends/api_backend.py +1178 -0
  53. clearskies/backends/backend.py +136 -0
  54. clearskies/backends/cursor_backend.py +335 -0
  55. clearskies/backends/memory_backend.py +797 -0
  56. clearskies/backends/secrets_backend.py +106 -0
  57. clearskies/column.py +1233 -0
  58. clearskies/columns/__init__.py +71 -0
  59. clearskies/columns/audit.py +206 -0
  60. clearskies/columns/belongs_to_id.py +483 -0
  61. clearskies/columns/belongs_to_model.py +132 -0
  62. clearskies/columns/belongs_to_self.py +105 -0
  63. clearskies/columns/boolean.py +113 -0
  64. clearskies/columns/category_tree.py +275 -0
  65. clearskies/columns/category_tree_ancestors.py +51 -0
  66. clearskies/columns/category_tree_children.py +127 -0
  67. clearskies/columns/category_tree_descendants.py +48 -0
  68. clearskies/columns/created.py +95 -0
  69. clearskies/columns/created_by_authorization_data.py +116 -0
  70. clearskies/columns/created_by_header.py +99 -0
  71. clearskies/columns/created_by_ip.py +92 -0
  72. clearskies/columns/created_by_routing_data.py +97 -0
  73. clearskies/columns/created_by_user_agent.py +92 -0
  74. clearskies/columns/date.py +234 -0
  75. clearskies/columns/datetime.py +282 -0
  76. clearskies/columns/email.py +76 -0
  77. clearskies/columns/float.py +153 -0
  78. clearskies/columns/has_many.py +505 -0
  79. clearskies/columns/has_many_self.py +56 -0
  80. clearskies/columns/has_one.py +14 -0
  81. clearskies/columns/integer.py +160 -0
  82. clearskies/columns/json.py +128 -0
  83. clearskies/columns/many_to_many_ids.py +337 -0
  84. clearskies/columns/many_to_many_ids_with_data.py +274 -0
  85. clearskies/columns/many_to_many_models.py +158 -0
  86. clearskies/columns/many_to_many_pivots.py +134 -0
  87. clearskies/columns/phone.py +159 -0
  88. clearskies/columns/select.py +92 -0
  89. clearskies/columns/string.py +102 -0
  90. clearskies/columns/timestamp.py +164 -0
  91. clearskies/columns/updated.py +110 -0
  92. clearskies/columns/uuid.py +86 -0
  93. clearskies/configs/README.md +105 -0
  94. clearskies/configs/__init__.py +162 -0
  95. clearskies/configs/actions.py +43 -0
  96. clearskies/configs/any.py +13 -0
  97. clearskies/configs/any_dict.py +22 -0
  98. clearskies/configs/any_dict_or_callable.py +23 -0
  99. clearskies/configs/authentication.py +23 -0
  100. clearskies/configs/authorization.py +23 -0
  101. clearskies/configs/boolean.py +16 -0
  102. clearskies/configs/boolean_or_callable.py +18 -0
  103. clearskies/configs/callable_config.py +18 -0
  104. clearskies/configs/columns.py +34 -0
  105. clearskies/configs/conditions.py +30 -0
  106. clearskies/configs/config.py +24 -0
  107. clearskies/configs/datetime.py +18 -0
  108. clearskies/configs/datetime_or_callable.py +19 -0
  109. clearskies/configs/endpoint.py +23 -0
  110. clearskies/configs/endpoint_list.py +29 -0
  111. clearskies/configs/float.py +16 -0
  112. clearskies/configs/float_or_callable.py +18 -0
  113. clearskies/configs/integer.py +16 -0
  114. clearskies/configs/integer_or_callable.py +18 -0
  115. clearskies/configs/joins.py +30 -0
  116. clearskies/configs/list_any_dict.py +30 -0
  117. clearskies/configs/list_any_dict_or_callable.py +31 -0
  118. clearskies/configs/model_class.py +35 -0
  119. clearskies/configs/model_column.py +65 -0
  120. clearskies/configs/model_columns.py +56 -0
  121. clearskies/configs/model_destination_name.py +25 -0
  122. clearskies/configs/model_to_id_column.py +43 -0
  123. clearskies/configs/readable_model_column.py +9 -0
  124. clearskies/configs/readable_model_columns.py +9 -0
  125. clearskies/configs/schema.py +23 -0
  126. clearskies/configs/searchable_model_columns.py +9 -0
  127. clearskies/configs/security_headers.py +39 -0
  128. clearskies/configs/select.py +26 -0
  129. clearskies/configs/select_list.py +47 -0
  130. clearskies/configs/string.py +29 -0
  131. clearskies/configs/string_dict.py +32 -0
  132. clearskies/configs/string_list.py +32 -0
  133. clearskies/configs/string_list_or_callable.py +35 -0
  134. clearskies/configs/string_or_callable.py +18 -0
  135. clearskies/configs/timedelta.py +18 -0
  136. clearskies/configs/timezone.py +18 -0
  137. clearskies/configs/url.py +23 -0
  138. clearskies/configs/validators.py +45 -0
  139. clearskies/configs/writeable_model_column.py +9 -0
  140. clearskies/configs/writeable_model_columns.py +9 -0
  141. clearskies/configurable.py +76 -0
  142. clearskies/contexts/__init__.py +11 -0
  143. clearskies/contexts/cli.py +117 -0
  144. clearskies/contexts/context.py +98 -0
  145. clearskies/contexts/wsgi.py +76 -0
  146. clearskies/contexts/wsgi_ref.py +82 -0
  147. clearskies/decorators.py +33 -0
  148. clearskies/di/__init__.py +14 -0
  149. clearskies/di/additional_config.py +130 -0
  150. clearskies/di/additional_config_auto_import.py +17 -0
  151. clearskies/di/di.py +973 -0
  152. clearskies/di/inject/__init__.py +23 -0
  153. clearskies/di/inject/by_class.py +21 -0
  154. clearskies/di/inject/by_name.py +18 -0
  155. clearskies/di/inject/di.py +13 -0
  156. clearskies/di/inject/environment.py +14 -0
  157. clearskies/di/inject/input_output.py +20 -0
  158. clearskies/di/inject/now.py +13 -0
  159. clearskies/di/inject/requests.py +13 -0
  160. clearskies/di/inject/secrets.py +14 -0
  161. clearskies/di/inject/utcnow.py +13 -0
  162. clearskies/di/inject/uuid.py +15 -0
  163. clearskies/di/injectable.py +29 -0
  164. clearskies/di/injectable_properties.py +131 -0
  165. clearskies/di/test_module/__init__.py +6 -0
  166. clearskies/di/test_module/another_module/__init__.py +2 -0
  167. clearskies/di/test_module/module_class.py +5 -0
  168. clearskies/end.py +183 -0
  169. clearskies/endpoint.py +1314 -0
  170. clearskies/endpoint_group.py +336 -0
  171. clearskies/endpoints/__init__.py +25 -0
  172. clearskies/endpoints/advanced_search.py +526 -0
  173. clearskies/endpoints/callable.py +388 -0
  174. clearskies/endpoints/create.py +205 -0
  175. clearskies/endpoints/delete.py +139 -0
  176. clearskies/endpoints/get.py +271 -0
  177. clearskies/endpoints/health_check.py +183 -0
  178. clearskies/endpoints/list.py +574 -0
  179. clearskies/endpoints/restful_api.py +427 -0
  180. clearskies/endpoints/schema.py +189 -0
  181. clearskies/endpoints/simple_search.py +286 -0
  182. clearskies/endpoints/update.py +193 -0
  183. clearskies/environment.py +104 -0
  184. clearskies/exceptions/__init__.py +19 -0
  185. clearskies/exceptions/authentication.py +2 -0
  186. clearskies/exceptions/authorization.py +2 -0
  187. clearskies/exceptions/client_error.py +2 -0
  188. clearskies/exceptions/input_errors.py +4 -0
  189. clearskies/exceptions/missing_dependency.py +2 -0
  190. clearskies/exceptions/moved_permanently.py +3 -0
  191. clearskies/exceptions/moved_temporarily.py +3 -0
  192. clearskies/exceptions/not_found.py +2 -0
  193. clearskies/functional/__init__.py +7 -0
  194. clearskies/functional/routing.py +92 -0
  195. clearskies/functional/string.py +112 -0
  196. clearskies/functional/validations.py +76 -0
  197. clearskies/input_outputs/__init__.py +13 -0
  198. clearskies/input_outputs/cli.py +171 -0
  199. clearskies/input_outputs/exceptions/__init__.py +2 -0
  200. clearskies/input_outputs/exceptions/cli_input_error.py +2 -0
  201. clearskies/input_outputs/exceptions/cli_not_found.py +2 -0
  202. clearskies/input_outputs/headers.py +45 -0
  203. clearskies/input_outputs/input_output.py +138 -0
  204. clearskies/input_outputs/programmatic.py +69 -0
  205. clearskies/input_outputs/py.typed +0 -0
  206. clearskies/input_outputs/wsgi.py +77 -0
  207. clearskies/model.py +1922 -0
  208. clearskies/py.typed +0 -0
  209. clearskies/query/__init__.py +12 -0
  210. clearskies/query/condition.py +223 -0
  211. clearskies/query/join.py +136 -0
  212. clearskies/query/query.py +196 -0
  213. clearskies/query/sort.py +27 -0
  214. clearskies/schema.py +82 -0
  215. clearskies/secrets/__init__.py +6 -0
  216. clearskies/secrets/additional_configs/__init__.py +32 -0
  217. clearskies/secrets/additional_configs/mysql_connection_dynamic_producer.py +61 -0
  218. clearskies/secrets/additional_configs/mysql_connection_dynamic_producer_via_ssh_cert_bastion.py +160 -0
  219. clearskies/secrets/akeyless.py +182 -0
  220. clearskies/secrets/exceptions/__init__.py +1 -0
  221. clearskies/secrets/exceptions/not_found.py +2 -0
  222. clearskies/secrets/secrets.py +38 -0
  223. clearskies/security_header.py +15 -0
  224. clearskies/security_headers/__init__.py +11 -0
  225. clearskies/security_headers/cache_control.py +67 -0
  226. clearskies/security_headers/cors.py +50 -0
  227. clearskies/security_headers/csp.py +94 -0
  228. clearskies/security_headers/hsts.py +22 -0
  229. clearskies/security_headers/x_content_type_options.py +0 -0
  230. clearskies/security_headers/x_frame_options.py +0 -0
  231. clearskies/test_base.py +8 -0
  232. clearskies/typing.py +11 -0
  233. clearskies/validator.py +37 -0
  234. clearskies/validators/__init__.py +33 -0
  235. clearskies/validators/after_column.py +62 -0
  236. clearskies/validators/before_column.py +13 -0
  237. clearskies/validators/in_the_future.py +32 -0
  238. clearskies/validators/in_the_future_at_least.py +11 -0
  239. clearskies/validators/in_the_future_at_most.py +10 -0
  240. clearskies/validators/in_the_past.py +32 -0
  241. clearskies/validators/in_the_past_at_least.py +10 -0
  242. clearskies/validators/in_the_past_at_most.py +10 -0
  243. clearskies/validators/maximum_length.py +26 -0
  244. clearskies/validators/maximum_value.py +29 -0
  245. clearskies/validators/minimum_length.py +26 -0
  246. clearskies/validators/minimum_value.py +29 -0
  247. clearskies/validators/required.py +34 -0
  248. clearskies/validators/timedelta.py +59 -0
  249. clearskies/validators/unique.py +30 -0
  250. clear_skies-2.0.5.dist-info/RECORD +0 -4
  251. {clear_skies-2.0.5.dist-info → clear_skies-2.0.6.dist-info}/WHEEL +0 -0
  252. {clear_skies-2.0.5.dist-info → clear_skies-2.0.6.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,336 @@
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
+
244
+ @clearskies.decorators.parameters_to_properties
245
+ def __init__(
246
+ self,
247
+ endpoints: list[Endpoint | Self],
248
+ url: str = "",
249
+ response_headers: list[str | Callable[..., list[str]]] = [],
250
+ security_headers: list[SecurityHeader] = [],
251
+ internal_casing: str = "snake_case",
252
+ external_casing: str = "snake_case",
253
+ authentication: Authentication = Public(),
254
+ authorization: Authorization = Authorization(),
255
+ ):
256
+ self.finalize_and_validate_configuration()
257
+ for security_header in self.security_headers:
258
+ if not security_header.is_cors:
259
+ continue
260
+ self.cors_header = security_header
261
+ self.has_cors = True
262
+ break
263
+
264
+ if not endpoints:
265
+ raise ValueError(
266
+ "An endpoint group must receive a list of endpoints/endpoint groups, but my list of endpoints is empty."
267
+ )
268
+ if not isinstance(endpoints, list):
269
+ raise ValueError(
270
+ 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__}'"
271
+ )
272
+ for index, endpoint in enumerate(endpoints):
273
+ if not isinstance(endpoint, Endpoint) and not isinstance(endpoint, self.__class__):
274
+ raise ValueError(
275
+ 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__}'"
276
+ )
277
+ if self.url.strip("/"):
278
+ endpoint.add_url_prefix(self.url)
279
+
280
+ def add_url_prefix(self, prefix: str) -> None:
281
+ self.url = (prefix.rstrip("/") + "/" + self.url.lstrip("/")).lstrip("/")
282
+ for endpoint in self.endpoints:
283
+ endpoint.add_url_prefix(self.url)
284
+
285
+ def matches_request(self, input_output: InputOutput, allow_partial=True) -> bool:
286
+ """Whether or not we can handle an incoming request based on URL and request method."""
287
+ expected_url = self.url.strip("/")
288
+ incoming_url = input_output.get_full_path().strip("/")
289
+ if not expected_url and not incoming_url:
290
+ return True
291
+ (matches, routing_data) = routing.match_route(expected_url, incoming_url, allow_partial=allow_partial)
292
+ return matches
293
+
294
+ def populate_routing_data(self, input_output: InputOutput) -> Any:
295
+ # only endpoints (not the endpoint group) can handle this because the endpoint group doesn't have the full url
296
+ return None
297
+
298
+ def handle(self, input_output):
299
+ if not self.endpoints_initialized:
300
+ self.endpoints_initialized = True
301
+ for endpoint in self.endpoints:
302
+ endpoint.injectable_properties(self.di)
303
+
304
+ has_match = False
305
+ for endpoint in self.endpoints:
306
+ if not endpoint.matches_request(input_output):
307
+ continue
308
+ has_match = True
309
+ break
310
+
311
+ if not has_match:
312
+ return self.error(input_output, "Not Found", 404)
313
+
314
+ self.add_response_headers(input_output)
315
+
316
+ # "register" ourself with the DI system
317
+ current_endpoint_groups = self.di.build_from_name("endpoint_groups", cache=True)
318
+ current_endpoint_groups.append(self)
319
+ self.di.add_binding("endpoint_groups", current_endpoint_groups)
320
+
321
+ return endpoint(input_output)
322
+
323
+ def error(self, input_output: InputOutput, message: str, status_code: int) -> Any:
324
+ """Return a client-side error (e.g. 400)."""
325
+ return self.respond_json(input_output, {"status": "client_error", "error": message}, status_code)
326
+
327
+ def all_endpoints(self) -> list[Endpoint]:
328
+ """Returns the full (recursive) list of all endpoints associated with this endpoint group"""
329
+ all_endpoints: list[Endpoint] = []
330
+ for endpoint in self.endpoints:
331
+ if hasattr(endpoint, "all_endpoints"):
332
+ all_endpoints = [*all_endpoints, *endpoint.all_endpoints()]
333
+ else:
334
+ all_endpoints.append(endpoint)
335
+
336
+ return all_endpoints
@@ -0,0 +1,25 @@
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
+ ]