1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 06:51:10 +03:00

add "added_in_api_version" metadata to OPTIONS requests

This commit is contained in:
Ryan Petrello 2017-04-12 11:48:51 -04:00
parent ba259e0ad4
commit 7e64a6fd60
5 changed files with 29 additions and 5 deletions

View File

@ -165,6 +165,7 @@ class APIView(views.APIView):
'new_in_300': getattr(self, 'new_in_300', False),
'new_in_310': getattr(self, 'new_in_310', False),
'new_in_320': getattr(self, 'new_in_320', False),
'new_in_api_v2': getattr(self, 'new_in_api_v2', False),
'deprecated': getattr(self, 'deprecated', False),
}

View File

@ -186,6 +186,14 @@ class Metadata(metadata.SimpleMetadata):
break
metadata['added_in_version'] = added_in_version
# Add API version number in which view was added to Tower.
added_in_api_version = 'v1'
for version in ('v2',):
if getattr(view, 'new_in_api_%s' % version, False):
added_in_api_version = version
break
metadata['added_in_api_version'] = added_in_api_version
# Add type(s) handled by this view/serializer.
if hasattr(view, 'get_serializer'):
serializer = view.get_serializer()

View File

@ -0,0 +1,4 @@
Version 2 of the Ansible Tower REST API.
Make a GET request to this resource to obtain a list of all child resources
available via the API.

View File

@ -340,7 +340,7 @@ activity_stream_urls = patterns('awx.api.views',
)
v1_urls = patterns('awx.api.views',
url(r'^$', 'api_version_root_view'),
url(r'^$', 'api_v1_root_view'),
url(r'^ping/$', 'api_v1_ping_view'),
url(r'^config/$', 'api_v1_config_view'),
url(r'^auth/$', 'auth_view'),
@ -384,7 +384,7 @@ v1_urls = patterns('awx.api.views',
)
v2_urls = patterns('awx.api.views',
url(r'^$', 'api_version_root_view'),
url(r'^$', 'api_v2_root_view'),
url(r'^credential_types/', include(credential_type_urls)),
)

View File

@ -134,8 +134,8 @@ class ApiRootView(APIView):
def get(self, request, format=None):
''' list supported API versions '''
v1 = reverse('api:api_version_root_view', kwargs={'version': 'v1'})
v2 = reverse('api:api_version_root_view', kwargs={'version': 'v2'})
v1 = reverse('api:api_v1_root_view', kwargs={'version': 'v1'})
v2 = reverse('api:api_v2_root_view', kwargs={'version': 'v2'})
data = dict(
description = _('Ansible Tower REST API'),
current_version = v2,
@ -150,7 +150,6 @@ class ApiRootView(APIView):
class ApiVersionRootView(APIView):
authentication_classes = []
view_name = _('Version')
permission_classes = (AllowAny,)
def get(self, request, format=None):
@ -197,6 +196,16 @@ class ApiVersionRootView(APIView):
return Response(data)
class ApiV1RootView(ApiVersionRootView):
view_name = _('Version 1')
class ApiV2RootView(ApiVersionRootView):
view_name = _('Version 2')
new_in_320 = True
new_in_api_v2 = True
class ApiV1PingView(APIView):
"""A simple view that reports very basic information about this Tower
instance, which is acceptable to be public information.
@ -1482,6 +1491,7 @@ class CredentialTypeList(ListCreateAPIView):
model = CredentialType
serializer_class = CredentialTypeSerializer
new_in_320 = True
new_in_api_v2 = True
class CredentialTypeDetail(RetrieveUpdateDestroyAPIView):
@ -1489,6 +1499,7 @@ class CredentialTypeDetail(RetrieveUpdateDestroyAPIView):
model = CredentialType
serializer_class = CredentialTypeSerializer
new_in_320 = True
new_in_api_v2 = True
class CredentialList(ListCreateAPIView):