Skip to content

Commit

Permalink
Add a ApiV2RootView for /api/v2 (#1997)
Browse files Browse the repository at this point in the history
  • Loading branch information
alikins authored and Chris Houseknecht committed Aug 29, 2019
1 parent 9e0ab6b commit 9e2017f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
3 changes: 2 additions & 1 deletion galaxy/api/v2/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
# You should have received a copy of the Apache License
# along with Galaxy. If not, see <http://www.apache.org/licenses/>.

from django.urls import path
from django.urls import path, re_path as url

from galaxy.api.v2 import views

app_name = 'api'
urlpatterns = [
url(r'^$', views.ApiV2RootView.as_view(), name='api_v2_root_view'),
# Collection Imports URLs
path('collection-imports/<int:pk>/',
views.CollectionImportView.as_view(),
Expand Down
4 changes: 4 additions & 0 deletions galaxy/api/v2/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
VersionDetailView,
)

from .api import ( # noqa: F401
ApiV2RootView,
)
__all__ = (
'ApiV2RootView',
'CollectionListView',
'CollectionDetailView',
'CollectionImportView',
Expand Down
36 changes: 36 additions & 0 deletions galaxy/api/v2/views/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# (c) 2012-2019, Ansible by Red Hat
#
# This file is part of Ansible Galaxy
#
# Ansible Galaxy is free software: you can redistribute it and/or modify
# it under the terms of the Apache License as published by
# the Apache Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# Ansible Galaxy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# Apache License for more details.
#
# You should have received a copy of the Apache License
# along with Galaxy. If not, see <http://www.apache.org/licenses/>.

from collections import OrderedDict

from django.urls import reverse

from rest_framework.permissions import AllowAny
from rest_framework.response import Response
from galaxy.api.views import base_views


class ApiV2RootView(base_views.APIView):
permission_classes = (AllowAny,)
view_name = 'Version 2'

def get(self, request, format=None):
# list top level resources
data = OrderedDict()
data['collections'] = reverse('api:v2:collection-list')

return Response(data)
2 changes: 1 addition & 1 deletion galaxy/api/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def get(self, request, format=None):
current_version='v1',
available_versions=dict(
v1=current,
v2='/api/v2',
v2=reverse('api:v2:api_v2_root_view'),
),
server_version=version.get_package_version('galaxy'),
version_name=version.get_version_name(),
Expand Down

0 comments on commit 9e2017f

Please sign in to comment.