32
32
API_ROOT = settings .V3_DOMAIN_API_ROOT_NO_FRONT_SLASH
33
33
else :
34
34
API_ROOT = settings .V3_API_ROOT_NO_FRONT_SLASH
35
+
35
36
if settings .API_ROOT_REWRITE_HEADER :
36
37
V3_API_ROOT = settings .V3_API_ROOT .replace ("/<path:api_root>/" , settings .API_ROOT )
38
+ V4_API_ROOT = settings .V4_API_ROOT .replace ("/<path:api_root>/" , settings .API_ROOT )
37
39
else :
38
40
V3_API_ROOT = settings .V3_API_ROOT
41
+ V4_API_ROOT = settings .V4_API_ROOT
39
42
40
43
41
44
class ViewSetNode :
@@ -153,70 +156,83 @@ class PulpDefaultRouter(routers.DefaultRouter):
153
156
vs_tree .add_decendent (ViewSetNode (viewset ))
154
157
155
158
special_views = [
156
- path ("login/" , LoginViewSet .as_view ()),
157
- path ("repair/" , RepairView .as_view ()),
159
+ path ("login/" , LoginViewSet .as_view (), name = "login" ),
160
+ path ("repair/" , RepairView .as_view (), name = "repair" ),
158
161
path (
159
162
"orphans/cleanup/" ,
160
163
OrphansCleanupViewset .as_view (actions = {"post" : "cleanup" }),
164
+ name = "orphan-cleanup" ,
161
165
),
162
- path ("orphans/" , OrphansView .as_view ()),
166
+ path ("orphans/" , OrphansView .as_view (), name = "orphans" ),
163
167
path (
164
168
"repository_versions/" ,
165
169
ListRepositoryVersionViewSet .as_view (actions = {"get" : "list" }),
170
+ name = "repository-versions" ,
166
171
),
167
172
path (
168
173
"repositories/reclaim_space/" ,
169
174
ReclaimSpaceViewSet .as_view (actions = {"post" : "reclaim" }),
175
+ name = "reclaim" ,
170
176
),
171
177
path (
172
178
"importers/core/pulp/import-check/" ,
173
179
PulpImporterImportCheckView .as_view (),
180
+ name = "pulp-importer-import-check" ,
174
181
),
175
182
]
176
183
177
- docs_and_status = [
178
- path ("livez/" , LivezView .as_view ()),
179
- path ("status/" , StatusView .as_view ()),
180
- path (
181
- "docs/api.json" ,
182
- SpectacularJSONAPIView .as_view (authentication_classes = [], permission_classes = []),
183
- name = "schema" ,
184
- ),
185
- path (
186
- "docs/api.yaml" ,
187
- SpectacularYAMLAPIView .as_view (authentication_classes = [], permission_classes = []),
188
- name = "schema-yaml" ,
189
- ),
190
- path (
191
- "docs/" ,
192
- SpectacularRedocView .as_view (
193
- authentication_classes = [],
194
- permission_classes = [],
195
- url = f"{ V3_API_ROOT } docs/api.json?include_html=1&pk_path=1" ,
184
+
185
+ def _docs_and_status (_api_root ):
186
+ paths = [
187
+ path (
188
+ "docs/api.json" ,
189
+ SpectacularJSONAPIView .as_view (authentication_classes = [], permission_classes = []),
190
+ name = "schema" ,
196
191
),
197
- name = "schema-redoc" ,
198
- ),
199
- path (
200
- "swagger/" ,
201
- SpectacularSwaggerView .as_view (
202
- authentication_classes = [],
203
- permission_classes = [],
204
- url = f"{ V3_API_ROOT } docs/api.json?include_html=1&pk_path=1" ,
192
+ path (
193
+ "docs/api.yaml" ,
194
+ SpectacularYAMLAPIView .as_view (authentication_classes = [], permission_classes = []),
195
+ name = "schema-yaml" ,
205
196
),
206
- name = "schema-swagger" ,
207
- ),
208
- ]
197
+ path (
198
+ "docs/" ,
199
+ SpectacularRedocView .as_view (
200
+ authentication_classes = [],
201
+ permission_classes = [],
202
+ url = f"{ _api_root } docs/api.json?include_html=1&pk_path=1" ,
203
+ ),
204
+ name = "schema-redoc" ,
205
+ ),
206
+ path (
207
+ "swagger/" ,
208
+ SpectacularSwaggerView .as_view (
209
+ authentication_classes = [],
210
+ permission_classes = [],
211
+ url = f"{ _api_root } docs/api.json?include_html=1&pk_path=1" ,
212
+ ),
213
+ name = "schema-swagger" ,
214
+ ),
215
+ path ("livez/" , LivezView .as_view (), name = "livez" ),
216
+ path ("status/" , StatusView .as_view (), name = "status" ),
217
+ ]
218
+
219
+ return paths
220
+
221
+
222
+ v3_docs_and_status = _docs_and_status (V3_API_ROOT )
223
+ v4_docs_and_status = _docs_and_status (V4_API_ROOT )
209
224
210
225
urlpatterns = [
211
- path (API_ROOT , include (special_views )),
212
226
path ("auth/" , include ("rest_framework.urls" )),
213
- path (settings .V3_API_ROOT_NO_FRONT_SLASH , include (docs_and_status )),
227
+ path (API_ROOT , include (special_views )),
228
+ path (settings .V3_API_ROOT_NO_FRONT_SLASH , include (v3_docs_and_status )),
214
229
]
215
230
231
+
216
232
if settings .DOMAIN_ENABLED :
217
233
# Ensure Docs and Status endpoints are available within domains, but are not shown in API schema
218
234
docs_and_status_no_schema = []
219
- for p in docs_and_status :
235
+ for p in v3_docs_and_status :
220
236
221
237
@extend_schema (exclude = True )
222
238
class NoSchema (p .callback .cls ):
@@ -227,6 +243,34 @@ class NoSchema(p.callback.cls):
227
243
docs_and_status_no_schema .append (path (str (p .pattern ), view , name = name ))
228
244
urlpatterns .insert (- 1 , path (API_ROOT , include (docs_and_status_no_schema )))
229
245
246
+
247
+ if settings .ENABLE_V4_API :
248
+ urlpatterns .extend (
249
+ [
250
+ path (V4_API_ROOT , include ((special_views , "core" ), namespace = "v4" )),
251
+ path (
252
+ settings .V4_API_ROOT_NO_FRONT_SLASH ,
253
+ include ((v4_docs_and_status , "core" ), namespace = "v4" ),
254
+ ),
255
+ ]
256
+ )
257
+
258
+
259
+ if settings .DOMAIN_ENABLED :
260
+ # Ensure Docs and Status endpoints are available within domains, but are not shown in API schema
261
+ docs_and_status_no_schema = []
262
+ for p in v4_docs_and_status :
263
+
264
+ @extend_schema (exclude = True )
265
+ class NoSchema (p .callback .cls ):
266
+ pass
267
+
268
+ view = NoSchema .as_view (** p .callback .initkwargs )
269
+ name = p .name + "-domains" if p .name else None
270
+ docs_and_status_no_schema .append (path (str (p .pattern ), view , name = name ))
271
+ urlpatterns .insert (- 1 , path (API_ROOT , include (docs_and_status_no_schema )))
272
+
273
+
230
274
if "social_django" in settings .INSTALLED_APPS :
231
275
urlpatterns .append (
232
276
path ("" , include ("social_django.urls" , namespace = settings .SOCIAL_AUTH_URL_NAMESPACE ))
@@ -239,6 +283,12 @@ class NoSchema(p.callback.cls):
239
283
for router in all_routers :
240
284
urlpatterns .append (path (API_ROOT , include (router .urls )))
241
285
286
+ if settings .ENABLE_V4_API :
287
+ for router in all_routers :
288
+ urlpatterns .append (
289
+ path (V4_API_ROOT .lstrip ("/" ), include ((router .urls , "core" ), namespace = "v4" ))
290
+ )
291
+
242
292
# If plugins define a urls.py, include them into the root namespace.
243
293
for plugin_pattern in plugin_patterns :
244
294
urlpatterns .append (path ("" , include (plugin_pattern )))
0 commit comments