52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
|
from rest_framework.views import APIView
|
||
|
from rest_framework.response import Response
|
||
|
from rest_framework.decorators import schema
|
||
|
|
||
|
from django.urls import reverse
|
||
|
|
||
|
from lib.utils.general import get_ip_address
|
||
|
|
||
|
@schema(None)
|
||
|
class Info(APIView):
|
||
|
"""
|
||
|
Show some API information. Also this can be used to check if the Hawk credentials are working.
|
||
|
|
||
|
Make sure your request does contain the header 'Content-Type': 'application/json'
|
||
|
"""
|
||
|
|
||
|
def get(self, request, format=None):
|
||
|
"""
|
||
|
Default API get action will return the following information in a dict:
|
||
|
|
||
|
- Connected user
|
||
|
- Used authentication scheme
|
||
|
- The remote IP of the connection
|
||
|
- The used content type
|
||
|
- The full url to the API documentation (OpenAPI)
|
||
|
- If a super token is used
|
||
|
"""
|
||
|
|
||
|
data = {
|
||
|
'type' : 'anonymous',
|
||
|
'auth' : 'none',
|
||
|
'remote_ip' : get_ip_address(request),
|
||
|
'content_type' : request.content_type,
|
||
|
'openapi' : request.build_absolute_uri(reverse('api:schema-redoc')),
|
||
|
}
|
||
|
|
||
|
if request.user.is_authenticated:
|
||
|
|
||
|
data['user'] = request.user.username
|
||
|
data['type'] = 'authenticated'
|
||
|
data['auth'] = str(request.successful_authenticator)
|
||
|
|
||
|
if request.user.token.is_supertoken:
|
||
|
data['type'] = 'supertoken'
|
||
|
else:
|
||
|
try:
|
||
|
assert request.user.researcher
|
||
|
data['type'] = 'researcher'
|
||
|
except AttributeError:
|
||
|
pass
|
||
|
|
||
|
return Response(data)
|